O'Reilly logo

Test-Driven Java Development - Second Edition by Viktor Farcic, Alex Garcia

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Requirement 8 – win condition (IV)

The last requirement is the last win condition.

If a player inserts a disc and connects more than three discs of his color in a straight diagonal line, then that player wins.

We need to perform valid game movements to achieve the condition. In this case, we need to test both diagonals across the board: from top-right to bottom-left and from bottom-right to top-left. The following tests use a list of columns to recreate a full game to reproduce the scenario under test:

@Test public void when4Diagonal1DiscsAreConnectedThenThatPlayerWins() { int[] gameplay = new int[] {1, 2, 2, 3, 4, 3, 3, 4, 4, 5, 4}; for (int column : gameplay) { tested.putDiscInColumn(column); } assertThat(tested.getWinner(), is("R")); } ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required