summaryrefslogtreecommitdiff
path: root/domain/src/test/java
diff options
context:
space:
mode:
authorMike Vink <mike1994vink@gmail.com>2021-06-22 17:11:42 +0200
committerMike Vink <mike1994vink@gmail.com>2021-06-22 17:11:42 +0200
commit92c61668daefe1486d8ce6aefcf4c60c2eee0c3b (patch)
treef88110b3ec6d9f65bbe3b4183286b276b38fb50e /domain/src/test/java
parent17b594e943eaccc69b6036e258308d1a1ddad53f (diff)
refactor(domain tests) <- configurable state
Diffstat (limited to 'domain/src/test/java')
-rw-r--r--domain/src/test/java/mancala/domain/BowlTest.java547
-rw-r--r--domain/src/test/java/mancala/domain/MancalaImplTest.java23
2 files changed, 309 insertions, 261 deletions
diff --git a/domain/src/test/java/mancala/domain/BowlTest.java b/domain/src/test/java/mancala/domain/BowlTest.java
index 34ca42d..7e1ec01 100644
--- a/domain/src/test/java/mancala/domain/BowlTest.java
+++ b/domain/src/test/java/mancala/domain/BowlTest.java
@@ -2,323 +2,348 @@ package mancala.domain;
import org.junit.jupiter.api.*;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
import static org.junit.jupiter.api.Assertions.*;
+@IndicativeSentencesGeneration(separator = " -> ", generator = DisplayNameGenerator.ReplaceUnderscores.class)
class BowlTest {
- protected void traverseAndCheckBoard(Bowl currentBowl, int position) {
- Bowl initialBowl = currentBowl;
- int traversedCount = 0;
- int currentPosition = 0;
- for (int i = 0; i < 14; i++) {
- if ((position + traversedCount) > 14) {
- // if looping around the board, position = ((start+traversed) - total)
- // in other words the amount of bowls that the absolute position is greater than the board's total bowls
- //
- // Only relevant to check construction btw, also only checking in the case where there are 14 bowls
- currentPosition = ((traversedCount + position) - 14);
- } else
- // Or just use normal position
- currentPosition = position + traversedCount;
-
- // check for kalaha's, and check for smallbowl otherwise
- if (currentPosition == 7 || currentPosition == 14)
- assertEquals(currentBowl.getClass(), Kalaha.class);
- else
- assertEquals(currentBowl.getClass(), SmallBowl.class);
-
- currentBowl = currentBowl.getNextBowl();
- assertNotNull(currentBowl);
- traversedCount++;
- }
- assertSame(initialBowl, currentBowl);
- }
@Nested
- @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
- class For_a_normal_mancala_bowl{
- SmallBowl firstSmallBowlPlayer;
-
- @BeforeEach
- public void makeASmallBowlInMancala() {
- firstSmallBowlPlayer = new SmallBowl();
- traverseAndCheckBoard(firstSmallBowlPlayer, 1);
- }
+ class instantiatingDefaultGame {
- @Nested
- class GIVEN_its_the_start_of_the_game {
- @Test
- public void WHEN_before_any_small_bowls_are_played_THEN_has_four_rocks() {
- Bowl current = firstSmallBowlPlayer;
- for (int i = 0; i < 14; i++) {
- current = current.getNextBowl();
- if (current.getClass() == SmallBowl.class)
- assertEquals(current.getMyStones(), 4);
+ private void checkIfDefaultState(Bowl currentBowl, int position) {
+ Bowl initialBowl = currentBowl;
+ int traversedCount = 0;
+ int currentPosition = 0;
+ for (int i = 0; i < 14; i++) {
+ if ((position + traversedCount) > 14) {
+ // if looping around the board, position = ((start+traversed) - total)
+ // in other words the amount of bowls that the absolute position is greater than the board's total bowls
+ //
+ // Only relevant to check construction btw, also only checking in the case where there are 14 bowls
+ currentPosition = ((traversedCount + position) - 14);
+ } else
+ // Or just use normal position
+ currentPosition = position + traversedCount;
+
+ // check for kalaha's, and check for smallbowl otherwise
+ if (currentPosition == 7 || currentPosition == 14) {
+ assertEquals(currentBowl.getClass(), Kalaha.class);
+ assertEquals(0, currentBowl.getMyStones(),
+ "In a 'normal' game the kalaha should have 0 rocks when created.");
+ } else {
+ assertEquals(currentBowl.getClass(), SmallBowl.class);
+ assertEquals(4, currentBowl.getMyStones(),
+ "In a 'normal' game the smallbowl should have 4 rocks when created.");
}
- assertSame(current, firstSmallBowlPlayer);
- }
- @Test
- public void WHEN_chosen_by_the_player_that_has_the_turn_THEN_distribute_its_rocks_anti_clockwise() {
- int initialRocks = firstSmallBowlPlayer.getMyStones();
- firstSmallBowlPlayer.play();
- Bowl neighbour = firstSmallBowlPlayer.getNextBowl();
- for (int i = 0; i < initialRocks; i++) {
- assertEquals(5, neighbour.getMyStones());
- neighbour = neighbour.getNextBowl();
- }
- assertEquals(4, neighbour.getMyStones());
+ currentBowl = currentBowl.getNextBowl();
+ assertNotNull(currentBowl);
+ traversedCount++;
}
+ assertSame(initialBowl, currentBowl);
+ }
+
+ SmallBowl referenceSmallBowl = new SmallBowl();
+
+ @Test
+ public void default_stones_amount_check() {
+ checkIfDefaultState(referenceSmallBowl, 1);
}
@Nested
- class GIVEN_the_game_is_in_a_state_where {
+ class given_a_small_bowl {
+
+ @Nested
+ class and_its_the_start_of_the_game {
+ @Test
+ public void when_getMyStones_is_called_then_it_returns_four() {
+ SmallBowl next = referenceSmallBowl.getNextSmallBowl();
+ while (!next.equals(referenceSmallBowl)) {
+ assertEquals(4, next.getMyStones());
+ next = next.getNextSmallBowl();
+ }
+ }
- @Test
- public void its_not_the_players_turn_WHEN_played_by_the_player_THEN_nothing_happens() {
- firstSmallBowlPlayer.getMyOwner().switchTurn();
- int initialRocks = firstSmallBowlPlayer.getMyStones();
- firstSmallBowlPlayer.play();
- Bowl neighbour = firstSmallBowlPlayer.getNextBowl();
- for (int i = 0; i < initialRocks; i++) {
+ @Test
+ public void when_play_is_called_and_owner_has_turn_then_distribute_its_rocks_anti_clockwise() {
+ int initialRocks = referenceSmallBowl.getMyStones();
+ referenceSmallBowl.play();
+ Bowl neighbour = referenceSmallBowl.getNextBowl();
+ for (int i = 0; i < initialRocks; i++) {
+ assertEquals(5, neighbour.getMyStones());
+ neighbour = neighbour.getNextBowl();
+ }
assertEquals(4, neighbour.getMyStones());
- neighbour = neighbour.getNextBowl();
}
- assertEquals(4, neighbour.getMyStones());
}
- @Test
- public void play_can_reach_opponents_kalaha_WHEN_played_by_the_player_THEN_opponents_kalaha_is_skipped() {
- SmallBowl playWillSkipFromThisBowl = goToSkippableState();
- int opponentKalahaRocksBefore = firstSmallBowlPlayer.getNextSmallBowlTimes(11).getNextBowl().getMyStones();
- playWillSkipFromThisBowl.play();
- int opponentKalahaRocksAfter = firstSmallBowlPlayer.getNextSmallBowlTimes(11).getNextBowl().getMyStones();
- assertEquals(opponentKalahaRocksBefore, opponentKalahaRocksAfter);
- }
+ @Nested
+ class and_the_game_is_in_a_state_where {
+
+ @Test
+ public void its_not_the_players_turn_when_play_is_called_then_nothing_happens() {
+ referenceSmallBowl.getMyOwner().switchTurn();
+ int initialRocks = referenceSmallBowl.getMyStones();
+ referenceSmallBowl.play();
+ Bowl neighbour = referenceSmallBowl.getNextBowl();
+ for (int i = 0; i < initialRocks; i++) {
+ assertEquals(4, neighbour.getMyStones());
+ neighbour = neighbour.getNextBowl();
+ }
+ assertEquals(4, neighbour.getMyStones());
+ }
- @Test
- public void the_bowl_is_empty_WHEN_the_player_plays_the_empty_bowl_THEN_nothing_happens() {
- firstSmallBowlPlayer.play();
- firstSmallBowlPlayer.getMyOwner().switchTurn();
- assertTrue(firstSmallBowlPlayer.getMyOwner().hasTheTurn());
- firstSmallBowlPlayer.play();
- assertTrue(firstSmallBowlPlayer.getMyOwner().hasTheTurn());
- assertEquals(5, firstSmallBowlPlayer.getNextBowl().getMyStones());
- }
+ @Test
+ public void the_bowl_is_empty_WHEN_the_player_plays_the_empty_bowl_THEN_nothing_happens() {
+ referenceSmallBowl.play();
+ referenceSmallBowl.getMyOwner().switchTurn();
+ assertTrue(referenceSmallBowl.getMyOwner().hasTheTurn());
+ referenceSmallBowl.play();
+ assertTrue(referenceSmallBowl.getMyOwner().hasTheTurn());
+ assertEquals(5, referenceSmallBowl.getNextBowl().getMyStones());
+ }
- @Test
- public void all_small_bowls_of_the_player_are_empty_WHEN_a_play_ends_THEN_tell_players_who_won() {
- Player player = firstSmallBowlPlayer.getMyOwner();
- Player opponent = firstSmallBowlPlayer.getNextSmallBowlTimes(6).getMyOwner();
- assertFalse(player.won());
- assertFalse(opponent.won());
- goToEndOfSillyGame();
- assertTrue(player.won());
- assertFalse(opponent.won());
+ @Test
+ public void all_small_bowls_of_the_player_are_empty_WHEN_a_play_ends_THEN_tell_players_who_won() {
+ Player player = referenceSmallBowl.getMyOwner();
+ Player opponent = referenceSmallBowl.getNextSmallBowlTimes(6).getMyOwner();
+ assertFalse(player.won());
+ assertFalse(opponent.won());
+ goToEndOfSillyGame();
+ assertTrue(player.won());
+ assertFalse(opponent.won());
- }
+ }
- @Test
- public void all_small_bowls_of_the_player_are_empty_WHEN_a_play_ends_THEN_tell_players_who_wonOPPONENTVARIATION() {
- Player player = firstSmallBowlPlayer.getMyOwner();
- Player opponent = firstSmallBowlPlayer.getNextSmallBowlTimes(6).getMyOwner();
- goToEndOfGameWhereOpponentWins();
- assertFalse(player.won());
- assertTrue(opponent.won());
- }
+ @Test
+ public void all_small_bowls_of_the_player_are_empty_WHEN_a_play_ends_THEN_tell_players_who_wonOPPONENTVARIATION() {
+ Player player = referenceSmallBowl.getMyOwner();
+ Player opponent = referenceSmallBowl.getNextSmallBowlTimes(6).getMyOwner();
+ goToEndOfGameWhereOpponentWins();
+ assertFalse(player.won());
+ assertTrue(opponent.won());
+ }
- @Test
- public void the_play_would_skip_past_opponent_kalaha_at_the_last_rock_and_steal_WHEN_played_THEN_should_skip_and_steal_correctly() {
- goToSkipAndStealOnLast();
- SmallBowl firstSmallBowlOpponent = firstSmallBowlPlayer.getNextSmallBowlTimes(6);
- assertEquals(3, firstSmallBowlPlayer.getNextSmallBowlTimes(5).getNextBowl().getMyStones());
- firstSmallBowlOpponent.getNextSmallBowlTimes(3).play();
- assertEquals(19, firstSmallBowlOpponent.getNextSmallBowlTimes(5).getNextBowl().getMyStones());
- }
+ @Test
+ public void the_play_would_skip_past_opponent_kalaha_at_the_last_rock_and_steal_WHEN_played_THEN_should_skip_and_steal_correctly() {
+ goToSkipAndStealOnLast();
+ SmallBowl firstSmallBowlOpponent = referenceSmallBowl.getNextSmallBowlTimes(6);
+ assertEquals(3, referenceSmallBowl.getNextSmallBowlTimes(5).getNextBowl().getMyStones());
+ firstSmallBowlOpponent.getNextSmallBowlTimes(3).play();
+ assertEquals(19, firstSmallBowlOpponent.getNextSmallBowlTimes(5).getNextBowl().getMyStones());
+ }
- private void goToSkipAndStealOnLast() {
- SmallBowl firstSmallBowlOpponent = firstSmallBowlPlayer.getNextSmallBowlTimes(6);
- firstSmallBowlPlayer.getNextSmallBowlTimes(1).play();
- firstSmallBowlOpponent.getNextSmallBowlTimes(2).play();
- firstSmallBowlOpponent.getNextSmallBowlTimes(5).play();
- firstSmallBowlPlayer.getNextSmallBowlTimes(1).play();
- firstSmallBowlOpponent.getNextSmallBowlTimes(1).play();
- firstSmallBowlPlayer.getNextSmallBowlTimes(2).play();
- firstSmallBowlOpponent.play();
- firstSmallBowlPlayer.getNextSmallBowlTimes(3).play();
- firstSmallBowlOpponent.getNextSmallBowlTimes(1).play();
- firstSmallBowlPlayer.getNextSmallBowlTimes(4).play();
- firstSmallBowlOpponent.play();
- // Cheating here, let player go again >:), i'm too dumb too make a loop/skip and steal play happen in fair game
- firstSmallBowlOpponent.getMyOwner().switchTurn();
- // Should skip and steal
- // this bowls rocks
- assertEquals(10, firstSmallBowlOpponent.getNextSmallBowlTimes(3).getMyStones());
- // End up here by looping around the board, thus skipping
- assertEquals(0, firstSmallBowlOpponent.getMyStones());
- // Thus steal from last bowl on players side
- assertEquals(8, firstSmallBowlPlayer.getNextSmallBowlTimes(5).getMyStones());
- // Result is big kalaha booty
- assertEquals(8, firstSmallBowlOpponent.getNextSmallBowlTimes(5).getNextBowl().getMyStones());
- }
+ private void goToSkipAndStealOnLast() {
+ SmallBowl firstSmallBowlOpponent = referenceSmallBowl.getNextSmallBowlTimes(6);
+ referenceSmallBowl.getNextSmallBowlTimes(1).play();
+ firstSmallBowlOpponent.getNextSmallBowlTimes(2).play();
+ firstSmallBowlOpponent.getNextSmallBowlTimes(5).play();
+ referenceSmallBowl.getNextSmallBowlTimes(1).play();
+ firstSmallBowlOpponent.getNextSmallBowlTimes(1).play();
+ referenceSmallBowl.getNextSmallBowlTimes(2).play();
+ firstSmallBowlOpponent.play();
+ referenceSmallBowl.getNextSmallBowlTimes(3).play();
+ firstSmallBowlOpponent.getNextSmallBowlTimes(1).play();
+ referenceSmallBowl.getNextSmallBowlTimes(4).play();
+ firstSmallBowlOpponent.play();
+ // Cheating here, let player go again >:), i'm too dumb too make a loop/skip and steal play happen in fair game
+ firstSmallBowlOpponent.getMyOwner().switchTurn();
+ // Should skip and steal
+ // this bowls rocks
+ assertEquals(10, firstSmallBowlOpponent.getNextSmallBowlTimes(3).getMyStones());
+ // End up here by looping around the board, thus skipping
+ assertEquals(0, firstSmallBowlOpponent.getMyStones());
+ // Thus steal from last bowl on players side
+ assertEquals(8, referenceSmallBowl.getNextSmallBowlTimes(5).getMyStones());
+ // Result is big kalaha booty
+ assertEquals(8, firstSmallBowlOpponent.getNextSmallBowlTimes(5).getNextBowl().getMyStones());
+ }
- private void goToEndOfGameWhereOpponentWins() {
- goToSkipAndStealOnLast();
- SmallBowl firstSmallBowlOpponent = firstSmallBowlPlayer.getNextSmallBowlTimes(6);
- firstSmallBowlOpponent.getNextSmallBowlTimes(3).play();
- firstSmallBowlPlayer.getNextSmallBowlTimes(1).play();
- firstSmallBowlOpponent.getNextSmallBowlTimes(1).play();
- firstSmallBowlPlayer.play();
- firstSmallBowlPlayer.getMyOwner().switchTurn();
- firstSmallBowlPlayer.getNextSmallBowlTimes(3).play();
- firstSmallBowlPlayer.getMyOwner().switchTurn();
- firstSmallBowlPlayer.getNextSmallBowlTimes(4).play();
- firstSmallBowlPlayer.getNextSmallBowlTimes(5).play();
- }
+ private void goToEndOfGameWhereOpponentWins() {
+ goToSkipAndStealOnLast();
+ SmallBowl firstSmallBowlOpponent = referenceSmallBowl.getNextSmallBowlTimes(6);
+ firstSmallBowlOpponent.getNextSmallBowlTimes(3).play();
+ referenceSmallBowl.getNextSmallBowlTimes(1).play();
+ firstSmallBowlOpponent.getNextSmallBowlTimes(1).play();
+ referenceSmallBowl.play();
+ referenceSmallBowl.getMyOwner().switchTurn();
+ referenceSmallBowl.getNextSmallBowlTimes(3).play();
+ referenceSmallBowl.getMyOwner().switchTurn();
+ referenceSmallBowl.getNextSmallBowlTimes(4).play();
+ referenceSmallBowl.getNextSmallBowlTimes(5).play();
+ }
+
+ private void goToEndOfSillyGame() {
+ SmallBowl firstSmallBowlOpponent = referenceSmallBowl.getNextSmallBowlTimes(6);
+
+ // player
+ // Best opening
+ referenceSmallBowl.getNextSmallBowlTimes(2).play();
+ // Set up for steal move
+ referenceSmallBowl.getNextSmallBowlTimes(4).play();
+ assertEquals(2, referenceSmallBowl.getKalaha().getMyStones());
+
+ // opponent
+ // ... worst opening?
+ firstSmallBowlOpponent.play();
+
+ // player
+ assertSame(referenceSmallBowl.getNextSmallBowlTimes(4).getOpposite(), referenceSmallBowl.getKalaha().getNextBowl().getNextBowl());
+ referenceSmallBowl.play();
+ // Check if i did it properly on paper
+ assertEquals(9, referenceSmallBowl.getKalaha().getMyStones());
+ assertEquals(0, referenceSmallBowl.getNextSmallBowlTimes(4).getMyStones());
+ // assertEquals(0, firstSmallBowlPlayer.getNextSmallBowlTimes(4).getOpposite().getMyRocks());
+
+ // opponent
+ firstSmallBowlOpponent.getNextSmallBowlTimes(3).play();
+
+ //Player
+ referenceSmallBowl.getNextSmallBowlTimes(3).play();
+ assertEquals(10, referenceSmallBowl.getNextSmallBowlTimes(5).getNextBowl().getMyStones());
+
+ // opponent makes stupid move again
+ firstSmallBowlOpponent.getNextSmallBowlTimes(1).play();
+
+ // player makes big steal
+ //assertEquals(0, firstSmallBowlPlayer.getNextSmallBowlTimes(5).getNextBowl().getMyRocks());
+ assertEquals(10, referenceSmallBowl.getNextSmallBowlTimes(5).getNextBowl().getMyStones());
+ referenceSmallBowl.getNextSmallBowlTimes(2).play();
+ assertEquals(19, referenceSmallBowl.getNextSmallBowlTimes(5).getNextBowl().getMyStones());
+
+ // opponent steals tiny booty
+ firstSmallBowlOpponent.play();
+ assertEquals(3, firstSmallBowlOpponent.getNextSmallBowlTimes(5).getNextBowl().getMyStones());
+
+ // player is stalling until the end
+ referenceSmallBowl.play();
+
+ // opponent is heading for disaster
+ firstSmallBowlOpponent.getNextSmallBowlTimes(5).play();
+ referenceSmallBowl.play();
+ firstSmallBowlOpponent.getNextSmallBowlTimes(4).play();
+ referenceSmallBowl.play();
+ firstSmallBowlOpponent.getNextSmallBowlTimes(5).play();
+ // everything empty!
+ for (int i = 0; i < 6; i++) {
+ assertEquals(0, firstSmallBowlOpponent.getNextSmallBowlTimes(i).getMyStones());
+ }
- private void goToEndOfSillyGame() {
- SmallBowl firstSmallBowlOpponent = firstSmallBowlPlayer.getNextSmallBowlTimes(6);
-
- // player
- // Best opening
- firstSmallBowlPlayer.getNextSmallBowlTimes(2).play();
- // Set up for steal move
- firstSmallBowlPlayer.getNextSmallBowlTimes(4).play();
- assertEquals(2, firstSmallBowlPlayer.getKalaha().getMyStones());
-
- // opponent
- // ... worst opening?
- firstSmallBowlOpponent.play();
-
- // player
- assertSame(firstSmallBowlPlayer.getNextSmallBowlTimes(4).getOpposite(), firstSmallBowlPlayer.getKalaha().getNextBowl().getNextBowl());
- firstSmallBowlPlayer.play();
- // Check if i did it properly on paper
- assertEquals(9, firstSmallBowlPlayer.getKalaha().getMyStones());
- assertEquals(0, firstSmallBowlPlayer.getNextSmallBowlTimes(4).getMyStones());
- // assertEquals(0, firstSmallBowlPlayer.getNextSmallBowlTimes(4).getOpposite().getMyRocks());
-
- // opponent
- firstSmallBowlOpponent.getNextSmallBowlTimes(3).play();
-
- //Player
- firstSmallBowlPlayer.getNextSmallBowlTimes(3).play();
- assertEquals(10, firstSmallBowlPlayer.getNextSmallBowlTimes(5).getNextBowl().getMyStones());
-
- // opponent makes stupid move again
- firstSmallBowlOpponent.getNextSmallBowlTimes(1).play();
-
- // player makes big steal
- //assertEquals(0, firstSmallBowlPlayer.getNextSmallBowlTimes(5).getNextBowl().getMyRocks());
- assertEquals(10, firstSmallBowlPlayer.getNextSmallBowlTimes(5).getNextBowl().getMyStones());
- firstSmallBowlPlayer.getNextSmallBowlTimes(2).play();
- assertEquals(19, firstSmallBowlPlayer.getNextSmallBowlTimes(5).getNextBowl().getMyStones());
-
- // opponent steals tiny booty
- firstSmallBowlOpponent.play();
- assertEquals(3, firstSmallBowlOpponent.getNextSmallBowlTimes(5).getNextBowl().getMyStones());
-
- // player is stalling until the end
- firstSmallBowlPlayer.play();
-
- // opponent is heading for disaster
- firstSmallBowlOpponent.getNextSmallBowlTimes(5).play();
- firstSmallBowlPlayer.play();
- firstSmallBowlOpponent.getNextSmallBowlTimes(4).play();
- firstSmallBowlPlayer.play();
- firstSmallBowlOpponent.getNextSmallBowlTimes(5).play();
- // everything empty!
- for (int i = 0; i < 6; i++) {
- assertEquals(0, firstSmallBowlOpponent.getNextSmallBowlTimes(i).getMyStones());
}
+ private SmallBowl goToSkippableState() {
+ SmallBowl firstSmallBowlOpponent = referenceSmallBowl.getNextSmallBowlTimes(6);
+
+ referenceSmallBowl.getNextSmallBowlTimes(2).play();
+ referenceSmallBowl.getNextSmallBowlTimes(3).play();
+
+ firstSmallBowlOpponent.getNextSmallBowlTimes(2).play();
+ firstSmallBowlOpponent.getNextSmallBowlTimes(3).play();
+
+ referenceSmallBowl.play();
+ firstSmallBowlOpponent.play();
+
+ referenceSmallBowl.getNextSmallBowlTimes(4).play();
+ firstSmallBowlOpponent.getNextSmallBowlTimes(4).play();
+
+ // Playing this bowl should give a skip!
+ assertTrue(referenceSmallBowl.getNextSmallBowlTimes(5).getMyStones() >= 8);
+ return referenceSmallBowl.getNextSmallBowlTimes(5);
+ }
}
- private SmallBowl goToSkippableState() {
- SmallBowl firstSmallBowlOpponent = firstSmallBowlPlayer.getNextSmallBowlTimes(6);
+ @Nested
+ class GIVEN_the_play_ends{
- firstSmallBowlPlayer.getNextSmallBowlTimes(2).play();
- firstSmallBowlPlayer.getNextSmallBowlTimes(3).play();
+ @Test
+ public void in_own_kalaha_WHEN_play_ends_THEN_turn_is_not_switched() {
+ referenceSmallBowl.getNextSmallBowlTimes(2).play();
+ assertTrue(referenceSmallBowl.getMyOwner().hasTheTurn());
+ }
- firstSmallBowlOpponent.getNextSmallBowlTimes(2).play();
- firstSmallBowlOpponent.getNextSmallBowlTimes(3).play();
+ @Test
+ public void in_own_small_bowl_WHEN_play_ends_THEN_turn_is_switched() {
+ referenceSmallBowl.play();
+ assertFalse(referenceSmallBowl.getMyOwner().hasTheTurn());
+ }
- firstSmallBowlPlayer.play();
- firstSmallBowlOpponent.play();
+ @Test
+ public void in_opponents_small_bowl_WHEN_player_plays_this_bowl_THEN_turn_is_switched() {
+ referenceSmallBowl.getNextSmallBowlTimes(5).play();
+ assertFalse(referenceSmallBowl.getMyOwner().hasTheTurn());
+ }
- firstSmallBowlPlayer.getNextSmallBowlTimes(4).play();
- firstSmallBowlOpponent.getNextSmallBowlTimes(4).play();
+ @Test
+ public void in_own_empty_small_bowl_and_opposite_has_rocks_WHEN_play_ends_THEN_rocks_of_opposite_plus_last_rock_of_play_are_added_to_kalaha() {
+ referenceSmallBowl.getNextSmallBowlTimes(5).play();
+ SmallBowl firstSmallBowlOpponent = referenceSmallBowl.getNextSmallBowlTimes(6);
+ firstSmallBowlOpponent.getNextSmallBowlTimes(5).play();
+ assertSame(referenceSmallBowl.getNextSmallBowlTimes(1).getOpposite(), referenceSmallBowl.getKalaha().getNextSmallBowl().getNextSmallBowlTimes(4));
+ // assertSame(firstSmallBowlPlayer.getOpposite(), firstSmallBowlPlayer.getKalaha().getNextSmallBowlTimes(5));
+ referenceSmallBowl.play();
+ assertEquals(7, referenceSmallBowl.getNextSmallBowlTimes(5).getNextBowl().getMyStones());
+ }
- // Playing this bowl should give a skip!
- assertTrue(firstSmallBowlPlayer.getNextSmallBowlTimes(5).getMyStones() >= 8);
- return firstSmallBowlPlayer.getNextSmallBowlTimes(5);
}
+
+
}
@Nested
- class GIVEN_the_play_ends{
+ class given_a_kalaha {
- @Test
- public void in_own_kalaha_WHEN_play_ends_THEN_turn_is_not_switched() {
- firstSmallBowlPlayer.getNextSmallBowlTimes(2).play();
- assertTrue(firstSmallBowlPlayer.getMyOwner().hasTheTurn());
- }
-
- @Test
- public void in_own_small_bowl_WHEN_play_ends_THEN_turn_is_switched() {
- firstSmallBowlPlayer.play();
- assertFalse(firstSmallBowlPlayer.getMyOwner().hasTheTurn());
- }
+ Kalaha playerKalaha;
+ Kalaha opponentKalaha;
- @Test
- public void in_opponents_small_bowl_WHEN_player_plays_this_bowl_THEN_turn_is_switched() {
- firstSmallBowlPlayer.getNextSmallBowlTimes(5).play();
- assertFalse(firstSmallBowlPlayer.getMyOwner().hasTheTurn());
+ @BeforeEach
+ public void makeKalahaInBoard() {
+ playerKalaha = referenceSmallBowl.getKalaha();
+ opponentKalaha = referenceSmallBowl.getKalaha().getNextSmallBowl().getKalaha();
}
@Test
- public void in_own_empty_small_bowl_and_opposite_has_rocks_WHEN_play_ends_THEN_rocks_of_opposite_plus_last_rock_of_play_are_added_to_kalaha() {
- firstSmallBowlPlayer.getNextSmallBowlTimes(5).play();
- SmallBowl firstSmallBowlOpponent = firstSmallBowlPlayer.getNextSmallBowlTimes(6);
- firstSmallBowlOpponent.getNextSmallBowlTimes(5).play();
- assertSame(firstSmallBowlPlayer.getNextSmallBowlTimes(1).getOpposite(), firstSmallBowlPlayer.getKalaha().getSmallBowl().getNextSmallBowlTimes(4));
- // assertSame(firstSmallBowlPlayer.getOpposite(), firstSmallBowlPlayer.getKalaha().getNextSmallBowlTimes(5));
- firstSmallBowlPlayer.play();
- assertEquals(7, firstSmallBowlPlayer.getNextSmallBowlTimes(5).getNextBowl().getMyStones());
+ public void when_getMyStones_is_called_after_instantiating_then_has_zero_stones() {
+ assertEquals(0, playerKalaha.getMyStones());
+ assertEquals(0, opponentKalaha.getMyStones());
}
-
}
-
}
- @Nested
- @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
- class a_kalaha {
-
- SmallBowl smallBowl;
- Kalaha kalaha;
- @BeforeEach
- public void makeKalahaInBoard() {
- smallBowl = new SmallBowl();
- kalaha = smallBowl.getNextSmallBowlTimes(6).getKalaha();
- }
+ @Nested
+ class instantiatingGameWithStonesList {
+ SmallBowl referenceSmallBowl;
@Test
- public void exists_in_a_mancala_board() {
- traverseAndCheckBoard(kalaha, 14);
+ void given_a_stones_list_when_instantiating_a_small_bowl_then_configure_stones_as_in_list() {
+ int[] stonesArray = new int[] {1,2,3,4,5,6,7,8,9,10,11,12,13,14};
+ List<Integer> stonesList = Arrays.stream(stonesArray).boxed().collect(Collectors.toList());
+ referenceSmallBowl = new SmallBowl(stonesList);
+ for (int i = 0; i < stonesArray.length; i++) {
+ if (i < 6) assertEquals(stonesArray[i], referenceSmallBowl.getNextSmallBowlTimes(i).getMyStones());
+ else if (i == 6) assertEquals(stonesArray[i], referenceSmallBowl.getKalaha().getMyStones());
+ else if (i == 13) assertEquals(stonesArray[i], referenceSmallBowl.getKalaha().getNextBowl().getKalaha().getMyStones());
+ else {
+ int index = i - 1;
+ assertEquals(stonesArray[i], referenceSmallBowl.getNextSmallBowlTimes(index).getMyStones());
+ }
+ }
}
@Test
- public void has_zero_rocks_when_created() {
- Bowl current = kalaha;
- for (int i = 0; i < 14; i++) {
- current = current.getNextBowl();
- if (current.getClass() == Kalaha.class)
- assertEquals(current.getMyStones(), 0);
- }
+ public void given_stones_can_reach_oppenent_kalaha_when_played_validly_then_opponents_kalaha_is_skipped() {
+ SmallBowl playWillSkipFromThisBowl = goToSkippableState();
+ int opponentKalahaRocksBefore = referenceSmallBowl.getNextSmallBowlTimes(11).getNextBowl().getMyStones();
+ playWillSkipFromThisBowl.play();
+ int opponentKalahaRocksAfter = referenceSmallBowl.getNextSmallBowlTimes(11).getNextBowl().getMyStones();
+ assertEquals(opponentKalahaRocksBefore, opponentKalahaRocksAfter);
}
}
} \ No newline at end of file
diff --git a/domain/src/test/java/mancala/domain/MancalaImplTest.java b/domain/src/test/java/mancala/domain/MancalaImplTest.java
index b040b02..6f0ce2a 100644
--- a/domain/src/test/java/mancala/domain/MancalaImplTest.java
+++ b/domain/src/test/java/mancala/domain/MancalaImplTest.java
@@ -173,13 +173,36 @@ class MancalaImplTest {
@Nested
class isEndOfGame {
+ @Test
void given_the_game_is_not_ended_when_isEndOfGame_is_called_then_return_false() {
assertFalse(mancala.isEndOfGame());
}
+
+ @Test
+ void given_the_game_is_ended_when_isEndOfGame_is_called_then_return_true() {
+ assertTrue(mancala.isEndOfGame());
+ }
+
+
}
@Nested
class getWinner {
+ @Test
+ void given_the_game_has_not_ended_when_getWinner_is_called_then_immediately_return_Mancala_NO_PLAYERS() {
+ assertEquals(Mancala.NO_PLAYERS, mancala.getWinner());
+ }
+
+ @Test
+ void given_PLAYER_ONE_has_won_in_the_domain_model_when_getWinner_is_called_then_return_Mancala_PLAYER_ONE() {
+ assertEquals(Mancala.PLAYER_ONE, mancala.getWinner());
+ }
+
+ @Test
+ void given_PLAYER_TWO_has_won_in_the_domain_model_when_getWinner_is_called_then_return_Mancala_PLAYER_TWO() {
+ assertEquals(Mancala.PLAYER_TWO, mancala.getWinner());
+ }
+
}
void assumeTurn(int player) {