summaryrefslogtreecommitdiff
path: root/game-engine/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'game-engine/src/test')
-rw-r--r--game-engine/src/test/java/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializerTest.java3
-rw-r--r--game-engine/src/test/java/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.java14
-rw-r--r--game-engine/src/test/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.java142
-rw-r--r--game-engine/src/test/java/org/luxons/sevenwonders/game/effects/DiscountTest.java72
-rw-r--r--game-engine/src/test/java/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.java80
-rw-r--r--game-engine/src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java81
-rw-r--r--game-engine/src/test/java/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.java109
-rw-r--r--game-engine/src/test/java/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.java63
-rw-r--r--game-engine/src/test/java/org/luxons/sevenwonders/game/effects/ScienceProgressTest.java38
-rw-r--r--game-engine/src/test/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.java94
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/CardTest.kt6
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.kt141
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/DiscountTest.kt72
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.kt46
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.kt47
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.kt72
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.kt28
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ScienceProgressTest.kt43
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.kt95
-rw-r--r--game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt4
20 files changed, 555 insertions, 695 deletions
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializerTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializerTest.java
index 861d5a09..d7aeeeb2 100644
--- a/game-engine/src/test/java/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializerTest.java
+++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializerTest.java
@@ -12,6 +12,7 @@ import org.luxons.sevenwonders.game.effects.GoldIncrease;
import org.luxons.sevenwonders.game.effects.MilitaryReinforcements;
import org.luxons.sevenwonders.game.effects.ProductionIncrease;
import org.luxons.sevenwonders.game.effects.RawPointsIncrease;
+import org.luxons.sevenwonders.game.resources.Production;
import static org.junit.Assert.assertEquals;
@@ -52,7 +53,7 @@ public class NumericEffectSerializerTest {
@Test(expected = IllegalArgumentException.class)
public void serialize_failOnUnknownType() {
- gson.toJson(new ProductionIncrease());
+ gson.toJson(new ProductionIncrease(new Production(), false));
}
@Theory
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.java
index 8c5108ba..fd2e593b 100644
--- a/game-engine/src/test/java/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.java
+++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.java
@@ -43,19 +43,13 @@ public class ProductionIncreaseSerializerTest {
if (clay > 0) {
production.addFixedResource(ResourceType.CLAY, clay);
}
- ProductionIncrease prodIncrease = new ProductionIncrease();
- prodIncrease.setProduction(production);
- prodIncrease.setSellable(sellable);
- return prodIncrease;
+ return new ProductionIncrease(production, sellable);
}
private static ProductionIncrease createChoice(boolean sellable, ResourceType... types) {
Production production = new Production();
production.addChoice(types);
- ProductionIncrease prodIncrease = new ProductionIncrease();
- prodIncrease.setProduction(production);
- prodIncrease.setSellable(sellable);
- return prodIncrease;
+ return new ProductionIncrease(production, sellable);
}
@Test
@@ -65,7 +59,7 @@ public class ProductionIncreaseSerializerTest {
@Test
public void serialize_emptyProdIncreaseAsNull() {
- ProductionIncrease prodIncrease = new ProductionIncrease();
+ ProductionIncrease prodIncrease = new ProductionIncrease(new Production(), false);
assertEquals("null", gson.toJson(prodIncrease, ProductionIncrease.class));
}
@@ -138,7 +132,7 @@ public class ProductionIncreaseSerializerTest {
@Test
public void deserialize_emptyList() {
- ProductionIncrease prodIncrease = new ProductionIncrease();
+ ProductionIncrease prodIncrease = new ProductionIncrease(new Production(), true);
assertEquals(prodIncrease, gson.fromJson("\"\"", ProductionIncrease.class));
}
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.java
deleted file mode 100644
index a32bc342..00000000
--- a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.java
+++ /dev/null
@@ -1,142 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-import java.util.Arrays;
-import java.util.Collections;
-
-import org.junit.Before;
-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.CardBack;
-import org.luxons.sevenwonders.game.cards.Color;
-import org.luxons.sevenwonders.game.test.TestUtilsKt;
-
-import static org.junit.Assert.assertEquals;
-
-@RunWith(Theories.class)
-public class BonusPerBoardElementTest {
-
- private Table table;
-
- @DataPoints
- public static int[] values() {
- return new int[]{0, 1, 2, 3};
- }
-
- @DataPoints
- public static Color[] colors() {
- return Color.values();
- }
-
- @DataPoints
- public static RelativeBoardPosition[] positions() {
- return RelativeBoardPosition.values();
- }
-
- @Before
- public void setUp() {
- table = TestUtilsKt.testTable(4);
- }
-
- private static BonusPerBoardElement createBonus(BoardElementType type, int gold, int points, Color... colors) {
- BonusPerBoardElement bonus = new BonusPerBoardElement();
- bonus.setType(type);
- bonus.setGold(gold);
- bonus.setPoints(points);
- bonus.setColors(Arrays.asList(colors));
- return bonus;
- }
-
- @Theory
- public void computePoints_countsCards(RelativeBoardPosition boardPosition, int nbCards, int nbOtherCards,
- int points, int gold, Color color) {
- Board board = table.getBoard(0, boardPosition);
- TestUtilsKt.addCards(board, nbCards, nbOtherCards, color);
-
- BonusPerBoardElement bonus = createBonus(BoardElementType.CARD, gold, points, color);
- bonus.setBoards(Collections.singletonList(boardPosition));
-
- assertEquals(nbCards * points, bonus.computePoints(table, 0));
- }
-
- @Theory
- public void computePoints_countsDefeatTokens(RelativeBoardPosition boardPosition, int nbDefeatTokens, int points,
- int gold) {
- Board board = table.getBoard(0, boardPosition);
- for (int i = 0; i < nbDefeatTokens; i++) {
- board.getMilitary().defeat();
- }
-
- BonusPerBoardElement bonus = createBonus(BoardElementType.DEFEAT_TOKEN, gold, points);
- bonus.setBoards(Collections.singletonList(boardPosition));
-
- assertEquals(nbDefeatTokens * points, bonus.computePoints(table, 0));
- }
-
- @Theory
- public void computePoints_countsWonderStages(RelativeBoardPosition boardPosition, int nbStages, int points,
- int gold) {
- Board board = table.getBoard(0, boardPosition);
- for (int i = 0; i < nbStages; i++) {
- board.getWonder().buildLevel(new CardBack(""));
- }
-
- BonusPerBoardElement bonus = createBonus(BoardElementType.BUILT_WONDER_STAGES, gold, points);
- bonus.setBoards(Collections.singletonList(boardPosition));
-
- assertEquals(nbStages * points, bonus.computePoints(table, 0));
- }
-
- @Theory
- public void apply_countsCards(RelativeBoardPosition boardPosition, int nbCards, int nbOtherCards, int points,
- int gold, Color color) {
- Board board = table.getBoard(0, boardPosition);
- TestUtilsKt.addCards(board, nbCards, nbOtherCards, color);
-
- BonusPerBoardElement bonus = createBonus(BoardElementType.CARD, gold, points, color);
- bonus.setBoards(Collections.singletonList(boardPosition));
-
- Board selfBoard = table.getBoard(0);
- int initialGold = selfBoard.getGold();
- bonus.apply(table, 0);
- assertEquals(initialGold + nbCards * gold, selfBoard.getGold());
- }
-
- @Theory
- public void apply_countsDefeatTokens(RelativeBoardPosition boardPosition, int nbDefeatTokens, int points,
- int gold) {
- Board board = table.getBoard(0, boardPosition);
- for (int i = 0; i < nbDefeatTokens; i++) {
- board.getMilitary().defeat();
- }
-
- BonusPerBoardElement bonus = createBonus(BoardElementType.DEFEAT_TOKEN, gold, points);
- bonus.setBoards(Collections.singletonList(boardPosition));
-
- Board selfBoard = table.getBoard(0);
- int initialGold = selfBoard.getGold();
- bonus.apply(table, 0);
- assertEquals(initialGold + nbDefeatTokens * gold, selfBoard.getGold());
- }
-
- @Theory
- public void apply_countsWonderStages(RelativeBoardPosition boardPosition, int nbStages, int points, int gold) {
- Board board = table.getBoard(0, boardPosition);
- for (int i = 0; i < nbStages; i++) {
- board.getWonder().buildLevel(new CardBack(""));
- }
-
- BonusPerBoardElement bonus = createBonus(BoardElementType.BUILT_WONDER_STAGES, gold, points);
- bonus.setBoards(Collections.singletonList(boardPosition));
-
- Board selfBoard = table.getBoard(0);
- int initialGold = selfBoard.getGold();
- bonus.apply(table, 0);
- assertEquals(initialGold + nbStages * gold, selfBoard.getGold());
- }
-}
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/DiscountTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/DiscountTest.java
deleted file mode 100644
index c13cec1b..00000000
--- a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/DiscountTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-import org.junit.Assume;
-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.Board;
-import org.luxons.sevenwonders.game.resources.Provider;
-import org.luxons.sevenwonders.game.resources.ResourceTransactions;
-import org.luxons.sevenwonders.game.resources.ResourceType;
-import org.luxons.sevenwonders.game.test.TestUtilsKt;
-
-import static org.junit.Assert.assertEquals;
-
-@RunWith(Theories.class)
-public class DiscountTest {
-
- @DataPoints
- public static int[] discountedPrices() {
- return new int[] {0, 1, 2};
- }
-
- @DataPoints
- public static ResourceType[] resourceTypes() {
- return ResourceType.values();
- }
-
- @DataPoints
- public static Provider[] providers() {
- return Provider.values();
- }
-
- @Theory
- public void apply_givesDiscountedPrice(int discountedPrice, ResourceType discountedType, Provider provider) {
- Board board = TestUtilsKt.testBoard(ResourceType.CLAY, 3);
- Discount discount = new Discount();
- discount.setDiscountedPrice(discountedPrice);
- discount.getProviders().add(provider);
- discount.getResourceTypes().add(discountedType);
- discount.apply(board);
-
- ResourceTransactions transactions = TestUtilsKt.createTransactions(provider, discountedType);
- assertEquals(discountedPrice, board.getTradingRules().computeCost(transactions));
- }
-
- @Theory
- public void apply_doesNotAffectOtherResources(int discountedPrice, ResourceType discountedType, Provider provider,
- ResourceType otherType, Provider otherProvider) {
- Assume.assumeTrue(otherProvider != provider);
- Assume.assumeTrue(otherType != discountedType);
-
- Board board = TestUtilsKt.testBoard(ResourceType.CLAY, 3);
- Discount discount = new Discount();
- discount.setDiscountedPrice(discountedPrice);
- discount.getProviders().add(provider);
- discount.getResourceTypes().add(discountedType);
- discount.apply(board);
-
- // this is the default in the settings used by TestUtilsKt.testBoard()
- int normalPrice = 2;
-
- ResourceTransactions fromOtherType = TestUtilsKt.createTransactions(provider, otherType);
- assertEquals(normalPrice, board.getTradingRules().computeCost(fromOtherType));
-
- ResourceTransactions fromOtherProvider = TestUtilsKt.createTransactions(otherProvider, discountedType);
- assertEquals(normalPrice, board.getTradingRules().computeCost(fromOtherProvider));
-
- ResourceTransactions fromOtherProviderAndType = TestUtilsKt.createTransactions(otherProvider, otherType);
- assertEquals(normalPrice, board.getTradingRules().computeCost(fromOtherProviderAndType));
- }
-}
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.java
deleted file mode 100644
index ffc506c0..00000000
--- a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-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.resources.ResourceType;
-import org.luxons.sevenwonders.game.test.TestUtilsKt;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-@RunWith(Theories.class)
-public class GoldIncreaseTest {
-
- @DataPoints
- public static int[] goldAmounts() {
- return new int[] {-5, -1, 0, 1, 2, 5, 10};
- }
-
- @DataPoints
- public static ResourceType[] resourceTypes() {
- return ResourceType.values();
- }
-
- @Theory
- public void apply_increaseGoldWithRightAmount(int initialAmount, int goldIncreaseAmount, ResourceType type) {
- Board board = TestUtilsKt.testBoard(type, initialAmount);
- GoldIncrease goldIncrease = new GoldIncrease(goldIncreaseAmount);
-
- goldIncrease.apply(board);
-
- assertEquals(initialAmount + goldIncreaseAmount, board.getGold());
- }
-
- @Theory
- public void computePoints_isAlwaysZero(int gold) {
- GoldIncrease goldIncrease = new GoldIncrease(gold);
- Table table = TestUtilsKt.testTable(5);
- assertEquals(0, goldIncrease.computePoints(table, 0));
- }
-
- @Theory
- public void equals_falseWhenNull(int gold) {
- GoldIncrease goldIncrease = new GoldIncrease(gold);
- //noinspection ObjectEqualsNull
- assertFalse(goldIncrease.equals(null));
- }
-
- @Theory
- public void equals_falseWhenDifferentClass(int gold) {
- GoldIncrease goldIncrease = new GoldIncrease(gold);
- MilitaryReinforcements reinforcements = new MilitaryReinforcements(gold);
- //noinspection EqualsBetweenInconvertibleTypes
- assertFalse(goldIncrease.equals(reinforcements));
- }
-
- @Theory
- public void equals_trueWhenSame(int gold) {
- GoldIncrease goldIncrease = new GoldIncrease(gold);
- assertEquals(goldIncrease, goldIncrease);
- }
-
- @Theory
- public void equals_trueWhenSameContent(int gold) {
- GoldIncrease goldIncrease1 = new GoldIncrease(gold);
- GoldIncrease goldIncrease2 = new GoldIncrease(gold);
- assertTrue(goldIncrease1.equals(goldIncrease2));
- }
-
- @Theory
- public void hashCode_sameWhenSameContent(int gold) {
- GoldIncrease goldIncrease1 = new GoldIncrease(gold);
- GoldIncrease goldIncrease2 = new GoldIncrease(gold);
- assertEquals(goldIncrease1.hashCode(), goldIncrease2.hashCode());
- }
-}
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java
deleted file mode 100644
index f5a25d98..00000000
--- a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-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.resources.ResourceType;
-import org.luxons.sevenwonders.game.test.TestUtilsKt;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-@RunWith(Theories.class)
-public class MilitaryReinforcementsTest {
-
- @DataPoints
- public static int[] shieldCounts() {
- return new int[] {0, 1, 2, 3, 5};
- }
-
- @DataPoints
- public static ResourceType[] resourceTypes() {
- return ResourceType.values();
- }
-
- @Theory
- public void apply_increaseGoldWithRightAmount(int initialShields, int additionalShields, ResourceType type) {
- Board board = TestUtilsKt.testBoard(type);
- board.getMilitary().addShields(initialShields);
-
- MilitaryReinforcements reinforcements = new MilitaryReinforcements(additionalShields);
- reinforcements.apply(board);
-
- assertEquals(initialShields + additionalShields, board.getMilitary().getNbShields());
- }
-
- @Theory
- public void computePoints_isAlwaysZero(int shields) {
- MilitaryReinforcements reinforcements = new MilitaryReinforcements(shields);
- Table table = TestUtilsKt.testTable(5);
- assertEquals(0, reinforcements.computePoints(table, 0));
- }
-
- @Theory
- public void equals_falseWhenNull(int shields) {
- MilitaryReinforcements reinforcements = new MilitaryReinforcements(shields);
- //noinspection ObjectEqualsNull
- assertFalse(reinforcements.equals(null));
- }
-
- @Theory
- public void equals_falseWhenDifferentClass(int shields) {
- MilitaryReinforcements reinforcements = new MilitaryReinforcements(shields);
- GoldIncrease goldIncrease = new GoldIncrease(shields);
- //noinspection EqualsBetweenInconvertibleTypes
- assertFalse(reinforcements.equals(goldIncrease));
- }
-
- @Theory
- public void equals_trueWhenSame(int shields) {
- MilitaryReinforcements reinforcements = new MilitaryReinforcements(shields);
- assertEquals(reinforcements, reinforcements);
- }
-
- @Theory
- public void equals_trueWhenSameContent(int shields) {
- MilitaryReinforcements reinforcements1 = new MilitaryReinforcements(shields);
- MilitaryReinforcements reinforcements2 = new MilitaryReinforcements(shields);
- assertTrue(reinforcements1.equals(reinforcements2));
- }
-
- @Theory
- public void hashCode_sameWhenSameContent(int shields) {
- MilitaryReinforcements reinforcements1 = new MilitaryReinforcements(shields);
- MilitaryReinforcements reinforcements2 = new MilitaryReinforcements(shields);
- assertEquals(reinforcements1.hashCode(), reinforcements2.hashCode());
- }
-}
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.java
deleted file mode 100644
index c39854e5..00000000
--- a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-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.resources.Production;
-import org.luxons.sevenwonders.game.resources.ResourceType;
-import org.luxons.sevenwonders.game.resources.Resources;
-import org.luxons.sevenwonders.game.test.TestUtilsKt;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-@RunWith(Theories.class)
-public class ProductionIncreaseTest {
-
- @DataPoints
- public static ResourceType[] resourceTypes() {
- return ResourceType.values();
- }
-
- private static ProductionIncrease createProductionIncrease(ResourceType... types) {
- ProductionIncrease effect = new ProductionIncrease();
- effect.getProduction().addAll(TestUtilsKt.fixedProduction(types));
- return effect;
- }
-
- @Theory
- public void apply_boardContainsAddedResourceType(ResourceType initialType, ResourceType addedType,
- ResourceType extraType) {
- Board board = TestUtilsKt.testBoard(initialType);
- ProductionIncrease effect = createProductionIncrease(addedType);
- effect.setSellable(false);
-
- effect.apply(board);
-
- Resources resources = TestUtilsKt.createResources(initialType, addedType);
- assertTrue(board.getProduction().contains(resources));
- assertFalse(board.getPublicProduction().contains(resources));
-
- Resources moreResources = TestUtilsKt.createResources(initialType, addedType, extraType);
- assertFalse(board.getProduction().contains(moreResources));
- assertFalse(board.getPublicProduction().contains(moreResources));
- }
-
- @Theory
- public void apply_boardContainsAddedResourceType_sellable(ResourceType initialType, ResourceType addedType,
- ResourceType extraType) {
- Board board = TestUtilsKt.testBoard(initialType);
- ProductionIncrease effect = createProductionIncrease(addedType);
- effect.setSellable(true);
-
- effect.apply(board);
-
- Resources resources = TestUtilsKt.createResources(initialType, addedType);
- assertTrue(board.getProduction().contains(resources));
- assertTrue(board.getPublicProduction().contains(resources));
-
- Resources moreResources = TestUtilsKt.createResources(initialType, addedType, extraType);
- assertFalse(board.getProduction().contains(moreResources));
- assertFalse(board.getPublicProduction().contains(moreResources));
- }
-
- @Theory
- public void computePoints_isAlwaysZero(ResourceType addedType) {
- ProductionIncrease effect = createProductionIncrease(addedType);
- Table table = TestUtilsKt.testTable(5);
- assertEquals(0, effect.computePoints(table, 0));
- }
-
- @Theory
- public void equals_falseWhenNull(ResourceType addedType) {
- ProductionIncrease effect = createProductionIncrease(addedType);
- //noinspection ObjectEqualsNull
- assertFalse(effect.equals(null));
- }
-
- @Theory
- public void equals_falseWhenDifferentClass(ResourceType addedType) {
- ProductionIncrease effect = createProductionIncrease(addedType);
- Production production = TestUtilsKt.fixedProduction(addedType);
- //noinspection EqualsBetweenInconvertibleTypes
- assertFalse(effect.equals(production));
- }
-
- @Theory
- public void equals_trueWhenSame(ResourceType addedType) {
- ProductionIncrease effect = createProductionIncrease(addedType);
- assertEquals(effect, effect);
- }
-
- @Theory
- public void equals_trueWhenSameContent(ResourceType addedType) {
- ProductionIncrease effect1 = createProductionIncrease(addedType);
- ProductionIncrease effect2 = createProductionIncrease(addedType);
- assertTrue(effect1.equals(effect2));
- }
-
- @Theory
- public void hashCode_sameWhenSameContent(ResourceType addedType) {
- ProductionIncrease effect1 = createProductionIncrease(addedType);
- ProductionIncrease effect2 = createProductionIncrease(addedType);
- assertEquals(effect1.hashCode(), effect2.hashCode());
- }
-}
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.java
deleted file mode 100644
index dcf178f3..00000000
--- a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-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.test.TestUtilsKt;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-@RunWith(Theories.class)
-public class RawPointsIncreaseTest {
-
- @DataPoints
- public static int[] points() {
- return new int[] {0, 1, 2, 3, 5};
- }
-
- @Theory
- public void computePoints_equalsNbOfPoints(int points) {
- RawPointsIncrease rawPointsIncrease = new RawPointsIncrease(points);
- Table table = TestUtilsKt.testTable(5);
- assertEquals(points, rawPointsIncrease.computePoints(table, 0));
- }
-
- @Theory
- public void equals_falseWhenNull(int points) {
- RawPointsIncrease rawPointsIncrease = new RawPointsIncrease(points);
- //noinspection ObjectEqualsNull
- assertFalse(rawPointsIncrease.equals(null));
- }
-
- @Theory
- public void equals_falseWhenDifferentClass(int points) {
- RawPointsIncrease rawPointsIncrease = new RawPointsIncrease(points);
- GoldIncrease goldIncrease = new GoldIncrease(points);
- //noinspection EqualsBetweenInconvertibleTypes
- assertFalse(rawPointsIncrease.equals(goldIncrease));
- }
-
- @Theory
- public void equals_trueWhenSame(int points) {
- RawPointsIncrease rawPointsIncrease = new RawPointsIncrease(points);
- assertEquals(rawPointsIncrease, rawPointsIncrease);
- }
-
- @Theory
- public void equals_trueWhenSameContent(int points) {
- RawPointsIncrease rawPointsIncrease1 = new RawPointsIncrease(points);
- RawPointsIncrease rawPointsIncrease2 = new RawPointsIncrease(points);
- assertTrue(rawPointsIncrease1.equals(rawPointsIncrease2));
- }
-
- @Theory
- public void hashCode_sameWhenSameContent(int points) {
- RawPointsIncrease rawPointsIncrease1 = new RawPointsIncrease(points);
- RawPointsIncrease rawPointsIncrease2 = new RawPointsIncrease(points);
- assertEquals(rawPointsIncrease1.hashCode(), rawPointsIncrease2.hashCode());
- }
-}
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/ScienceProgressTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/ScienceProgressTest.java
deleted file mode 100644
index cecafad9..00000000
--- a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/ScienceProgressTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package org.luxons.sevenwonders.game.effects;
-
-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.Board;
-import org.luxons.sevenwonders.game.boards.Science;
-import org.luxons.sevenwonders.game.boards.ScienceType;
-import org.luxons.sevenwonders.game.resources.ResourceType;
-import org.luxons.sevenwonders.game.test.TestUtilsKt;
-
-import static org.junit.Assert.assertEquals;
-
-@RunWith(Theories.class)
-public class ScienceProgressTest {
-
- @DataPoints
- public static int[] elementsCount() {
- return new int[] {0, 1, 2};
- }
-
- @Theory
- public void apply_initContainsAddedScience(int initCompasses, int initWheels, int initTablets, int initJokers,
- int compasses, int wheels, int tablets, int jokers) {
- Board board = TestUtilsKt.testBoard(ResourceType.ORE);
- Science initialScience = TestUtilsKt.createScience(initCompasses, initWheels, initTablets, initJokers);
- board.getScience().addAll(initialScience);
-
- ScienceProgress effect = TestUtilsKt.createScienceProgress(compasses, wheels, tablets, jokers);
- effect.apply(board);
-
- assertEquals(initCompasses + compasses, board.getScience().getQuantity(ScienceType.COMPASS));
- assertEquals(initWheels + wheels, board.getScience().getQuantity(ScienceType.WHEEL));
- assertEquals(initTablets + tablets, board.getScience().getQuantity(ScienceType.TABLET));
- assertEquals(initJokers + jokers, board.getScience().getJokers());
- }
-}
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.java
deleted file mode 100644
index 021e8f7c..00000000
--- a/game-engine/src/test/java/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.java
+++ /dev/null
@@ -1,94 +0,0 @@
-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.TestUtilsKt;
-
-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[] {TestUtilsKt.createGuildCard(1, bonus), TestUtilsKt.createGuildCard(2, bonus2)};
- }
-
- @Theory
- public void apply_addsAbility(SpecialAbility ability) {
- SpecialAbilityActivation effect = new SpecialAbilityActivation(ability);
- Table table = TestUtilsKt.testTable(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 = TestUtilsKt.testTable(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 = TestUtilsKt.testTable(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 = TestUtilsKt.testTable(5);
- effect.computePoints(table, 0);
- }
-}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/CardTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/CardTest.kt
index 170ae1e4..3253136c 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/CardTest.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/cards/CardTest.kt
@@ -7,6 +7,7 @@ import org.luxons.sevenwonders.game.Settings
import org.luxons.sevenwonders.game.api.Table
import org.luxons.sevenwonders.game.boards.Board
import org.luxons.sevenwonders.game.effects.ProductionIncrease
+import org.luxons.sevenwonders.game.resources.Production
import org.luxons.sevenwonders.game.resources.ResourceTransactions
import org.luxons.sevenwonders.game.resources.ResourceType
import org.luxons.sevenwonders.game.resources.Resources
@@ -31,8 +32,9 @@ class CardTest {
table = Table(boards)
val treeFarmRequirements = Requirements(1)
- val treeFarmEffect = ProductionIncrease()
- treeFarmEffect.production.addChoice(ResourceType.WOOD, ResourceType.CLAY)
+ val treeFarmProduction = Production()
+ treeFarmProduction.addChoice(ResourceType.WOOD, ResourceType.CLAY)
+ val treeFarmEffect = ProductionIncrease(treeFarmProduction, false)
treeFarmCard = testCard("Tree Farm", Color.BROWN, treeFarmEffect, treeFarmRequirements)
}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.kt
new file mode 100644
index 00000000..ccc1c142
--- /dev/null
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/BonusPerBoardElementTest.kt
@@ -0,0 +1,141 @@
+package org.luxons.sevenwonders.game.effects
+
+import org.junit.Before
+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.BoardElementType
+import org.luxons.sevenwonders.game.boards.RelativeBoardPosition
+import org.luxons.sevenwonders.game.cards.CardBack
+import org.luxons.sevenwonders.game.cards.Color
+import org.luxons.sevenwonders.game.test.*
+
+import org.junit.Assert.assertEquals
+
+@RunWith(Theories::class)
+class BonusPerBoardElementTest {
+
+ private var table: Table? = null
+
+ @Before
+ fun setUp() {
+ table = testTable(4)
+ }
+
+ @Theory
+ fun computePoints_countsCards(
+ boardPosition: RelativeBoardPosition, nbCards: Int, nbOtherCards: Int,
+ points: Int, gold: Int, color: Color
+ ) {
+ val board = table!!.getBoard(0, boardPosition)
+ addCards(board, nbCards, nbOtherCards, color)
+
+ val bonus = BonusPerBoardElement(listOf(boardPosition), BoardElementType.CARD, gold, points, listOf(color))
+
+ assertEquals((nbCards * points).toLong(), bonus.computePoints(table!!, 0).toLong())
+ }
+
+ @Theory
+ fun computePoints_countsDefeatTokens(
+ boardPosition: RelativeBoardPosition, nbDefeatTokens: Int, points: Int,
+ gold: Int
+ ) {
+ val board = table!!.getBoard(0, boardPosition)
+ for (i in 0 until nbDefeatTokens) {
+ board.military.defeat()
+ }
+
+ val bonus = BonusPerBoardElement(listOf(boardPosition), BoardElementType.DEFEAT_TOKEN, gold, points, listOf())
+
+ assertEquals((nbDefeatTokens * points).toLong(), bonus.computePoints(table!!, 0).toLong())
+ }
+
+ @Theory
+ fun computePoints_countsWonderStages(
+ boardPosition: RelativeBoardPosition, nbStages: Int, points: Int,
+ gold: Int
+ ) {
+ val board = table!!.getBoard(0, boardPosition)
+ for (i in 0 until nbStages) {
+ board.wonder.buildLevel(CardBack(""))
+ }
+
+ val bonus =
+ BonusPerBoardElement(listOf(boardPosition), BoardElementType.BUILT_WONDER_STAGES, gold, points, listOf())
+
+ assertEquals((nbStages * points).toLong(), bonus.computePoints(table!!, 0).toLong())
+ }
+
+ @Theory
+ fun apply_countsCards(
+ boardPosition: RelativeBoardPosition, nbCards: Int, nbOtherCards: Int, points: Int,
+ gold: Int, color: Color
+ ) {
+ val board = table!!.getBoard(0, boardPosition)
+ addCards(board, nbCards, nbOtherCards, color)
+
+ val bonus = BonusPerBoardElement(listOf(boardPosition), BoardElementType.CARD, gold, points, listOf(color))
+
+ val selfBoard = table!!.getBoard(0)
+ val initialGold = selfBoard.gold
+ bonus.apply(table!!, 0)
+ assertEquals((initialGold + nbCards * gold).toLong(), selfBoard.gold.toLong())
+ }
+
+ @Theory
+ fun apply_countsDefeatTokens(
+ boardPosition: RelativeBoardPosition, nbDefeatTokens: Int, points: Int,
+ gold: Int
+ ) {
+ val board = table!!.getBoard(0, boardPosition)
+ for (i in 0 until nbDefeatTokens) {
+ board.military.defeat()
+ }
+
+ val bonus = BonusPerBoardElement(listOf(boardPosition), BoardElementType.DEFEAT_TOKEN, gold, points, listOf())
+
+ val selfBoard = table!!.getBoard(0)
+ val initialGold = selfBoard.gold
+ bonus.apply(table!!, 0)
+ assertEquals((initialGold + nbDefeatTokens * gold).toLong(), selfBoard.gold.toLong())
+ }
+
+ @Theory
+ fun apply_countsWonderStages(boardPosition: RelativeBoardPosition, nbStages: Int, points: Int, gold: Int) {
+ val board = table!!.getBoard(0, boardPosition)
+ for (i in 0 until nbStages) {
+ board.wonder.buildLevel(CardBack(""))
+ }
+
+ val bonus =
+ BonusPerBoardElement(listOf(boardPosition), BoardElementType.BUILT_WONDER_STAGES, gold, points, listOf())
+
+ val selfBoard = table!!.getBoard(0)
+ val initialGold = selfBoard.gold
+ bonus.apply(table!!, 0)
+ assertEquals((initialGold + nbStages * gold).toLong(), selfBoard.gold.toLong())
+ }
+
+ companion object {
+
+ @JvmStatic
+ @DataPoints
+ fun values(): IntArray {
+ return intArrayOf(0, 1, 2, 3)
+ }
+
+ @JvmStatic
+ @DataPoints
+ fun colors(): Array<Color> {
+ return Color.values()
+ }
+
+ @JvmStatic
+ @DataPoints
+ fun positions(): Array<RelativeBoardPosition> {
+ return RelativeBoardPosition.values()
+ }
+ }
+}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/DiscountTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/DiscountTest.kt
new file mode 100644
index 00000000..e228d585
--- /dev/null
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/DiscountTest.kt
@@ -0,0 +1,72 @@
+package org.luxons.sevenwonders.game.effects
+
+import org.junit.Assert.assertEquals
+import org.junit.Assume
+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.resources.Provider
+import org.luxons.sevenwonders.game.resources.ResourceType
+import org.luxons.sevenwonders.game.test.createTransactions
+import org.luxons.sevenwonders.game.test.testBoard
+
+@RunWith(Theories::class)
+class DiscountTest {
+
+ @Theory
+ fun apply_givesDiscountedPrice(discountedPrice: Int, discountedType: ResourceType, provider: Provider) {
+ val board = testBoard(ResourceType.CLAY, 3)
+ val discount = Discount(listOf(discountedType), listOf(provider), discountedPrice)
+ discount.apply(board)
+
+ val transactions = createTransactions(provider, discountedType)
+ assertEquals(discountedPrice.toLong(), board.tradingRules.computeCost(transactions).toLong())
+ }
+
+ @Theory
+ fun apply_doesNotAffectOtherResources(
+ discountedPrice: Int, discountedType: ResourceType, provider: Provider,
+ otherType: ResourceType, otherProvider: Provider
+ ) {
+ Assume.assumeTrue(otherProvider != provider)
+ Assume.assumeTrue(otherType != discountedType)
+
+ val board = testBoard(ResourceType.CLAY, 3)
+ val discount = Discount(listOf(discountedType), listOf(provider), discountedPrice)
+ discount.apply(board)
+
+ // this is the default in the settings used by TestUtilsKt.testBoard()
+ val normalPrice = 2
+
+ val fromOtherType = createTransactions(provider, otherType)
+ assertEquals(normalPrice.toLong(), board.tradingRules.computeCost(fromOtherType).toLong())
+
+ val fromOtherProvider = createTransactions(otherProvider, discountedType)
+ assertEquals(normalPrice.toLong(), board.tradingRules.computeCost(fromOtherProvider).toLong())
+
+ val fromOtherProviderAndType = createTransactions(otherProvider, otherType)
+ assertEquals(normalPrice.toLong(), board.tradingRules.computeCost(fromOtherProviderAndType).toLong())
+ }
+
+ companion object {
+
+ @JvmStatic
+ @DataPoints
+ fun discountedPrices(): IntArray {
+ return intArrayOf(0, 1, 2)
+ }
+
+ @JvmStatic
+ @DataPoints
+ fun resourceTypes(): Array<ResourceType> {
+ return ResourceType.values()
+ }
+
+ @JvmStatic
+ @DataPoints
+ fun providers(): Array<Provider> {
+ return Provider.values()
+ }
+ }
+}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.kt
new file mode 100644
index 00000000..175f15ea
--- /dev/null
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.kt
@@ -0,0 +1,46 @@
+package org.luxons.sevenwonders.game.effects
+
+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.resources.ResourceType
+import org.luxons.sevenwonders.game.test.*
+
+import org.junit.Assert.assertEquals
+
+@RunWith(Theories::class)
+class GoldIncreaseTest {
+
+ @Theory
+ fun apply_increaseGoldWithRightAmount(initialAmount: Int, goldIncreaseAmount: Int, type: ResourceType) {
+ val board = testBoard(type, initialAmount)
+ val goldIncrease = GoldIncrease(goldIncreaseAmount)
+
+ goldIncrease.apply(board)
+
+ assertEquals((initialAmount + goldIncreaseAmount).toLong(), board.gold.toLong())
+ }
+
+ @Theory
+ fun computePoints_isAlwaysZero(gold: Int) {
+ val goldIncrease = GoldIncrease(gold)
+ val table = testTable(5)
+ assertEquals(0, goldIncrease.computePoints(table, 0).toLong())
+ }
+
+ companion object {
+
+ @JvmStatic
+ @DataPoints
+ fun goldAmounts(): IntArray {
+ return intArrayOf(-5, -1, 0, 1, 2, 5, 10)
+ }
+
+ @JvmStatic
+ @DataPoints
+ fun resourceTypes(): Array<ResourceType> {
+ return ResourceType.values()
+ }
+ }
+}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.kt
new file mode 100644
index 00000000..a8bd01d6
--- /dev/null
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.kt
@@ -0,0 +1,47 @@
+package org.luxons.sevenwonders.game.effects
+
+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.resources.ResourceType
+import org.luxons.sevenwonders.game.test.*
+
+import org.junit.Assert.assertEquals
+
+@RunWith(Theories::class)
+class MilitaryReinforcementsTest {
+
+ @Theory
+ fun apply_increaseGoldWithRightAmount(initialShields: Int, additionalShields: Int, type: ResourceType) {
+ val board = testBoard(type)
+ board.military.addShields(initialShields)
+
+ val reinforcements = MilitaryReinforcements(additionalShields)
+ reinforcements.apply(board)
+
+ assertEquals((initialShields + additionalShields).toLong(), board.military.nbShields.toLong())
+ }
+
+ @Theory
+ fun computePoints_isAlwaysZero(shields: Int) {
+ val reinforcements = MilitaryReinforcements(shields)
+ val table = testTable(5)
+ assertEquals(0, reinforcements.computePoints(table, 0).toLong())
+ }
+
+ companion object {
+
+ @JvmStatic
+ @DataPoints
+ fun shieldCounts(): IntArray {
+ return intArrayOf(0, 1, 2, 3, 5)
+ }
+
+ @JvmStatic
+ @DataPoints
+ fun resourceTypes(): Array<ResourceType> {
+ return ResourceType.values()
+ }
+ }
+}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.kt
new file mode 100644
index 00000000..6f8da55d
--- /dev/null
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.kt
@@ -0,0 +1,72 @@
+package org.luxons.sevenwonders.game.effects
+
+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.resources.ResourceType
+import org.luxons.sevenwonders.game.test.*
+
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
+
+@RunWith(Theories::class)
+class ProductionIncreaseTest {
+
+ @Theory
+ fun apply_boardContainsAddedResourceType(
+ initialType: ResourceType,
+ addedType: ResourceType,
+ extraType: ResourceType
+ ) {
+ val board = testBoard(initialType)
+ val effect = ProductionIncrease(fixedProduction(addedType), false)
+
+ effect.apply(board)
+
+ val resources = createResources(initialType, addedType)
+ assertTrue(board.production.contains(resources))
+ assertFalse(board.publicProduction.contains(resources))
+
+ val moreResources = createResources(initialType, addedType, extraType)
+ assertFalse(board.production.contains(moreResources))
+ assertFalse(board.publicProduction.contains(moreResources))
+ }
+
+ @Theory
+ fun apply_boardContainsAddedResourceType_sellable(
+ initialType: ResourceType,
+ addedType: ResourceType,
+ extraType: ResourceType
+ ) {
+ val board = testBoard(initialType)
+ val effect = ProductionIncrease(fixedProduction(addedType), true)
+
+ effect.apply(board)
+
+ val resources = createResources(initialType, addedType)
+ assertTrue(board.production.contains(resources))
+ assertTrue(board.publicProduction.contains(resources))
+
+ val moreResources = createResources(initialType, addedType, extraType)
+ assertFalse(board.production.contains(moreResources))
+ assertFalse(board.publicProduction.contains(moreResources))
+ }
+
+ @Theory
+ fun computePoints_isAlwaysZero(addedType: ResourceType) {
+ val effect = ProductionIncrease(fixedProduction(addedType), false)
+ val table = testTable(5)
+ assertEquals(0, effect.computePoints(table, 0).toLong())
+ }
+
+ companion object {
+
+ @JvmStatic
+ @DataPoints
+ fun resourceTypes(): Array<ResourceType> {
+ return ResourceType.values()
+ }
+ }
+}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.kt
new file mode 100644
index 00000000..844c28eb
--- /dev/null
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/RawPointsIncreaseTest.kt
@@ -0,0 +1,28 @@
+package org.luxons.sevenwonders.game.effects
+
+import org.junit.Assert.assertEquals
+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.testTable
+
+@RunWith(Theories::class)
+class RawPointsIncreaseTest {
+
+ @Theory
+ fun computePoints_equalsNbOfPoints(points: Int) {
+ val rawPointsIncrease = RawPointsIncrease(points)
+ val table = testTable(5)
+ assertEquals(points.toLong(), rawPointsIncrease.computePoints(table, 0).toLong())
+ }
+
+ companion object {
+
+ @JvmStatic
+ @DataPoints
+ fun points(): IntArray {
+ return intArrayOf(0, 1, 2, 3, 5)
+ }
+ }
+}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ScienceProgressTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ScienceProgressTest.kt
new file mode 100644
index 00000000..cbea1581
--- /dev/null
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/ScienceProgressTest.kt
@@ -0,0 +1,43 @@
+package org.luxons.sevenwonders.game.effects
+
+import org.junit.Assert.assertEquals
+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.ScienceType
+import org.luxons.sevenwonders.game.resources.ResourceType
+import org.luxons.sevenwonders.game.test.createScience
+import org.luxons.sevenwonders.game.test.createScienceProgress
+import org.luxons.sevenwonders.game.test.testBoard
+
+@RunWith(Theories::class)
+class ScienceProgressTest {
+
+ @Theory
+ fun apply_initContainsAddedScience(
+ initCompasses: Int, initWheels: Int, initTablets: Int, initJokers: Int,
+ compasses: Int, wheels: Int, tablets: Int, jokers: Int
+ ) {
+ val board = testBoard(ResourceType.ORE)
+ val initialScience = createScience(initCompasses, initWheels, initTablets, initJokers)
+ board.science.addAll(initialScience)
+
+ val effect = createScienceProgress(compasses, wheels, tablets, jokers)
+ effect.apply(board)
+
+ assertEquals((initCompasses + compasses).toLong(), board.science.getQuantity(ScienceType.COMPASS).toLong())
+ assertEquals((initWheels + wheels).toLong(), board.science.getQuantity(ScienceType.WHEEL).toLong())
+ assertEquals((initTablets + tablets).toLong(), board.science.getQuantity(ScienceType.TABLET).toLong())
+ assertEquals((initJokers + jokers).toLong(), board.science.jokers.toLong())
+ }
+
+ companion object {
+
+ @JvmStatic
+ @DataPoints
+ fun elementsCount(): IntArray {
+ return intArrayOf(0, 1, 2)
+ }
+ }
+}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.kt
new file mode 100644
index 00000000..7282d60d
--- /dev/null
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/effects/SpecialAbilityActivationTest.kt
@@ -0,0 +1,95 @@
+package org.luxons.sevenwonders.game.effects
+
+import org.junit.Assert.assertEquals
+import org.junit.Assert.assertTrue
+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.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.createGuildCard
+import org.luxons.sevenwonders.game.test.testTable
+
+@RunWith(Theories::class)
+class SpecialAbilityActivationTest {
+
+ @Theory
+ fun apply_addsAbility(ability: SpecialAbility) {
+ val effect = SpecialAbilityActivation(ability)
+ val table = testTable(5)
+
+ effect.apply(table, 0)
+
+ val board = table.getBoard(0)
+ assertTrue(board.hasSpecial(ability))
+ }
+
+ @Theory
+ fun computePoints_zeroExceptForCopyGuild(ability: SpecialAbility) {
+ Assume.assumeTrue(ability !== SpecialAbility.COPY_GUILD)
+
+ val effect = SpecialAbilityActivation(ability)
+ val table = testTable(5)
+
+ assertEquals(0, effect.computePoints(table, 0).toLong())
+ }
+
+ @Theory
+ fun computePoints_copiedGuild(guildCard: Card, neighbour: RelativeBoardPosition) {
+ val effect = SpecialAbilityActivation(SpecialAbility.COPY_GUILD)
+ val table = testTable(5)
+
+ val neighbourBoard = table.getBoard(0, neighbour)
+ neighbourBoard.addCard(guildCard)
+
+ val board = table.getBoard(0)
+ board.copiedGuild = guildCard
+
+ val directPointsFromGuildCard = guildCard.effects.stream().mapToInt { e -> e.computePoints(table, 0) }.sum()
+ assertEquals(directPointsFromGuildCard.toLong(), effect.computePoints(table, 0).toLong())
+ }
+
+ @Test(expected = IllegalStateException::class)
+ fun computePoints_copyGuild_failWhenNoChosenGuild() {
+ val effect = SpecialAbilityActivation(SpecialAbility.COPY_GUILD)
+ val table = testTable(5)
+ effect.computePoints(table, 0)
+ }
+
+ companion object {
+
+ @JvmStatic
+ @DataPoints
+ fun abilities(): Array<SpecialAbility> {
+ return SpecialAbility.values()
+ }
+
+ @JvmStatic
+ @DataPoints
+ fun neighbours(): Array<RelativeBoardPosition> {
+ return arrayOf(RelativeBoardPosition.LEFT, RelativeBoardPosition.RIGHT)
+ }
+
+ @JvmStatic
+ @DataPoints
+ fun guilds(): Array<Card> {
+ val bonus = BonusPerBoardElement(
+ listOf(RelativeBoardPosition.LEFT, RelativeBoardPosition.RIGHT),
+ BoardElementType.CARD,
+ points = 1,
+ colors = listOf(Color.GREY, Color.BROWN)
+ )
+ val bonus2 = BonusPerBoardElement(
+ listOf(RelativeBoardPosition.LEFT, RelativeBoardPosition.SELF, RelativeBoardPosition.RIGHT),
+ BoardElementType.BUILT_WONDER_STAGES,
+ points = 1
+ )
+ return arrayOf(createGuildCard(1, bonus), createGuildCard(2, bonus2))
+ }
+ }
+}
diff --git a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt
index 85caa35f..28ab714d 100644
--- a/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt
+++ b/game-engine/src/test/kotlin/org/luxons/sevenwonders/game/test/TestUtils.kt
@@ -183,9 +183,7 @@ fun getDifferentColorFrom(vararg colors: Color): Color {
}
fun createScienceProgress(compasses: Int, wheels: Int, tablets: Int, jokers: Int): ScienceProgress {
- val progress = ScienceProgress()
- progress.science = createScience(compasses, wheels, tablets, jokers)
- return progress
+ return ScienceProgress(createScience(compasses, wheels, tablets, jokers))
}
fun createScience(compasses: Int, wheels: Int, tablets: Int, jokers: Int): Science {
bgstack15