summaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2016-12-25 15:54:58 +0100
committerjbion <joffrey.bion@amadeus.com>2016-12-25 15:55:13 +0100
commit9cc964926891b9655571d553fbf0bbf2bc4174f2 (patch)
tree9d6747b329f5b0578b06b7e9ee1873b681d6a5dd /src/test/java/org
parentAdd military conflict resolution at end of age (diff)
downloadseven-wonders-9cc964926891b9655571d553fbf0bbf2bc4174f2.tar.gz
seven-wonders-9cc964926891b9655571d553fbf0bbf2bc4174f2.tar.bz2
seven-wonders-9cc964926891b9655571d553fbf0bbf2bc4174f2.zip
Add proper test for military victory/defeat points
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/boards/MilitaryTest.java70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/test/java/org/luxons/sevenwonders/game/boards/MilitaryTest.java b/src/test/java/org/luxons/sevenwonders/game/boards/MilitaryTest.java
new file mode 100644
index 00000000..9a1fcb65
--- /dev/null
+++ b/src/test/java/org/luxons/sevenwonders/game/boards/MilitaryTest.java
@@ -0,0 +1,70 @@
+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.Settings;
+import org.luxons.sevenwonders.game.boards.Military.UnknownAgeException;
+
+import static org.junit.Assert.*;
+
+@RunWith(Theories.class)
+public class MilitaryTest {
+
+ @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};
+ }
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private static Military createMilitary(int age, int nbPointsPerVictory, int nbPointsPerDefeat) {
+ Map<Integer, Integer> wonPointsPerAge = new HashMap<>();
+ wonPointsPerAge.put(age, nbPointsPerVictory);
+
+ Settings settings = new Settings();
+ settings.setWonPointsPerVictoryPerAge(wonPointsPerAge);
+ settings.setLostPointsPerDefeat(nbPointsPerDefeat);
+
+ return new Military(settings);
+ }
+
+ @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());
+ }
+} \ No newline at end of file
bgstack15