diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2017-01-14 12:59:25 +0100 |
---|---|---|
committer | Joffrey BION <joffrey.bion@gmail.com> | 2017-01-14 12:59:25 +0100 |
commit | e7e838b26ab1bd34333cb0e129f906f03254a0e7 (patch) | |
tree | 60d35f47921b0810479ff29dcf01e063fe3e303d /src/test | |
parent | Add test for Lobby initialization (diff) | |
download | seven-wonders-e7e838b26ab1bd34333cb0e129f906f03254a0e7.tar.gz seven-wonders-e7e838b26ab1bd34333cb0e129f906f03254a0e7.tar.bz2 seven-wonders-e7e838b26ab1bd34333cb0e129f906f03254a0e7.zip |
Add test for Discount effect
Diffstat (limited to 'src/test')
3 files changed, 74 insertions, 3 deletions
diff --git a/src/test/java/org/luxons/sevenwonders/game/effects/DiscountTest.java b/src/test/java/org/luxons/sevenwonders/game/effects/DiscountTest.java new file mode 100644 index 00000000..cf8ce21d --- /dev/null +++ b/src/test/java/org/luxons/sevenwonders/game/effects/DiscountTest.java @@ -0,0 +1,72 @@ +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.BoughtResources; +import org.luxons.sevenwonders.game.resources.Provider; +import org.luxons.sevenwonders.game.resources.ResourceType; +import org.luxons.sevenwonders.game.test.TestUtils; + +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 = TestUtils.createBoard(ResourceType.CLAY, 3); + Discount discount = new Discount(); + discount.setDiscountedPrice(discountedPrice); + discount.getProviders().add(provider); + discount.getResourceTypes().add(discountedType); + discount.apply(board); + + BoughtResources boughtResources = TestUtils.createBoughtResources(provider, discountedType); + assertEquals(discountedPrice, board.getTradingRules().computeCost(boughtResources)); + } + + @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 = TestUtils.createBoard(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 TestUtils.createBoard() + int normalPrice = 2; + + BoughtResources fromOtherType = TestUtils.createBoughtResources(provider, otherType); + assertEquals(normalPrice, board.getTradingRules().computeCost(fromOtherType)); + + BoughtResources fromOtherProvider = TestUtils.createBoughtResources(otherProvider, discountedType); + assertEquals(normalPrice, board.getTradingRules().computeCost(fromOtherProvider)); + + BoughtResources fromOtherProviderAndType = TestUtils.createBoughtResources(otherProvider, otherType); + assertEquals(normalPrice, board.getTradingRules().computeCost(fromOtherProviderAndType)); + } +}
\ No newline at end of file diff --git a/src/test/java/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.java b/src/test/java/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.java index f4e52454..e4d4c27f 100644 --- a/src/test/java/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.java +++ b/src/test/java/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.java @@ -27,9 +27,9 @@ public class GoldIncreaseTest { @Theory public void apply_increaseGoldWithRightAmount(int initialAmount, int goldIncreaseAmount, ResourceType type) { Board board = TestUtils.createBoard(type, initialAmount); - GoldIncrease GoldIncrease = new GoldIncrease(goldIncreaseAmount); + GoldIncrease goldIncrease = new GoldIncrease(goldIncreaseAmount); - GoldIncrease.apply(board); + goldIncrease.apply(board); assertEquals(initialAmount + goldIncreaseAmount, board.getGold()); } 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 6e8c1335..2aa53f60 100644 --- a/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java +++ b/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java @@ -6,7 +6,6 @@ import java.util.List; import org.luxons.sevenwonders.game.Player; 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; import org.luxons.sevenwonders.game.boards.Science; |