diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2018-04-26 01:08:21 +0200 |
---|---|---|
committer | Joffrey BION <joffrey.bion@gmail.com> | 2018-04-26 01:08:21 +0200 |
commit | 598beca9a5b5357e15b2e7803876446a4484d1ee (patch) | |
tree | 9f1b636c8033863e04fcecb602c4795b40f12e12 /game-engine/src/test/java/org | |
parent | Extract move creation in GameTest (diff) | |
download | seven-wonders-598beca9a5b5357e15b2e7803876446a4484d1ee.tar.gz seven-wonders-598beca9a5b5357e15b2e7803876446a4484d1ee.tar.bz2 seven-wonders-598beca9a5b5357e15b2e7803876446a4484d1ee.zip |
Fix and improve BestPriceCalculator
Diffstat (limited to 'game-engine/src/test/java/org')
-rw-r--r-- | game-engine/src/test/java/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.java | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/game-engine/src/test/java/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.java b/game-engine/src/test/java/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.java index e6438789..9f43ec6b 100644 --- a/game-engine/src/test/java/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.java +++ b/game-engine/src/test/java/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.java @@ -1,6 +1,7 @@ package org.luxons.sevenwonders.game.resources; import java.util.Arrays; +import java.util.Collections; import org.junit.Test; import org.luxons.sevenwonders.game.api.Table; @@ -16,6 +17,7 @@ public class BestPriceCalculatorTest { Table table = TestUtils.createTable(3); Resources resources = new Resources(); assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 0)); + assertEquals(Collections.emptyList(), BestPriceCalculator.bestSolution(resources, table, 0)); } @Test @@ -26,10 +28,16 @@ public class BestPriceCalculatorTest { Table table = new Table(Arrays.asList(main, right, left)); Resources resources = new Resources(); - resources.add(ResourceType.STONE, 1); - assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 0)); - assertEquals(2, BestPriceCalculator.bestPrice(resources, table, 1)); - assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 2)); + resources.add(ResourceType.STONE, 2); + assertEquals(2, BestPriceCalculator.bestPrice(resources, table, 0)); + assertEquals(4, BestPriceCalculator.bestPrice(resources, table, 1)); + assertEquals(2, BestPriceCalculator.bestPrice(resources, table, 2)); + + BoughtResources stoneLeft = new BoughtResources(Provider.LEFT_PLAYER, Resources.of(ResourceType.STONE)); + BoughtResources stoneRight = new BoughtResources(Provider.RIGHT_PLAYER, Resources.of(ResourceType.STONE)); + assertEquals(Collections.singletonList(stoneLeft), BestPriceCalculator.bestSolution(resources, table, 0)); + assertEquals(Arrays.asList(stoneLeft, stoneRight), BestPriceCalculator.bestSolution(resources, table, 1)); + assertEquals(Collections.singletonList(stoneRight), BestPriceCalculator.bestSolution(resources, table, 2)); } @Test @@ -48,6 +56,13 @@ public class BestPriceCalculatorTest { assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 1)); assertEquals(2, BestPriceCalculator.bestPrice(resources, table, 2)); assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 3)); + + BoughtResources woodLeft = new BoughtResources(Provider.LEFT_PLAYER, Resources.of(ResourceType.WOOD)); + BoughtResources woodRight = new BoughtResources(Provider.RIGHT_PLAYER, Resources.of(ResourceType.WOOD)); + assertEquals(Collections.singletonList(woodRight), BestPriceCalculator.bestSolution(resources, table, 0)); + assertEquals(Collections.emptyList(), BestPriceCalculator.bestSolution(resources, table, 1)); + assertEquals(Collections.singletonList(woodLeft), BestPriceCalculator.bestSolution(resources, table, 2)); + assertEquals(Collections.emptyList(), BestPriceCalculator.bestSolution(resources, table, 3)); } @Test @@ -68,6 +83,11 @@ public class BestPriceCalculatorTest { assertEquals(1, BestPriceCalculator.bestPrice(resources, table, 0)); assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 1)); assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 2)); + + BoughtResources woodRight = new BoughtResources(Provider.RIGHT_PLAYER, Resources.of(ResourceType.WOOD)); + assertEquals(Collections.singletonList(woodRight), BestPriceCalculator.bestSolution(resources, table, 0)); + assertEquals(Collections.emptyList(), BestPriceCalculator.bestSolution(resources, table, 1)); + assertEquals(Collections.emptyList(), BestPriceCalculator.bestSolution(resources, table, 2)); } @Test @@ -75,7 +95,7 @@ public class BestPriceCalculatorTest { Board left = TestUtils.createBoard(ResourceType.WOOD); Board main = TestUtils.createBoard(ResourceType.WOOD); - main.getProduction().addChoice(ResourceType.ORE, ResourceType.CLAY); + main.getProduction().addChoice(ResourceType.CLAY, ResourceType.ORE); main.getTradingRules().setCost(ResourceType.CLAY, Provider.RIGHT_PLAYER, 1); Board right = TestUtils.createBoard(ResourceType.WOOD); @@ -92,5 +112,12 @@ public class BestPriceCalculatorTest { assertEquals(1, BestPriceCalculator.bestPrice(resources, table, 0)); assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 1)); assertEquals(4, BestPriceCalculator.bestPrice(resources, table, 2)); + + BoughtResources oreLeft = new BoughtResources(Provider.LEFT_PLAYER, Resources.of(ResourceType.ORE)); + BoughtResources clayLeft = new BoughtResources(Provider.LEFT_PLAYER, Resources.of(ResourceType.CLAY)); + BoughtResources clayRight = new BoughtResources(Provider.RIGHT_PLAYER, Resources.of(ResourceType.CLAY)); + assertEquals(Collections.singletonList(clayRight), BestPriceCalculator.bestSolution(resources, table, 0)); + assertEquals(Collections.emptyList(), BestPriceCalculator.bestSolution(resources, table, 1)); + assertEquals(Arrays.asList(oreLeft, clayLeft), BestPriceCalculator.bestSolution(resources, table, 2)); } } |