From 2f4ddf0b69629fa7c0d41759f07b9f075941d278 Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Mon, 15 May 2017 23:14:24 +0200 Subject: Add tests for requirement and payment of bought resources --- .../sevenwonders/game/cards/RequirementsTest.java | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) 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()); + } } -- cgit