From 4178ba9700ffd6619f995482a369bd5133276e2e Mon Sep 17 00:00:00 2001 From: Joffrey Bion Date: Thu, 28 May 2020 13:03:36 +0200 Subject: Fix production alternative duplicates Having twice the same choice wasn't supported so far. This can happen with Alexandria's bonuses (4 primary resources, or 3 secondary) associated to the yellow Market/Caravansery cards. Resolves: https://github.com/joffrey-bion/seven-wonders/issues/19 --- .../engine/resources/ProductionTest.kt | 41 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'sw-engine/src/test/kotlin') diff --git a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/resources/ProductionTest.kt b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/resources/ProductionTest.kt index c449c784..9bc04142 100644 --- a/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/resources/ProductionTest.kt +++ b/sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/resources/ProductionTest.kt @@ -11,7 +11,6 @@ import org.luxons.sevenwonders.model.resources.ResourceType.PAPYRUS import org.luxons.sevenwonders.model.resources.ResourceType.STONE import org.luxons.sevenwonders.model.resources.ResourceType.WOOD import java.util.EnumSet -import java.util.HashSet import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -227,13 +226,23 @@ class ProductionTest { assertEquals(production.getAlternativeResources(), production.asChoices()) } + @Test + fun asChoices_withDuplicateChoices() { + val production = Production() + production.addChoice(STONE, WOOD) + production.addChoice(STONE, ORE) + production.addChoice(STONE, ORE) + production.addChoice(CLAY, LOOM, GLASS) + assertEquals(production.getAlternativeResources(), production.asChoices()) + } + @Test fun asChoices_onlyFixed() { val production = Production() production.addFixedResource(WOOD, 1) production.addFixedResource(CLAY, 2) - val expected = HashSet>() + val expected = mutableListOf>() expected.add(EnumSet.of(WOOD)) expected.add(EnumSet.of(CLAY)) expected.add(EnumSet.of(CLAY)) @@ -249,12 +258,32 @@ class ProductionTest { production.addFixedResource(WOOD, 1) production.addFixedResource(CLAY, 2) - val expected = HashSet>() + val expected = mutableListOf>() + expected.add(EnumSet.of(WOOD)) + expected.add(EnumSet.of(CLAY)) + expected.add(EnumSet.of(CLAY)) expected.add(EnumSet.of(STONE, ORE)) expected.add(EnumSet.of(CLAY, LOOM, GLASS)) + + assertEquals(expected, production.asChoices()) + } + + @Test + fun asChoices_mixed_withDuplicates() { + val production = Production() + production.addChoice(STONE, ORE) + production.addChoice(CLAY, LOOM, GLASS) + production.addChoice(STONE, ORE) + production.addFixedResource(WOOD, 1) + production.addFixedResource(CLAY, 2) + + val expected = mutableListOf>() expected.add(EnumSet.of(WOOD)) expected.add(EnumSet.of(CLAY)) expected.add(EnumSet.of(CLAY)) + expected.add(EnumSet.of(STONE, ORE)) + expected.add(EnumSet.of(CLAY, LOOM, GLASS)) + expected.add(EnumSet.of(STONE, ORE)) assertEquals(expected, production.asChoices()) } @@ -269,13 +298,13 @@ class ProductionTest { fun equals_trueWhenSameContent() { val production1 = Production() val production2 = Production() - assertTrue(production1 == production2) + assertEquals(production1, production2) production1.addFixedResource(GLASS, 1) production2.addFixedResource(GLASS, 1) - assertTrue(production1 == production2) + assertEquals(production1, production2) production1.addChoice(ORE, WOOD) production2.addChoice(ORE, WOOD) - assertTrue(production1 == production2) + assertEquals(production1, production2) } @Test -- cgit