summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2016-12-24 11:36:42 +0100
committerjbion <joffrey.bion@amadeus.com>2016-12-24 13:55:17 +0100
commite7f41e514ec74ca4ed501738126e819676579eb4 (patch)
tree65aa0ba0e2cb00fdedc34cca6f8082d4616d889c /src/test
parentAdd test for lobby (diff)
downloadseven-wonders-e7f41e514ec74ca4ed501738126e819676579eb4.tar.gz
seven-wonders-e7f41e514ec74ca4ed501738126e819676579eb4.tar.bz2
seven-wonders-e7f41e514ec74ca4ed501738126e819676579eb4.zip
Add equals, hashcode, and computePoints tests for instant effects
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.java49
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java45
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.java47
3 files changed, 134 insertions, 7 deletions
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 f29eb286..f4e52454 100644
--- a/src/test/java/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.java
+++ b/src/test/java/org/luxons/sevenwonders/game/effects/GoldIncreaseTest.java
@@ -4,11 +4,12 @@ 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.TestUtils;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
@RunWith(Theories.class)
public class GoldIncreaseTest {
@@ -26,10 +27,52 @@ 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());
}
+
+ @Theory
+ public void computePoints_isAlwaysZero(int gold) {
+ GoldIncrease goldIncrease = new GoldIncrease(gold);
+ Table table = TestUtils.createTable(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());
+ }
} \ No newline at end of file
diff --git a/src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java b/src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java
index 0f95bea9..fbfc2d6c 100644
--- a/src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java
+++ b/src/test/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcementsTest.java
@@ -4,11 +4,12 @@ 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.TestUtils;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
@RunWith(Theories.class)
public class MilitaryReinforcementsTest {
@@ -29,10 +30,50 @@ public class MilitaryReinforcementsTest {
board.setNbWarSymbols(initialShields);
MilitaryReinforcements reinforcements = new MilitaryReinforcements(additionalShields);
-
reinforcements.apply(board);
assertEquals(initialShields + additionalShields, board.getNbWarSymbols());
}
+ @Theory
+ public void computePoints_isAlwaysZero(int shields) {
+ MilitaryReinforcements reinforcements = new MilitaryReinforcements(shields);
+ Table table = TestUtils.createTable(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());
+ }
} \ No newline at end of file
diff --git a/src/test/java/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.java b/src/test/java/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.java
index 9ff35db3..6031e112 100644
--- a/src/test/java/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.java
+++ b/src/test/java/org/luxons/sevenwonders/game/effects/ProductionIncreaseTest.java
@@ -4,13 +4,14 @@ 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.TestUtils;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
@RunWith(Theories.class)
public class ProductionIncreaseTest {
@@ -39,4 +40,46 @@ public class ProductionIncreaseTest {
Resources moreResources = TestUtils.createResources(initialType, addedType, extraType);
assertFalse(board.getProduction().contains(moreResources));
}
+
+ @Theory
+ public void computePoints_isAlwaysZero(ResourceType addedType) {
+ ProductionIncrease effect = createProductionIncrease(addedType);
+ Table table = TestUtils.createTable(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 = TestUtils.createFixedProduction(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());
+ }
} \ No newline at end of file
bgstack15