diff options
| author | Mike Vink <mike1994vink@gmail.com> | 2021-06-21 18:13:31 +0200 |
|---|---|---|
| committer | Mike Vink <mike1994vink@gmail.com> | 2021-06-21 18:13:31 +0200 |
| commit | 653764b4fcd3fd951cb1ca7b7993a1736fd9dda6 (patch) | |
| tree | 9c09d18a4c91a4641c88285aa730f19451ea5ce7 /domain | |
| parent | d70d47add575d03d43fbf1ce81b32734e556c4b5 (diff) | |
merge mainline domain with mvcFeature domain
Diffstat (limited to 'domain')
| -rw-r--r-- | domain/build.gradle | 3 | ||||
| -rw-r--r-- | domain/src/main/java/mancala/domain/Bowl.java | 61 | ||||
| -rw-r--r-- | domain/src/main/java/mancala/domain/Kalaha.java | 51 | ||||
| -rw-r--r-- | domain/src/main/java/mancala/domain/Player.java | 52 | ||||
| -rw-r--r-- | domain/src/main/java/mancala/domain/SmallBowl.java | 114 | ||||
| -rw-r--r-- | domain/src/main/main.iml | 11 | ||||
| -rw-r--r-- | domain/src/test/java/mancala/domain/BowlTest.java | 324 | ||||
| -rw-r--r-- | domain/src/test/java/mancala/domain/PlayerTest.java | 46 | ||||
| -rw-r--r-- | domain/src/test/test.iml | 28 |
9 files changed, 689 insertions, 1 deletions
diff --git a/domain/build.gradle b/domain/build.gradle index aea31e5..001d2dd 100644 --- a/domain/build.gradle +++ b/domain/build.gradle @@ -13,9 +13,10 @@ dependencies { // Download JUnit so that we can use it in our tests. testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.2' + testRuntimeOnly "org.junit.platform:junit-platform-commons:1.7.0" } test { // For running our tests, use the test runner provided by JUnit. useJUnitPlatform() -}
\ No newline at end of file +} diff --git a/domain/src/main/java/mancala/domain/Bowl.java b/domain/src/main/java/mancala/domain/Bowl.java new file mode 100644 index 0000000..ade728d --- /dev/null +++ b/domain/src/main/java/mancala/domain/Bowl.java @@ -0,0 +1,61 @@ +package mancala.domain; + +abstract class Bowl { + protected int myRocks; + protected Player myOwner; + protected Bowl nextBowl; + + public int getMyRocks() { + return myRocks; + } + + public Bowl getNextBowl() { + return nextBowl; + } + + public Player getMyOwner() { + return myOwner; + } + + abstract void distribute(int remainingRocks); + + abstract SmallBowl getOpposite(int i); + + abstract SmallBowl getNextSmallBowlTimes(int i); + + abstract Kalaha getKalaha(); + + abstract SmallBowl getSmallBowl(); + + // abstract SmallBowl getNextSmallBowl(); + + void endTheGame() { + getNextBowl().endTheGame(this, 0, 0); + } + + abstract boolean isEmpty(); + + private void endTheGame(Bowl startOfLoop, int scorePlayer, int scoreOpponent) { + if (isEmpty() == false && myOwner.hasTheTurn()) return; + + if (getMyOwner().equals(startOfLoop.getMyOwner())) { + scorePlayer = scorePlayer + getMyRocks(); + } else scoreOpponent = scoreOpponent + getMyRocks(); + + if (this.equals(startOfLoop)) { + + int playerKalaha = getKalaha().getMyRocks(); + + if (scorePlayer == playerKalaha) { + + if (scorePlayer == scoreOpponent) getMyOwner().gotADraw(); + else if (scorePlayer > scoreOpponent) getMyOwner().isTheWinner(); + else getMyOwner().getOpponent().isTheWinner(); + + } + + + } else getNextBowl().endTheGame(startOfLoop, scorePlayer, scoreOpponent); + } + +} diff --git a/domain/src/main/java/mancala/domain/Kalaha.java b/domain/src/main/java/mancala/domain/Kalaha.java new file mode 100644 index 0000000..9e70e6c --- /dev/null +++ b/domain/src/main/java/mancala/domain/Kalaha.java @@ -0,0 +1,51 @@ +package mancala.domain; + +class Kalaha extends Bowl { + Kalaha(int boardSize, int bowlsToAdd, Bowl startBowl, Player playerOwningThisSide) { + bowlsToAdd = bowlsToAdd - 1; + + this.myRocks = 0; + this.myOwner = playerOwningThisSide; + + if (bowlsToAdd == 0) this.nextBowl = startBowl; + + else this.nextBowl = new SmallBowl(boardSize, bowlsToAdd, startBowl, playerOwningThisSide.getOpponent()); + } + + Kalaha getKalaha() { + return this; + } + + SmallBowl getSmallBowl() { + return getNextBowl().getSmallBowl(); + } + + SmallBowl getOpposite(int countTillThis) { + return getNextBowl().getNextSmallBowlTimes(countTillThis - 1); + } + + SmallBowl getNextSmallBowlTimes(int i) { + return getNextBowl().getNextSmallBowlTimes(i); + } + + void distribute(int remainingRocks) { + myRocks++; + // Skip? + if (getMyOwner().hasTheTurn() == false) { + myRocks--; + getNextBowl().distribute(remainingRocks); + } else if (remainingRocks == 1) { + endTheGame(); + } else getNextBowl().distribute(--remainingRocks); + } + + @Override + boolean isEmpty() { + return true; + } + + + void claimStolenBooty(int booty) { + myRocks = myRocks + booty; + } +} diff --git a/domain/src/main/java/mancala/domain/Player.java b/domain/src/main/java/mancala/domain/Player.java new file mode 100644 index 0000000..1eef716 --- /dev/null +++ b/domain/src/main/java/mancala/domain/Player.java @@ -0,0 +1,52 @@ +package mancala.domain; + +public class Player { + private boolean hasTheTurn; + private boolean isTheWinner; + final private Player opponent; + + public Player() { + this.hasTheTurn = true; + + this.opponent = new Player(this); + } + + private Player(Player opponent) { + this.hasTheTurn = false; + + this.opponent = opponent; + } + + public Player getOpponent() { + return opponent; + } + + public boolean hasTheTurn() { + return hasTheTurn; + } + + public void switchTurn() { + if (this.hasTheTurn == true) { + this.hasTheTurn = false; + this.opponent.hasTheTurn = true; + } else { + this.hasTheTurn = true; + this.opponent.hasTheTurn = false; + } + } + + public boolean won() { + return this.isTheWinner; + } + + void isTheWinner() { + this.isTheWinner = true; + this.opponent.isTheWinner = false; + } + + void gotADraw() { + this.isTheWinner = true; + this.opponent.isTheWinner = true; + } + +} diff --git a/domain/src/main/java/mancala/domain/SmallBowl.java b/domain/src/main/java/mancala/domain/SmallBowl.java new file mode 100644 index 0000000..5c97d72 --- /dev/null +++ b/domain/src/main/java/mancala/domain/SmallBowl.java @@ -0,0 +1,114 @@ +package mancala.domain; + +public class SmallBowl extends Bowl { + + public SmallBowl() { + this.myRocks = 4; + this.myOwner = new Player(); + + int boardSize = 14; + int bowlsToAdd = boardSize - 1; + + this.nextBowl = new SmallBowl(boardSize, bowlsToAdd, this, this.getMyOwner()); + } + + public SmallBowl(int boardSize) { + try { + if (boardSize < 4) { + throw new Exception("Can't have a board smaller than four bowls."); + } + } catch (Exception e) { + e.printStackTrace(); + } + this.myRocks = 4; + this.myOwner = new Player(); + int bowlsToAdd = boardSize - 1; + this.nextBowl = new SmallBowl(boardSize, bowlsToAdd, this, this.getMyOwner()); + } + + SmallBowl(int boardSize, int bowlsToAdd, Bowl startBowl, Player playerOwningThisSide) { + bowlsToAdd = bowlsToAdd - 1; + this.myOwner = playerOwningThisSide; + this.myRocks = 4; + + if (bowlsToAdd == 0) nextBowl = startBowl; + + else if (bowlsToAdd == (boardSize / 2) + 1) nextBowl = new Kalaha(boardSize, bowlsToAdd, startBowl, playerOwningThisSide); + + else if (bowlsToAdd == 1) nextBowl = new Kalaha(boardSize, bowlsToAdd, startBowl, playerOwningThisSide); + + else nextBowl = new SmallBowl(boardSize, bowlsToAdd, startBowl, playerOwningThisSide); + } + + public SmallBowl getNextSmallBowlTimes(int remainingTimes) { + if (remainingTimes == 0) + return this; + else { + return getNextBowl().getNextSmallBowlTimes(--remainingTimes); + } + } + + public void play() { + if (myOwner.hasTheTurn() == false) return; + if (isEmpty()) return; + + int passThese = myRocks; + myRocks = 0; + getNextBowl().distribute(passThese); + } + + @Override + boolean isEmpty() { + return this.myRocks == 0; + } + + void distribute(int remainingRocks) { + this.myRocks++; + // last? + if (remainingRocks == 1) + lastSmallBowl(); + else { + getNextBowl().distribute(--remainingRocks); + } + } + + private void lastSmallBowl() { + // Did play end in smallbowl of my player? steal, otherwise do nothing + if (getMyOwner().hasTheTurn()) stealTheBooty(false); + + getMyOwner().switchTurn(); + + endTheGame(); + } + + SmallBowl getSmallBowl() { + return this; + } + + Kalaha getKalaha() { + return getNextBowl().getKalaha(); + } + + private void stealTheBooty(boolean victim) { + if (victim){ + getOpposite().getKalaha().claimStolenBooty(myRocks); + myRocks = 0; + + } else if (getMyRocks() == 1 && + getOpposite().getMyRocks() != 0) { + + getKalaha().claimStolenBooty(myRocks); + myRocks = 0; + getOpposite().stealTheBooty(true); + } + } + + SmallBowl getOpposite() { + return getOpposite(0); + } + + SmallBowl getOpposite(int count) { + count = count + 1; + return getNextBowl().getOpposite(count); + } +} diff --git a/domain/src/main/main.iml b/domain/src/main/main.iml new file mode 100644 index 0000000..908ad4f --- /dev/null +++ b/domain/src/main/main.iml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module>
\ No newline at end of file diff --git a/domain/src/test/java/mancala/domain/BowlTest.java b/domain/src/test/java/mancala/domain/BowlTest.java new file mode 100644 index 0000000..530f628 --- /dev/null +++ b/domain/src/test/java/mancala/domain/BowlTest.java @@ -0,0 +1,324 @@ +package mancala.domain; + +import org.junit.jupiter.api.*; + +import static org.junit.jupiter.api.Assertions.*; + + +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); + } + + @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.getMyRocks(), 4); + } + assertSame(current, firstSmallBowlPlayer); + } + + @Test + public void WHEN_chosen_by_the_player_that_has_the_turn_THEN_distribute_its_rocks_anti_clockwise() { + int initialRocks = firstSmallBowlPlayer.getMyRocks(); + firstSmallBowlPlayer.play(); + Bowl neighbour = firstSmallBowlPlayer.getNextBowl(); + for (int i = 0; i < initialRocks; i++) { + assertEquals(5, neighbour.getMyRocks()); + neighbour = neighbour.getNextBowl(); + } + assertEquals(4, neighbour.getMyRocks()); + } + } + + @Nested + class GIVEN_the_game_is_in_a_state_where { + + @Test + public void its_not_the_players_turn_WHEN_played_by_the_player_THEN_nothing_happens() { + firstSmallBowlPlayer.getMyOwner().switchTurn(); + int initialRocks = firstSmallBowlPlayer.getMyRocks(); + firstSmallBowlPlayer.play(); + Bowl neighbour = firstSmallBowlPlayer.getNextBowl(); + for (int i = 0; i < initialRocks; i++) { + assertEquals(4, neighbour.getMyRocks()); + neighbour = neighbour.getNextBowl(); + } + assertEquals(4, neighbour.getMyRocks()); + } + + @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().getMyRocks(); + playWillSkipFromThisBowl.play(); + int opponentKalahaRocksAfter = firstSmallBowlPlayer.getNextSmallBowlTimes(11).getNextBowl().getMyRocks(); + assertEquals(opponentKalahaRocksBefore, opponentKalahaRocksAfter); + } + + @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().getMyRocks()); + } + + @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_wonOPPONENTVARIATION() { + Player player = firstSmallBowlPlayer.getMyOwner(); + Player opponent = firstSmallBowlPlayer.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().getMyRocks()); + firstSmallBowlOpponent.getNextSmallBowlTimes(3).play(); + assertEquals(19, firstSmallBowlOpponent.getNextSmallBowlTimes(5).getNextBowl().getMyRocks()); + } + + 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).getMyRocks()); + // End up here by looping around the board, thus skipping + assertEquals(0, firstSmallBowlOpponent.getMyRocks()); + // Thus steal from last bowl on players side + assertEquals(8, firstSmallBowlPlayer.getNextSmallBowlTimes(5).getMyRocks()); + // Result is big kalaha booty + assertEquals(8, firstSmallBowlOpponent.getNextSmallBowlTimes(5).getNextBowl().getMyRocks()); + } + + 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 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().getMyRocks()); + + // 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().getMyRocks()); + assertEquals(0, firstSmallBowlPlayer.getNextSmallBowlTimes(4).getMyRocks()); + // assertEquals(0, firstSmallBowlPlayer.getNextSmallBowlTimes(4).getOpposite().getMyRocks()); + + // opponent + firstSmallBowlOpponent.getNextSmallBowlTimes(3).play(); + + //Player + firstSmallBowlPlayer.getNextSmallBowlTimes(3).play(); + assertEquals(10, firstSmallBowlPlayer.getNextSmallBowlTimes(5).getNextBowl().getMyRocks()); + + // 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().getMyRocks()); + firstSmallBowlPlayer.getNextSmallBowlTimes(2).play(); + assertEquals(19, firstSmallBowlPlayer.getNextSmallBowlTimes(5).getNextBowl().getMyRocks()); + + // opponent steals tiny booty + firstSmallBowlOpponent.play(); + assertEquals(3, firstSmallBowlOpponent.getNextSmallBowlTimes(5).getNextBowl().getMyRocks()); + + // 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).getMyRocks()); + } + + } + + private SmallBowl goToSkippableState() { + SmallBowl firstSmallBowlOpponent = firstSmallBowlPlayer.getNextSmallBowlTimes(6); + + firstSmallBowlPlayer.getNextSmallBowlTimes(2).play(); + firstSmallBowlPlayer.getNextSmallBowlTimes(3).play(); + + firstSmallBowlOpponent.getNextSmallBowlTimes(2).play(); + firstSmallBowlOpponent.getNextSmallBowlTimes(3).play(); + + firstSmallBowlPlayer.play(); + firstSmallBowlOpponent.play(); + + firstSmallBowlPlayer.getNextSmallBowlTimes(4).play(); + firstSmallBowlOpponent.getNextSmallBowlTimes(4).play(); + + // Playing this bowl should give a skip! + assertTrue(firstSmallBowlPlayer.getNextSmallBowlTimes(5).getMyRocks() >= 8); + return firstSmallBowlPlayer.getNextSmallBowlTimes(5); + } + } + + @Nested + class GIVEN_the_play_ends{ + + @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()); + } + + @Test + public void in_opponents_small_bowl_WHEN_player_plays_this_bowl_THEN_turn_is_switched() { + firstSmallBowlPlayer.getNextSmallBowlTimes(5).play(); + assertFalse(firstSmallBowlPlayer.getMyOwner().hasTheTurn()); + } + + @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().getMyRocks()); + } + + } + + + } + + @Nested + @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) + class a_kalaha { + + SmallBowl smallBowl; + Kalaha kalaha; + + @BeforeEach + public void makeKalahaInBoard() { + smallBowl = new SmallBowl(); + kalaha = smallBowl.getNextSmallBowlTimes(6).getKalaha(); + } + + @Test + public void exists_in_a_mancala_board() { + traverseAndCheckBoard(kalaha, 14); + } + + @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.getMyRocks(), 0); + } + } + } +}
\ No newline at end of file diff --git a/domain/src/test/java/mancala/domain/PlayerTest.java b/domain/src/test/java/mancala/domain/PlayerTest.java new file mode 100644 index 0000000..4de7837 --- /dev/null +++ b/domain/src/test/java/mancala/domain/PlayerTest.java @@ -0,0 +1,46 @@ +package mancala.domain; + +import org.junit.jupiter.api.*; + +import static org.junit.jupiter.api.Assertions.*; + +@DisplayName("A player model ") +@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) +class PlayerTest { + Player player; + Player opponent; + + @BeforeEach + public void let_player_and_oppenent_exist() { + player = new Player(); + opponent = player.getOpponent(); + } + + @Test + public void has_turn_when_created() { + assertTrue(player.hasTheTurn()); + } + + @Test + public void opponent_does_not_have_turn_when_player_models_are_created() { + assertFalse(player.getOpponent().hasTheTurn()); + } + + @Test + public void can_change_turn_when_necessary() { + player.switchTurn(); + assertFalse(player.hasTheTurn()); + assertTrue(player.getOpponent().hasTheTurn()); + } + + @Test + public void knows_when_it_is_the_winner() { + assertFalse(player.won()); + player.isTheWinner(); + assertTrue(player.won()); + assertFalse(opponent.won()); + opponent.isTheWinner(); + assertTrue(opponent.won()); + assertFalse(player.won()); + } +}
\ No newline at end of file diff --git a/domain/src/test/test.iml b/domain/src/test/test.iml new file mode 100644 index 0000000..8cc6e96 --- /dev/null +++ b/domain/src/test/test.iml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="JAVA_MODULE" version="4"> + <component name="NewModuleRootManager" inherit-compiler-output="true"> + <exclude-output /> + <content url="file://$MODULE_DIR$"> + <sourceFolder url="file://$MODULE_DIR$/java" isTestSource="true" /> + </content> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + <orderEntry type="module-library" scope="TEST"> + <library name="JUnit5.7.0"> + <CLASSES> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.7.0/junit-jupiter-5.7.0.jar!/" /> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.7.0/junit-jupiter-api-5.7.0.jar!/" /> + <root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.0/apiguardian-api-1.1.0.jar!/" /> + <root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" /> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.7.0/junit-platform-commons-1.7.0.jar!/" /> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.7.0/junit-jupiter-params-5.7.0.jar!/" /> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.7.0/junit-jupiter-engine-5.7.0.jar!/" /> + <root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.7.0/junit-platform-engine-1.7.0.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES /> + </library> + </orderEntry> + <orderEntry type="module" module-name="main" scope="TEST" /> + </component> +</module>
\ No newline at end of file |
