Skip to content
This repository has been archived by the owner on Nov 29, 2017. It is now read-only.

Commit

Permalink
Merge pull request #43 from GoSuji/coverage
Browse files Browse the repository at this point in the history
Coverage
  • Loading branch information
vapour101 committed Oct 29, 2017
2 parents a88ec7f + 33c2848 commit 9d96c3f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 5 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ generateGrammarSource {

cobertura {
coverageFormats = ['html', 'xml']
coverageExcludes = ['.*instrumented_classes.ui.*', '.*instrumented_classes.event.*DrawerEventWrapper*']
coverageExcludes = ['.*instrumented_classes.ui.*', '.*instrumented_classes.event.*DrawerEventWrapper.*',
'.*instrumented_classes.sgf.SGFLexer.*', '.*instrumented_classes.sgf.SGFParser.*',
'.*instrumented_classes.sgf.SGFParserBaseVisitor.*']
coverageIgnoreTrivial = true
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/logic/gametree/ComplexTreeIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void addProperty(GameTreeBuilder.GameTreeProperty property) {
if ( identifier.equals("B") || identifier.equals("W") ) {
StoneColour colour = StoneColour.fromString(identifier);

if ( property.getValues().isEmpty() )
if ( property.getValues().isEmpty() || property.getValues().firstElement().equals("") )
node.setMove(Move.pass(colour));
else {
Coords coords = Coords.fromSGFString(property.getValues().firstElement());
Expand Down
9 changes: 8 additions & 1 deletion src/test/java/event/GameEventTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,36 @@
import logic.gamehandler.LocalGame;
import org.junit.Test;
import util.Move;
import util.StoneColour;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static util.Coords.getCoords;
import static util.Move.play;
import static util.StoneColour.BLACK;
import static util.StoneColour.WHITE;

public class GameEventTest {

@Test
public void getState() {
GameHandler game = new LocalGame(0);
final Board[] result = {null};
final StoneColour[] colours = {null};
Board board = new Board();

Move move = play(getCoords("K10"), BLACK);
board.playStone(move);

EventHandler<GameEvent> dummy = event -> result[0] = event.getBoard();
EventHandler<GameEvent> dummy = event -> {
result[0] = event.getBoard();
colours[0] = event.getTurnPlayer();
};
game.subscribe(GameEvent.MOVE, dummy);

game.playMove(move);

assertThat(result[0], is(board));
assertThat(colours[0], is(WHITE));
}
}
1 change: 1 addition & 0 deletions src/test/java/logic/board/BoardTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void equals() {

assertThat(board1, is(board1));
assertThat(board1, is(not(getCoords("D4"))));
assertThat(board1.toString(), containsString("B"));
}

@Test
Expand Down
32 changes: 30 additions & 2 deletions src/test/java/logic/gamehandler/LocalGameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
package logic.gamehandler;

import logic.board.Board;
import logic.gametree.GameTree;
import org.junit.Test;
import sgf.SGFReader;
import util.Move;

import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static util.Coords.getCoords;
import static util.Move.play;
Expand All @@ -33,6 +34,33 @@ public class LocalGameTest {

private static final String[] koBoard = {"C4", "D4", "D3", "E3", "D5", "E5", "K4", "F4", "E4"};

@Test
public void generatingSGF() {
LocalGame handler = new LocalGame();
handler.playMove(play(getCoords("D4"), BLACK));
handler.playMove(play(getCoords("D4"), WHITE)); //Illegal, should be ignored
handler.pass();
handler.pass();

String sgf = handler.getSGFWriter().getSGFString();

assertThat(sgf, containsString("B[dd]"));
assertThat(sgf, not(containsString("W[dd]")));
assertThat(sgf, containsString("W[]"));

SGFReader reader = new SGFReader(sgf);
GameTree tree = reader.getGameTree();

while (tree.getNumChildren() > 0)
tree.stepForward(0);

LocalGame compare = new LocalGame(tree);

assertThat(handler.getBoard(), is(compare.getBoard()));

assertThat(handler.getScorer(), not(nullValue()));
}

@Test
public void gameTracking() {
LocalGame handler = new LocalGame();
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/sgf/SimpleSGFWriterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package sgf;

import org.junit.Test;
import util.Move;

import java.util.LinkedList;
import java.util.List;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static util.Coords.getCoords;
import static util.Move.pass;
import static util.Move.play;
import static util.StoneColour.BLACK;
import static util.StoneColour.WHITE;

public class SimpleSGFWriterTest {

@Test
public void sgfString() {
List<Move> moveList = new LinkedList<Move>();
moveList.add(play(getCoords("D4"), BLACK));
moveList.add(play(getCoords("C3"), WHITE));
moveList.add(pass(BLACK));

SimpleSGFWriter writer = new SimpleSGFWriter(moveList);

assertThat(writer.getSGFString(), containsString("B[dd]"));
assertThat(writer.getSGFString(), containsString("W[cc]"));

SGFReader reader = new SGFReader(writer.getSGFString());
assertThat(reader.getGameTree(), is(notNullValue()));
}
}

0 comments on commit 9d96c3f

Please sign in to comment.