summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2016-12-22 23:36:35 +0100
committerjbion <joffrey.bion@amadeus.com>2016-12-22 23:36:35 +0100
commit54ba69d8961a96e7455401ec669f75f38352809f (patch)
tree9e701e9ee9f25bd0e32b0509d489b15079687fa2 /src/test
parentRemove middleman methods in Board (diff)
downloadseven-wonders-54ba69d8961a96e7455401ec669f75f38352809f.tar.gz
seven-wonders-54ba69d8961a96e7455401ec669f75f38352809f.tar.bz2
seven-wonders-54ba69d8961a96e7455401ec669f75f38352809f.zip
Add bought resources cost computation
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/resources/TradingRulesTest.java96
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java9
2 files changed, 105 insertions, 0 deletions
diff --git a/src/test/java/org/luxons/sevenwonders/game/resources/TradingRulesTest.java b/src/test/java/org/luxons/sevenwonders/game/resources/TradingRulesTest.java
new file mode 100644
index 00000000..cd6661dc
--- /dev/null
+++ b/src/test/java/org/luxons/sevenwonders/game/resources/TradingRulesTest.java
@@ -0,0 +1,96 @@
+package org.luxons.sevenwonders.game.resources;
+
+import java.util.ArrayList;
+import java.util.Collections;
+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.test.TestUtils;
+
+import static org.junit.Assert.*;
+import static org.junit.Assume.*;
+
+@RunWith(Theories.class)
+public class TradingRulesTest {
+
+ @DataPoints
+ public static int[] costs() {
+ return new int[] {0, 1, 2};
+ }
+
+ @DataPoints
+ public static Provider[] providers() {
+ return Provider.values();
+ }
+
+ @DataPoints
+ public static ResourceType[] resourceTypes() {
+ return ResourceType.values();
+ }
+
+ @Theory
+ public void computeCost_zeroForNoResources(int defaultCost) {
+ TradingRules rules = new TradingRules(defaultCost);
+ assertEquals(0, rules.computeCost(new ArrayList<>()));
+ }
+
+ @Theory
+ public void computeCost_defaultCostWhenNoOverride(int defaultCost, Provider provider, ResourceType type) {
+ TradingRules rules = new TradingRules(defaultCost);
+ BoughtResources resources = TestUtils.createBoughtResources(provider, type);
+ assertEquals(defaultCost, rules.computeCost(Collections.singletonList(resources)));
+ }
+
+ @Theory
+ public void computeCost_twiceDefaultFor2Resources(int defaultCost, Provider provider, ResourceType type) {
+ TradingRules rules = new TradingRules(defaultCost);
+ BoughtResources resources = TestUtils.createBoughtResources(provider, type, type);
+ assertEquals(2 * defaultCost, rules.computeCost(Collections.singletonList(resources)));
+ }
+
+ @Theory
+ public void computeCost_overriddenCost(int defaultCost, int overriddenCost, Provider provider, ResourceType type) {
+ TradingRules rules = new TradingRules(defaultCost);
+ rules.setCost(type, provider, overriddenCost);
+ BoughtResources resources = TestUtils.createBoughtResources(provider, type);
+ assertEquals(overriddenCost, rules.computeCost(Collections.singletonList(resources)));
+ }
+
+ @Theory
+ public void computeCost_defaultCostWhenOverrideOnOtherProviderOrType(int defaultCost, int overriddenCost,
+ Provider overriddenProvider, ResourceType overriddenType, Provider provider, ResourceType type) {
+ assumeTrue(overriddenProvider != provider || overriddenType != type);
+ TradingRules rules = new TradingRules(defaultCost);
+ rules.setCost(overriddenType, overriddenProvider, overriddenCost);
+ BoughtResources resources = TestUtils.createBoughtResources(provider, type);
+ assertEquals(defaultCost, rules.computeCost(Collections.singletonList(resources)));
+ }
+
+ @Theory
+ public void computeCost_oneDefaultAndOneOverriddenType(int defaultCost, int overriddenCost,
+ ResourceType overriddenType, Provider provider, ResourceType type) {
+ assumeTrue(overriddenType != type);
+ TradingRules rules = new TradingRules(defaultCost);
+ rules.setCost(overriddenType, provider, overriddenCost);
+ BoughtResources resources = TestUtils.createBoughtResources(provider, overriddenType, type);
+ assertEquals(defaultCost + overriddenCost, rules.computeCost(Collections.singletonList(resources)));
+ }
+
+ @Theory
+ public void computeCost_oneDefaultAndOneOverriddenProvider(int defaultCost, int overriddenCost,
+ Provider overriddenProvider, Provider provider, ResourceType type) {
+ assumeTrue(overriddenProvider != provider);
+ TradingRules rules = new TradingRules(defaultCost);
+ rules.setCost(type, overriddenProvider, overriddenCost);
+
+ List<BoughtResources> boughtResources = new ArrayList<>(2);
+ boughtResources.add(TestUtils.createBoughtResources(provider, type));
+ boughtResources.add(TestUtils.createBoughtResources(overriddenProvider, type));
+
+ assertEquals(defaultCost + overriddenCost, rules.computeCost(boughtResources));
+ }
+
+} \ No newline at end of file
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 968e4821..66a8e7c6 100644
--- a/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java
+++ b/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java
@@ -9,7 +9,9 @@ import org.luxons.sevenwonders.game.boards.Board;
import org.luxons.sevenwonders.game.cards.Card;
import org.luxons.sevenwonders.game.cards.Color;
import org.luxons.sevenwonders.game.cards.Requirements;
+import org.luxons.sevenwonders.game.resources.BoughtResources;
import org.luxons.sevenwonders.game.resources.Production;
+import org.luxons.sevenwonders.game.resources.Provider;
import org.luxons.sevenwonders.game.resources.ResourceType;
import org.luxons.sevenwonders.game.resources.Resources;
import org.luxons.sevenwonders.game.wonders.Wonder;
@@ -69,6 +71,13 @@ public class TestUtils {
return resources;
}
+ public static BoughtResources createBoughtResources(Provider provider, ResourceType... resources) {
+ BoughtResources boughtResources = new BoughtResources();
+ boughtResources.setProvider(provider);
+ boughtResources.setResources(TestUtils.createResources(resources));
+ return boughtResources;
+ }
+
public static List<Card> createSampleCards(int fromIndex, int nbCards) {
List<Card> sampleCards = new ArrayList<>();
for (int i = fromIndex; i < fromIndex + nbCards; i++) {
bgstack15