diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2017-05-15 23:52:09 +0200 |
---|---|---|
committer | Joffrey BION <joffrey.bion@gmail.com> | 2017-05-15 23:52:09 +0200 |
commit | 4dd3eb6c94a937c7ced557c4253ffefb66552a44 (patch) | |
tree | 92b1ab6290fabe9c5de7004e3135aa67e458f94f /backend/src/test/java | |
parent | Remove useless 'throws Exception' declarations in tests (diff) | |
download | seven-wonders-4dd3eb6c94a937c7ced557c4253ffefb66552a44.tar.gz seven-wonders-4dd3eb6c94a937c7ced557c4253ffefb66552a44.tar.bz2 seven-wonders-4dd3eb6c94a937c7ced557c4253ffefb66552a44.zip |
Add tests for special abilities in Board
Diffstat (limited to 'backend/src/test/java')
-rw-r--r-- | backend/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java | 77 | ||||
-rw-r--r-- | backend/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java | 4 |
2 files changed, 79 insertions, 2 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 451f8bb9..a4070c3c 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 @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.Collections; import org.junit.Rule; +import org.junit.Test; import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.FromDataPoints; import org.junit.experimental.theories.Theories; @@ -12,13 +13,19 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.luxons.sevenwonders.game.Settings; import org.luxons.sevenwonders.game.api.CustomizableSettings; +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.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.test.TestUtils; import static junit.framework.TestCase.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; @@ -45,6 +52,11 @@ public class BoardTest { return Color.values(); } + @DataPoints + public static SpecialAbility[] specialAbilities() { + return SpecialAbility.values(); + } + @Rule public ExpectedException thrown = ExpectedException.none(); @@ -90,7 +102,7 @@ public class BoardTest { @Theory public void getNbCardsOfColor_properCount_singleColor(ResourceType type, @FromDataPoints("nbCards") int nbCards, @FromDataPoints("nbCards") int nbOtherCards, Color color) { - Board board = new Board(TestUtils.createWonder(type), 0, new Settings(5)); + Board board = TestUtils.createBoard(type); TestUtils.addCards(board, nbCards, nbOtherCards, color); assertEquals(nbCards, board.getNbCardsOfColor(Collections.singletonList(color))); } @@ -99,10 +111,71 @@ public class BoardTest { public void getNbCardsOfColor_properCount_multiColors(ResourceType type, @FromDataPoints("nbCards") int nbCards1, @FromDataPoints("nbCards") int nbCards2, @FromDataPoints("nbCards") int nbOtherCards, Color color1, Color color2) { - Board board = new Board(TestUtils.createWonder(type), 0, new Settings(5)); + Board board = TestUtils.createBoard(type); TestUtils.addCards(board, nbCards1, color1); TestUtils.addCards(board, nbCards2, color2); TestUtils.addCards(board, nbOtherCards, TestUtils.getDifferentColorFrom(color1, color2)); assertEquals(nbCards1 + nbCards2, board.getNbCardsOfColor(Arrays.asList(color1, color2))); } + + @Test + public void setCopiedGuild_succeedsOnPurpleCard() { + Board board = TestUtils.createBoard(ResourceType.CLAY); + Card card = TestUtils.createCard(Color.PURPLE); + + board.setCopiedGuild(card); + assertSame(card, board.getCopiedGuild()); + } + + @Theory + public void setCopiedGuild_failsOnNonPurpleCard(Color color) { + assumeTrue(color != Color.PURPLE); + Board board = TestUtils.createBoard(ResourceType.CLAY); + Card card = TestUtils.createCard(color); + + thrown.expect(IllegalArgumentException.class); + board.setCopiedGuild(card); + } + + @Theory + public void hasSpecial(SpecialAbility applied, SpecialAbility tested) { + Board board = TestUtils.createBoard(ResourceType.CLAY); + Table table = new Table(Collections.singletonList(board)); + SpecialAbilityActivation special = new SpecialAbilityActivation(applied); + + special.apply(table, 0); + + assertEquals(applied == tested, board.hasSpecial(tested)); + } + + @Test + public void canPlayFreeCard() { + Board board = TestUtils.createBoard(ResourceType.CLAY); + Table table = new Table(Collections.singletonList(board)); + SpecialAbilityActivation special = new SpecialAbilityActivation(SpecialAbility.ONE_FREE_PER_AGE); + + special.apply(table, 0); + + assertTrue(board.canPlayFreeCard(0)); + assertTrue(board.canPlayFreeCard(1)); + assertTrue(board.canPlayFreeCard(2)); + + board.consumeFreeCard(0); + + assertFalse(board.canPlayFreeCard(0)); + assertTrue(board.canPlayFreeCard(1)); + assertTrue(board.canPlayFreeCard(2)); + + board.consumeFreeCard(1); + + assertFalse(board.canPlayFreeCard(0)); + assertFalse(board.canPlayFreeCard(1)); + assertTrue(board.canPlayFreeCard(2)); + + board.consumeFreeCard(2); + + assertFalse(board.canPlayFreeCard(0)); + assertFalse(board.canPlayFreeCard(1)); + assertFalse(board.canPlayFreeCard(2)); + } } 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 08cb10e8..65ba4369 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 @@ -127,6 +127,10 @@ public class TestUtils { return new Card(name, Color.BLUE, new Requirements(), null, null, null, null); } + public static Card createCard(Color color) { + return new Card("Test Card", color, new Requirements(), null, null, null, null); + } + private static Card createCard(int num, Color color) { return new Card("Test Card " + num, color, new Requirements(), null, null, null, null); } |