From f3dde990ca7b9b072298185666116668760cc9f6 Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Sat, 14 Jan 2017 13:31:02 +0100 Subject: Add test for SpecialAbilityActivation effect --- .../game/effects/SpecialAbilityActivationTest.java | 94 ++++++++++++++++++++++ .../luxons/sevenwonders/game/test/TestUtils.java | 7 ++ 2 files changed, 101 insertions(+) create mode 100644 src/test/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.java (limited to 'src/test/java/org') diff --git a/src/test/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.java b/src/test/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.java new file mode 100644 index 00000000..b04db127 --- /dev/null +++ b/src/test/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.java @@ -0,0 +1,94 @@ +package org.luxons.sevenwonders.game.effects; + +import java.util.Arrays; + +import org.junit.Assume; +import org.junit.Test; +import org.junit.experimental.theories.DataPoints; +import org.junit.experimental.theories.Theories; +import org.junit.experimental.theories.Theory; +import org.junit.runner.RunWith; +import org.luxons.sevenwonders.game.api.Table; +import org.luxons.sevenwonders.game.boards.Board; +import org.luxons.sevenwonders.game.boards.BoardElementType; +import org.luxons.sevenwonders.game.boards.RelativeBoardPosition; +import org.luxons.sevenwonders.game.cards.Card; +import org.luxons.sevenwonders.game.cards.Color; +import org.luxons.sevenwonders.game.test.TestUtils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +@RunWith(Theories.class) +public class SpecialAbilityActivationTest { + + @DataPoints + public static SpecialAbility[] abilities() { + return SpecialAbility.values(); + } + + @DataPoints + public static RelativeBoardPosition[] neighbours() { + return new RelativeBoardPosition[]{RelativeBoardPosition.LEFT, RelativeBoardPosition.RIGHT}; + } + + @DataPoints + public static Card[] guilds() { + BonusPerBoardElement bonus = new BonusPerBoardElement(); + bonus.setType(BoardElementType.CARD); + bonus.setColors(Arrays.asList(Color.GREY, Color.BROWN)); + bonus.setBoards(Arrays.asList(RelativeBoardPosition.LEFT, RelativeBoardPosition.RIGHT)); + bonus.setPoints(1); + + BonusPerBoardElement bonus2 = new BonusPerBoardElement(); + bonus2.setType(BoardElementType.BUILT_WONDER_STAGES); + bonus2.setBoards( + Arrays.asList(RelativeBoardPosition.LEFT, RelativeBoardPosition.SELF, RelativeBoardPosition.RIGHT)); + bonus2.setPoints(1); + + return new Card[]{TestUtils.createGuildCard(1, bonus), TestUtils.createGuildCard(2, bonus2)}; + } + + @Theory + public void apply_addsAbility(SpecialAbility ability) { + SpecialAbilityActivation effect = new SpecialAbilityActivation(ability); + Table table = TestUtils.createTable(5); + + effect.apply(table, 0); + + Board board = table.getBoard(0); + assertTrue(board.hasSpecial(ability)); + } + + @Theory + public void computePoints_zeroExceptForCopyGuild(SpecialAbility ability) { + Assume.assumeTrue(ability != SpecialAbility.COPY_GUILD); + + SpecialAbilityActivation effect = new SpecialAbilityActivation(ability); + Table table = TestUtils.createTable(5); + + assertEquals(0, effect.computePoints(table, 0)); + } + + @Theory + public void computePoints_copiedGuild(Card guildCard, RelativeBoardPosition neighbour) { + SpecialAbilityActivation effect = new SpecialAbilityActivation(SpecialAbility.COPY_GUILD); + Table table = TestUtils.createTable(5); + + Board neighbourBoard = table.getBoard(0, neighbour); + neighbourBoard.addCard(guildCard); + + Board board = table.getBoard(0); + board.setCopiedGuild(guildCard); + + int directPointsFromGuildCard = guildCard.getEffects().stream().mapToInt(e -> e.computePoints(table, 0)).sum(); + assertEquals(directPointsFromGuildCard, effect.computePoints(table, 0)); + } + + @Test(expected = IllegalStateException.class) + public void computePoints_copyGuild_failWhenNoChosenGuild() { + SpecialAbilityActivation effect = new SpecialAbilityActivation(SpecialAbility.COPY_GUILD); + Table table = TestUtils.createTable(5); + effect.computePoints(table, 0); + } +} \ No newline at end of file diff --git a/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java b/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java index 2aa53f60..e0b2ccd7 100644 --- a/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java +++ b/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java @@ -2,6 +2,7 @@ package org.luxons.sevenwonders.game.test; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.luxons.sevenwonders.game.Player; @@ -13,6 +14,7 @@ import org.luxons.sevenwonders.game.boards.ScienceType; import org.luxons.sevenwonders.game.cards.Card; import org.luxons.sevenwonders.game.cards.Color; import org.luxons.sevenwonders.game.cards.Requirements; +import org.luxons.sevenwonders.game.effects.Effect; import org.luxons.sevenwonders.game.effects.ScienceProgress; import org.luxons.sevenwonders.game.resources.BoughtResources; import org.luxons.sevenwonders.game.resources.Production; @@ -122,6 +124,11 @@ public class TestUtils { return new Card("Test Card " + num, color, new Requirements(), null, null, null, null); } + public static Card createGuildCard(int num, Effect effect) { + List effects = Collections.singletonList(effect); + return new Card("Test Guild " + num, Color.PURPLE, new Requirements(), effects, null, null, null); + } + public static void addCards(Board board, int nbCardsOfColor, int nbOtherCards, Color color) { addCards(board, nbCardsOfColor, color); Color otherColor = getDifferentColorFrom(color); -- cgit