From ed348a611a39e54995b64d4e11f1391283f62fd2 Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Wed, 25 Apr 2018 22:14:36 +0200 Subject: Add test for Table.getNeighbourGuildCards --- .../luxons/sevenwonders/game/api/TableTest.java | 37 ++++++++++++++++++++++ .../luxons/sevenwonders/game/test/TestUtils.java | 10 ++++-- 2 files changed, 45 insertions(+), 2 deletions(-) (limited to 'game-engine/src/test/java') 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 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 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 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 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 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) { -- cgit