summaryrefslogtreecommitdiff
path: root/game-engine/src/test/java/org
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2018-07-09 11:37:41 +0200
committerjbion <joffrey.bion@amadeus.com>2018-07-09 11:37:41 +0200
commita829a1769bb14c1557b98378bd7e985c8dc54013 (patch)
tree735300c1eaa9543aa6b002cfe1aa1b648272c579 /game-engine/src/test/java/org
parentKotlin mig: wonders package (diff)
downloadseven-wonders-a829a1769bb14c1557b98378bd7e985c8dc54013.tar.gz
seven-wonders-a829a1769bb14c1557b98378bd7e985c8dc54013.tar.bz2
seven-wonders-a829a1769bb14c1557b98378bd7e985c8dc54013.zip
Kotlin mig: Boards package
Diffstat (limited to 'game-engine/src/test/java/org')
-rw-r--r--game-engine/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java213
-rw-r--r--game-engine/src/test/java/org/luxons/sevenwonders/game/boards/MilitaryTest.java64
-rw-r--r--game-engine/src/test/java/org/luxons/sevenwonders/game/boards/RelativeBoardPositionTest.java44
-rw-r--r--game-engine/src/test/java/org/luxons/sevenwonders/game/boards/ScienceTest.java101
4 files changed, 0 insertions, 422 deletions
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java
deleted file mode 100644
index 4b373fa2..00000000
--- a/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java
+++ /dev/null
@@ -1,213 +0,0 @@
-package org.luxons.sevenwonders.game.boards;
-
-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;
-import org.junit.experimental.theories.Theory;
-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.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.TestUtilsKt;
-
-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;
-
-@RunWith(Theories.class)
-public class BoardTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @DataPoints("gold")
- public static int[] goldAmounts() {
- return new int[]{-3, -1, 0, 1, 2, 3};
- }
-
- @DataPoints("nbCards")
- public static int[] nbCards() {
- return new int[]{0, 1, 2};
- }
-
- @DataPoints
- public static ResourceType[] resourceTypes() {
- return ResourceType.values();
- }
-
- @DataPoints
- public static Color[] colors() {
- return Color.values();
- }
-
- @DataPoints
- public static SpecialAbility[] specialAbilities() {
- return SpecialAbility.values();
- }
-
- @Theory
- public void initialGold_respectsSettings(@FromDataPoints("gold") int goldAmountInSettings) {
- CustomizableSettings customSettings = TestUtilsKt.testCustomizableSettings(goldAmountInSettings);
- Settings settings = new Settings(5, customSettings);
- Board board = new Board(TestUtilsKt.testWonder(), 0, settings);
- assertEquals(goldAmountInSettings, board.getGold());
- }
-
- @Theory
- public void initialProduction_containsInitialResource(ResourceType type) {
- Board board = new Board(TestUtilsKt.testWonder(type), 0, new Settings(5));
- Resources resources = TestUtilsKt.createResources(type);
- assertTrue(board.getProduction().contains(resources));
- assertTrue(board.getPublicProduction().contains(resources));
- }
-
- @Theory
- public void removeGold_successfulWhenNotTooMuch(@FromDataPoints("gold") int initialGold,
- @FromDataPoints("gold") int goldRemoved) {
- assumeTrue(goldRemoved >= 0);
- assumeTrue(initialGold >= goldRemoved);
- Board board = new Board(TestUtilsKt.testWonder(), 0, new Settings(5));
- board.setGold(initialGold);
- board.removeGold(goldRemoved);
- assertEquals(initialGold - goldRemoved, board.getGold());
- }
-
- @Theory
- public void removeGold_failsWhenTooMuch(@FromDataPoints("gold") int initialGold,
- @FromDataPoints("gold") int goldRemoved) {
- assumeTrue(goldRemoved >= 0);
- assumeTrue(initialGold < goldRemoved);
- thrown.expect(InsufficientFundsException.class);
- Board board = new Board(TestUtilsKt.testWonder(), 0, new Settings(5));
- board.setGold(initialGold);
- board.removeGold(goldRemoved);
- }
-
- @Theory
- public void getNbCardsOfColor_properCount_singleColor(ResourceType type, @FromDataPoints("nbCards") int nbCards,
- @FromDataPoints("nbCards") int nbOtherCards, Color color) {
- Board board = TestUtilsKt.testBoard(type);
- TestUtilsKt.addCards(board, nbCards, nbOtherCards, color);
- assertEquals(nbCards, board.getNbCardsOfColor(Collections.singletonList(color)));
- }
-
- @Theory
- 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 = TestUtilsKt.testBoard(type);
- TestUtilsKt.addCards(board, nbCards1, color1);
- TestUtilsKt.addCards(board, nbCards2, color2);
- TestUtilsKt.addCards(board, nbOtherCards, TestUtilsKt.getDifferentColorFrom(color1, color2));
- assertEquals(nbCards1 + nbCards2, board.getNbCardsOfColor(Arrays.asList(color1, color2)));
- }
-
- @Test
- public void setCopiedGuild_succeedsOnPurpleCard() {
- Board board = TestUtilsKt.testBoard(ResourceType.CLAY);
- Card card = TestUtilsKt.testCard(Color.PURPLE);
-
- board.setCopiedGuild(card);
- assertSame(card, board.getCopiedGuild());
- }
-
- @Theory
- public void setCopiedGuild_failsOnNonPurpleCard(Color color) {
- assumeTrue(color != Color.PURPLE);
- Board board = TestUtilsKt.testBoard(ResourceType.CLAY);
- Card card = TestUtilsKt.testCard(color);
-
- thrown.expect(IllegalArgumentException.class);
- board.setCopiedGuild(card);
- }
-
- @Theory
- public void hasSpecial(SpecialAbility applied, SpecialAbility tested) {
- Board board = TestUtilsKt.testBoard(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 = TestUtilsKt.testBoard(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));
- }
-
- @Theory
- public void computePoints_gold(@FromDataPoints("gold") int gold) {
- assumeTrue(gold >= 0);
- Board board = TestUtilsKt.testBoard(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 = TestUtilsKt.testBoard(ResourceType.WOOD);
- Table table = new Table(Collections.singletonList(board));
- board.setGold(gold);
-
- Effect effect = new RawPointsIncrease(5);
- TestUtilsKt.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/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/MilitaryTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/MilitaryTest.java
deleted file mode 100644
index b391c6b0..00000000
--- a/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/MilitaryTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package org.luxons.sevenwonders.game.boards;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Rule;
-import org.junit.experimental.theories.DataPoints;
-import org.junit.experimental.theories.FromDataPoints;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.rules.ExpectedException;
-import org.junit.runner.RunWith;
-import org.luxons.sevenwonders.game.boards.Military.UnknownAgeException;
-
-import static org.junit.Assert.assertEquals;
-
-@RunWith(Theories.class)
-public class MilitaryTest {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @DataPoints("points")
- public static int[] points() {
- return new int[] {0, 1, 3, 5};
- }
-
- @DataPoints("ages")
- public static int[] ages() {
- return new int[] {1, 2, 3};
- }
-
- private static Military createMilitary(int age, int nbPointsPerVictory, int nbPointsPerDefeat) {
- Map<Integer, Integer> wonPointsPerAge = new HashMap<>();
- wonPointsPerAge.put(age, nbPointsPerVictory);
- return new Military(nbPointsPerDefeat, wonPointsPerAge);
- }
-
- @Theory
- public void victory_addsCorrectPoints(@FromDataPoints("ages") int age,
- @FromDataPoints("points") int nbPointsPerVictory) {
- Military military = createMilitary(age, nbPointsPerVictory, 0);
- int initialPoints = military.getTotalPoints();
-
- military.victory(age);
- assertEquals(initialPoints + nbPointsPerVictory, military.getTotalPoints());
- }
-
- @Theory
- public void victory_failsIfUnknownAge(@FromDataPoints("points") int nbPointsPerVictory) {
- Military military = createMilitary(0, nbPointsPerVictory, 0);
- thrown.expect(UnknownAgeException.class);
- military.victory(1);
- }
-
- @Theory
- public void defeat_removesCorrectPoints(@FromDataPoints("points") int nbPointsLostPerDefeat) {
- Military military = createMilitary(0, 0, nbPointsLostPerDefeat);
- int initialPoints = military.getTotalPoints();
-
- military.defeat();
- assertEquals(initialPoints - nbPointsLostPerDefeat, military.getTotalPoints());
- }
-}
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/RelativeBoardPositionTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/RelativeBoardPositionTest.java
deleted file mode 100644
index 9f60e572..00000000
--- a/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/RelativeBoardPositionTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package org.luxons.sevenwonders.game.boards;
-
-import org.junit.experimental.theories.DataPoints;
-import org.junit.experimental.theories.Theories;
-import org.junit.experimental.theories.Theory;
-import org.junit.runner.RunWith;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assume.assumeTrue;
-
-@RunWith(Theories.class)
-public class RelativeBoardPositionTest {
-
- @DataPoints
- public static int[] nbPlayers() {
- return new int[] {1, 2, 3, 5, 7, 9};
- }
-
- @Theory
- public void getIndexFrom_wrapLeft(int nbPlayers) {
- assumeTrue(nbPlayers >= 2);
- int last = nbPlayers - 1;
- assertEquals(last, RelativeBoardPosition.LEFT.getIndexFrom(0, nbPlayers));
- assertEquals(0, RelativeBoardPosition.SELF.getIndexFrom(0, nbPlayers));
- assertEquals(1, RelativeBoardPosition.RIGHT.getIndexFrom(0, nbPlayers));
- }
-
- @Theory
- public void getIndexFrom_wrapRight(int nbPlayers) {
- assumeTrue(nbPlayers >= 2);
- int last = nbPlayers - 1;
- assertEquals(last - 1, RelativeBoardPosition.LEFT.getIndexFrom(last, nbPlayers));
- assertEquals(last, RelativeBoardPosition.SELF.getIndexFrom(last, nbPlayers));
- assertEquals(0, RelativeBoardPosition.RIGHT.getIndexFrom(last, nbPlayers));
- }
-
- @Theory
- public void getIndexFrom_noWrap(int nbPlayers) {
- assumeTrue(nbPlayers >= 3);
- assertEquals(0, RelativeBoardPosition.LEFT.getIndexFrom(1, nbPlayers));
- assertEquals(1, RelativeBoardPosition.SELF.getIndexFrom(1, nbPlayers));
- assertEquals(2, RelativeBoardPosition.RIGHT.getIndexFrom(1, nbPlayers));
- }
-}
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/ScienceTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/ScienceTest.java
deleted file mode 100644
index b31da03b..00000000
--- a/game-engine/src/test/java/org/luxons/sevenwonders/game/boards/ScienceTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package org.luxons.sevenwonders.game.boards;
-
-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.test.TestUtilsKt;
-
-import static org.junit.Assert.assertEquals;
-
-@RunWith(Theories.class)
-public class ScienceTest {
-
- @DataPoints
- public static int[][] quantitiesWithExpectedPoints() {
- // compasses, wheels, tablets, jokers, expected points
- return new int[][] {{0, 0, 0, 1, 1}, {0, 0, 1, 0, 1}, {0, 0, 0, 2, 4}, {0, 0, 1, 1, 4}, {0, 0, 2, 0, 4},
- {0, 0, 0, 3, 10}, {0, 0, 1, 2, 10}, {0, 1, 1, 1, 10}, {1, 1, 1, 0, 10}, {0, 0, 0, 4, 16},
- {0, 0, 1, 3, 16}, {0, 0, 2, 2, 16}, {0, 0, 3, 1, 16}, {0, 0, 4, 0, 16}};
- }
-
- @DataPoints
- public static int[] quantitiesDataPoints() {
- return new int[] {0, 1, 3, 5, 8};
- }
-
- @Test
- public void addAll_empty() {
- Science initial = TestUtilsKt.createScience(3, 4, 5, 1);
- Science empty = new Science();
- initial.addAll(empty);
- assertEquals(3, initial.getQuantity(ScienceType.COMPASS));
- assertEquals(4, initial.getQuantity(ScienceType.WHEEL));
- assertEquals(5, initial.getQuantity(ScienceType.TABLET));
- assertEquals(1, initial.getJokers());
- }
-
- @Test
- public void addAll_noJoker() {
- Science initial = TestUtilsKt.createScience(3, 4, 5, 1);
- Science other = TestUtilsKt.createScience(1, 2, 3, 0);
- initial.addAll(other);
- assertEquals(4, initial.getQuantity(ScienceType.COMPASS));
- assertEquals(6, initial.getQuantity(ScienceType.WHEEL));
- assertEquals(8, initial.getQuantity(ScienceType.TABLET));
- assertEquals(1, initial.getJokers());
- }
-
- @Test
- public void addAll_withJokers() {
- Science initial = TestUtilsKt.createScience(3, 4, 5, 1);
- Science other = TestUtilsKt.createScience(0, 0, 0, 3);
- initial.addAll(other);
- assertEquals(3, initial.getQuantity(ScienceType.COMPASS));
- assertEquals(4, initial.getQuantity(ScienceType.WHEEL));
- assertEquals(5, initial.getQuantity(ScienceType.TABLET));
- assertEquals(4, initial.getJokers());
- }
-
- @Test
- public void addAll_mixed() {
- Science initial = TestUtilsKt.createScience(3, 4, 5, 1);
- Science other = TestUtilsKt.createScience(1, 2, 3, 4);
- initial.addAll(other);
- assertEquals(4, initial.getQuantity(ScienceType.COMPASS));
- assertEquals(6, initial.getQuantity(ScienceType.WHEEL));
- assertEquals(8, initial.getQuantity(ScienceType.TABLET));
- assertEquals(5, initial.getJokers());
- }
-
- @Theory
- public void computePoints_compassesOnly_noJoker(int compasses) {
- Science science = TestUtilsKt.createScience(compasses, 0, 0, 0);
- assertEquals(compasses * compasses, science.computePoints());
- }
-
- @Theory
- public void computePoints_wheelsOnly_noJoker(int wheels) {
- Science science = TestUtilsKt.createScience(0, wheels, 0, 0);
- assertEquals(wheels * wheels, science.computePoints());
- }
-
- @Theory
- public void computePoints_tabletsOnly_noJoker(int tablets) {
- Science science = TestUtilsKt.createScience(0, 0, tablets, 0);
- assertEquals(tablets * tablets, science.computePoints());
- }
-
- @Theory
- public void computePoints_allSameNoJoker(int eachSymbol) {
- Science science = TestUtilsKt.createScience(eachSymbol, eachSymbol, eachSymbol, 0);
- assertEquals(3 * eachSymbol * eachSymbol + 7 * eachSymbol, science.computePoints());
- }
-
- @Theory
- public void computePoints_expectation(int[] expectation) {
- Science science = TestUtilsKt.createScience(expectation[0], expectation[1], expectation[2], expectation[3]);
- assertEquals(expectation[4], science.computePoints());
- }
-}
bgstack15