diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2018-04-25 22:14:36 +0200 |
---|---|---|
committer | Joffrey BION <joffrey.bion@gmail.com> | 2018-04-25 22:14:36 +0200 |
commit | ed348a611a39e54995b64d4e11f1391283f62fd2 (patch) | |
tree | 7351173b8f50e80b512d0e8b6f00eed4c6df3b8a /game-engine | |
parent | Extract min/max players as JSON rules (diff) | |
download | seven-wonders-ed348a611a39e54995b64d4e11f1391283f62fd2.tar.gz seven-wonders-ed348a611a39e54995b64d4e11f1391283f62fd2.tar.bz2 seven-wonders-ed348a611a39e54995b64d4e11f1391283f62fd2.zip |
Add test for Table.getNeighbourGuildCards
Diffstat (limited to 'game-engine')
-rw-r--r-- | game-engine/src/test/java/org/luxons/sevenwonders/game/api/TableTest.java | 37 | ||||
-rw-r--r-- | game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java | 10 |
2 files changed, 45 insertions, 2 deletions
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/api/TableTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/api/TableTest.java index 71dbeb89..93b6eb08 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/api/TableTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/api/TableTest.java @@ -1,13 +1,18 @@ package org.luxons.sevenwonders.game.api; +import java.util.List; + 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.boards.RelativeBoardPosition; +import org.luxons.sevenwonders.game.cards.Card; import org.luxons.sevenwonders.game.test.TestUtils; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.junit.Assume.assumeTrue; @RunWith(Theories.class) @@ -46,4 +51,36 @@ public class TableTest { assertEquals(table.getBoard(1), table.getBoard(1, RelativeBoardPosition.SELF)); assertEquals(table.getBoard(2), table.getBoard(1, RelativeBoardPosition.RIGHT)); } + + @Theory + public void getNeighbourGuildCards(int nbPlayers) { + assumeTrue(nbPlayers >= 4); + Table table = TestUtils.createTable(nbPlayers); + List<Card> guildCards = TestUtils.createGuildCards(4); + table.getBoard(0).getPlayedCards().add(guildCards.get(0)); + table.getBoard(0).getPlayedCards().add(guildCards.get(1)); + table.getBoard(1).getPlayedCards().add(guildCards.get(2)); + table.getBoard(2).getPlayedCards().add(guildCards.get(3)); + + List<Card> neightbourCards0 = table.getNeighbourGuildCards(0); + assertEquals(1, neightbourCards0.size()); + assertFalse(neightbourCards0.contains(guildCards.get(0))); + assertFalse(neightbourCards0.contains(guildCards.get(1))); + assertTrue(neightbourCards0.contains(guildCards.get(2))); + assertFalse(neightbourCards0.contains(guildCards.get(3))); + + List<Card> neightbourCards1 = table.getNeighbourGuildCards(1); + assertEquals(3, neightbourCards1.size()); + assertTrue(neightbourCards1.contains(guildCards.get(0))); + assertTrue(neightbourCards1.contains(guildCards.get(1))); + assertFalse(neightbourCards1.contains(guildCards.get(2))); + assertTrue(neightbourCards1.contains(guildCards.get(3))); + + List<Card> neightbourCards2 = table.getNeighbourGuildCards(2); + assertEquals(1, neightbourCards2.size()); + assertFalse(neightbourCards2.contains(guildCards.get(0))); + assertFalse(neightbourCards2.contains(guildCards.get(1))); + assertTrue(neightbourCards2.contains(guildCards.get(2))); + assertFalse(neightbourCards2.contains(guildCards.get(3))); + } } diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java index 0dff9dbe..137dd3d7 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import org.luxons.sevenwonders.game.Settings; import org.luxons.sevenwonders.game.api.CustomizableSettings; @@ -147,8 +149,12 @@ public class TestUtils { return createCard("Test Card " + num, color); } - public static Card createGuildCard(int num, Effect effect) { - return createCard("Test Guild " + num, Color.PURPLE, effect); + public static List<Card> createGuildCards(int count) { + return IntStream.range(0, count).mapToObj(i -> TestUtils.createGuildCard(i)).collect(Collectors.toList()); + } + + public static Card createGuildCard(int num, Effect... effects) { + return createCard("Test Guild " + num, Color.PURPLE, effects); } private static Card createCard(String name, Color color, Effect... effects) { |