diff options
Diffstat (limited to 'backend/src/test/java')
-rw-r--r-- | backend/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java | 47 | ||||
-rw-r--r-- | backend/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java | 12 |
2 files changed, 52 insertions, 7 deletions
diff --git a/backend/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java b/backend/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java index a4070c3c..90a5e5d2 100644 --- a/backend/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java +++ b/backend/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java @@ -17,10 +17,14 @@ import org.luxons.sevenwonders.game.api.Table; import org.luxons.sevenwonders.game.boards.Board.InsufficientFundsException; import org.luxons.sevenwonders.game.cards.Card; import org.luxons.sevenwonders.game.cards.Color; +import org.luxons.sevenwonders.game.effects.Effect; +import org.luxons.sevenwonders.game.effects.RawPointsIncrease; import org.luxons.sevenwonders.game.effects.SpecialAbility; import org.luxons.sevenwonders.game.effects.SpecialAbilityActivation; import org.luxons.sevenwonders.game.resources.ResourceType; import org.luxons.sevenwonders.game.resources.Resources; +import org.luxons.sevenwonders.game.scoring.PlayerScore; +import org.luxons.sevenwonders.game.scoring.ScoreCategory; import org.luxons.sevenwonders.game.test.TestUtils; import static junit.framework.TestCase.assertEquals; @@ -34,12 +38,12 @@ public class BoardTest { @DataPoints("gold") public static int[] goldAmounts() { - return new int[] {-3, -1, 0, 1, 2, 3}; + return new int[]{-3, -1, 0, 1, 2, 3}; } @DataPoints("nbCards") public static int[] nbCards() { - return new int[] {0, 1, 2}; + return new int[]{0, 1, 2}; } @DataPoints @@ -79,7 +83,7 @@ public class BoardTest { @Theory public void removeGold_successfulWhenNotTooMuch(@FromDataPoints("gold") int initialGold, - @FromDataPoints("gold") int goldRemoved) { + @FromDataPoints("gold") int goldRemoved) { assumeTrue(goldRemoved >= 0); assumeTrue(initialGold >= goldRemoved); Board board = new Board(TestUtils.createWonder(), 0, new Settings(5)); @@ -90,7 +94,7 @@ public class BoardTest { @Theory public void removeGold_failsWhenTooMuch(@FromDataPoints("gold") int initialGold, - @FromDataPoints("gold") int goldRemoved) { + @FromDataPoints("gold") int goldRemoved) { assumeTrue(goldRemoved >= 0); assumeTrue(initialGold < goldRemoved); thrown.expect(InsufficientFundsException.class); @@ -101,7 +105,7 @@ public class BoardTest { @Theory public void getNbCardsOfColor_properCount_singleColor(ResourceType type, @FromDataPoints("nbCards") int nbCards, - @FromDataPoints("nbCards") int nbOtherCards, Color color) { + @FromDataPoints("nbCards") int nbOtherCards, Color color) { Board board = TestUtils.createBoard(type); TestUtils.addCards(board, nbCards, nbOtherCards, color); assertEquals(nbCards, board.getNbCardsOfColor(Collections.singletonList(color))); @@ -109,8 +113,9 @@ public class BoardTest { @Theory public void getNbCardsOfColor_properCount_multiColors(ResourceType type, @FromDataPoints("nbCards") int nbCards1, - @FromDataPoints("nbCards") int nbCards2, @FromDataPoints("nbCards") int nbOtherCards, Color color1, - Color color2) { + @FromDataPoints("nbCards") int nbCards2, + @FromDataPoints("nbCards") int nbOtherCards, Color color1, + Color color2) { Board board = TestUtils.createBoard(type); TestUtils.addCards(board, nbCards1, color1); TestUtils.addCards(board, nbCards2, color2); @@ -178,4 +183,32 @@ public class BoardTest { assertFalse(board.canPlayFreeCard(1)); assertFalse(board.canPlayFreeCard(2)); } + + @Theory + public void computePoints_gold(@FromDataPoints("gold") int gold) { + assumeTrue(gold >= 0); + Board board = TestUtils.createBoard(ResourceType.WOOD); + Table table = new Table(Collections.singletonList(board)); + board.setGold(gold); + + PlayerScore score = board.computePoints(table); + assertEquals(gold / 3, (int) score.getPoints(ScoreCategory.GOLD)); + assertEquals(gold / 3, score.getTotalPoints()); + } + + @Theory + public void computePoints_(@FromDataPoints("gold") int gold) { + assumeTrue(gold >= 0); + Board board = TestUtils.createBoard(ResourceType.WOOD); + Table table = new Table(Collections.singletonList(board)); + board.setGold(gold); + + Effect effect = new RawPointsIncrease(5); + TestUtils.playCardWithEffect(table, 0, Color.BLUE, effect); + + PlayerScore score = board.computePoints(table); + assertEquals(gold / 3, (int) score.getPoints(ScoreCategory.GOLD)); + assertEquals(5, (int) score.getPoints(ScoreCategory.CIVIL)); + assertEquals(5 + gold / 3, score.getTotalPoints()); + } } diff --git a/backend/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java b/backend/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java index 65ba4369..4b727944 100644 --- a/backend/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java +++ b/backend/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java @@ -131,6 +131,11 @@ public class TestUtils { return new Card("Test Card", color, new Requirements(), null, null, null, null); } + public static Card createCard(Color color, Effect effect) { + List<Effect> effects = Collections.singletonList(effect); + return new Card("Test Card", color, new Requirements(), effects, null, null, null); + } + private static Card createCard(int num, Color color) { return new Card("Test Card " + num, color, new Requirements(), null, null, null, null); } @@ -184,4 +189,11 @@ public class TestUtils { } return science; } + + public static void playCardWithEffect(Table table, int playerIndex, Color color, Effect effect) { + Card card = createCard(color, effect); + Board board = table.getBoard(playerIndex); + board.addCard(card); + card.applyTo(table, playerIndex, Collections.emptyList()); + } } |