summaryrefslogtreecommitdiff
path: root/backend/src/test/java
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2017-05-15 23:14:24 +0200
committerJoffrey BION <joffrey.bion@gmail.com>2017-05-15 23:14:24 +0200
commit2f4ddf0b69629fa7c0d41759f07b9f075941d278 (patch)
treea4128363ae06fddd648ff9ab8187fad104d6b040 /backend/src/test/java
parentRemove frontend test watch for gradle build (diff)
downloadseven-wonders-2f4ddf0b69629fa7c0d41759f07b9f075941d278.tar.gz
seven-wonders-2f4ddf0b69629fa7c0d41759f07b9f075941d278.tar.bz2
seven-wonders-2f4ddf0b69629fa7c0d41759f07b9f075941d278.zip
Add tests for requirement and payment of bought resources
Diffstat (limited to 'backend/src/test/java')
-rw-r--r--backend/src/test/java/org/luxons/sevenwonders/game/cards/RequirementsTest.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/backend/src/test/java/org/luxons/sevenwonders/game/cards/RequirementsTest.java b/backend/src/test/java/org/luxons/sevenwonders/game/cards/RequirementsTest.java
index efed4f7d..1b1607d4 100644
--- a/backend/src/test/java/org/luxons/sevenwonders/game/cards/RequirementsTest.java
+++ b/backend/src/test/java/org/luxons/sevenwonders/game/cards/RequirementsTest.java
@@ -1,5 +1,6 @@
package org.luxons.sevenwonders.game.cards;
+import java.util.Arrays;
import java.util.Collections;
import org.junit.experimental.theories.DataPoints;
@@ -8,10 +9,13 @@ 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.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;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
@@ -76,4 +80,53 @@ public class RequirementsTest {
assertTrue(requirements.couldBeMetBy(table, 0));
}
}
+
+ @Theory
+ public void resourceRequirement_boughtResource(ResourceType initialResource, ResourceType boughtResource,
+ ResourceType requiredResource) {
+ assumeTrue(initialResource != requiredResource);
+
+ Requirements requirements = TestUtils.createRequirements(requiredResource);
+
+ Board board = TestUtils.createBoard(initialResource, 2);
+ Board neighbourBoard = TestUtils.createBoard(initialResource, 0);
+ neighbourBoard.getPublicProduction().addFixedResource(boughtResource, 1);
+ Table table = new Table(Arrays.asList(board, neighbourBoard));
+
+ BoughtResources resources = new BoughtResources();
+ resources.setProvider(Provider.RIGHT_PLAYER);
+ resources.setResources(TestUtils.createResources(boughtResource));
+
+ assertFalse(requirements.areMetWithoutNeighboursBy(board));
+ assertEquals(boughtResource == requiredResource,
+ requirements.areMetWithHelpBy(board, Collections.singletonList(resources)));
+
+ if (boughtResource == requiredResource) {
+ assertTrue(requirements.couldBeMetBy(table, 0));
+ }
+ }
+
+ @Theory
+ public void pay_boughtResource(ResourceType initialResource, ResourceType requiredResource) {
+ assumeTrue(initialResource != requiredResource);
+
+ Requirements requirements = TestUtils.createRequirements(requiredResource);
+
+ Board board = TestUtils.createBoard(initialResource, 2);
+ Board neighbourBoard = TestUtils.createBoard(requiredResource, 0);
+ Table table = new Table(Arrays.asList(board, neighbourBoard));
+
+ BoughtResources boughtResources = new BoughtResources();
+ boughtResources.setProvider(Provider.RIGHT_PLAYER);
+ boughtResources.setResources(TestUtils.createResources(requiredResource));
+
+ assertFalse(requirements.areMetWithoutNeighboursBy(board));
+ assertTrue(requirements.areMetWithHelpBy(board, Collections.singletonList(boughtResources)));
+ assertTrue(requirements.couldBeMetBy(table, 0));
+
+ requirements.pay(table, 0, Collections.singletonList(boughtResources));
+
+ assertEquals(0, board.getGold());
+ assertEquals(2, neighbourBoard.getGold());
+ }
}
bgstack15