From 31221a3df74ff0b1a60f964d5ecbcd136f876151 Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Wed, 10 May 2017 06:37:01 +0200 Subject: Add more complicated test for playability --- .../game/resources/BestPriceCalculatorTest.java | 39 ++++++++++++++++++---- 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'backend/src/test/java') diff --git a/backend/src/test/java/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.java b/backend/src/test/java/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.java index bad611af..ad1641c5 100644 --- a/backend/src/test/java/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.java +++ b/backend/src/test/java/org/luxons/sevenwonders/game/resources/BestPriceCalculatorTest.java @@ -34,31 +34,35 @@ public class BestPriceCalculatorTest { @Test public void bestPrice_fixedResources_overridenCost() { - Board left = TestUtils.createBoard(ResourceType.WOOD); Board main = TestUtils.createBoard(ResourceType.STONE); + main.getTradingRules().setCost(ResourceType.WOOD, Provider.RIGHT_PLAYER, 1); + + Board left = TestUtils.createBoard(ResourceType.WOOD); Board right = TestUtils.createBoard(ResourceType.WOOD); Board opposite = TestUtils.createBoard(ResourceType.GLASS); - Table table = new Table(Arrays.asList(main, right, left, opposite)); + Table table = new Table(Arrays.asList(main, right, opposite, left)); - main.getTradingRules().setCost(ResourceType.WOOD, Provider.RIGHT_PLAYER, 1); Resources resources = new Resources(); resources.add(ResourceType.WOOD, 1); assertEquals(1, BestPriceCalculator.bestPrice(resources, table, 0)); assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 1)); - assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 2)); - assertEquals(2, BestPriceCalculator.bestPrice(resources, table, 3)); + assertEquals(2, BestPriceCalculator.bestPrice(resources, table, 2)); + assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 3)); } @Test public void bestPrice_mixedResources_overridenCost() { Board left = TestUtils.createBoard(ResourceType.WOOD); + Board main = TestUtils.createBoard(ResourceType.STONE); + main.getTradingRules().setCost(ResourceType.WOOD, Provider.RIGHT_PLAYER, 1); + Board right = TestUtils.createBoard(ResourceType.ORE); right.getProduction().addChoice(ResourceType.WOOD, ResourceType.CLAY); + Table table = new Table(Arrays.asList(main, right, left)); - main.getTradingRules().setCost(ResourceType.WOOD, Provider.RIGHT_PLAYER, 1); Resources resources = new Resources(); resources.add(ResourceType.WOOD, 1); @@ -66,4 +70,27 @@ public class BestPriceCalculatorTest { assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 1)); assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 2)); } + + @Test + public void bestPrice_chooseCheapest() { + Board left = TestUtils.createBoard(ResourceType.WOOD); + + Board main = TestUtils.createBoard(ResourceType.WOOD); + main.getProduction().addChoice(ResourceType.ORE, ResourceType.CLAY); + main.getTradingRules().setCost(ResourceType.CLAY, Provider.RIGHT_PLAYER, 1); + + Board right = TestUtils.createBoard(ResourceType.WOOD); + right.getProduction().addFixedResource(ResourceType.ORE, 1); + right.getProduction().addFixedResource(ResourceType.CLAY, 1); + + Table table = new Table(Arrays.asList(main, right, left)); + + + Resources resources = new Resources(); + resources.add(ResourceType.ORE, 1); + resources.add(ResourceType.CLAY, 1); + assertEquals(1, BestPriceCalculator.bestPrice(resources, table, 0)); + assertEquals(0, BestPriceCalculator.bestPrice(resources, table, 1)); + assertEquals(4, BestPriceCalculator.bestPrice(resources, table, 2)); + } } -- cgit