summaryrefslogtreecommitdiff
path: root/sw-engine/src/test/kotlin/org
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@booking.com>2020-05-28 13:03:36 +0200
committerJoffrey Bion <joffrey.bion@booking.com>2020-05-28 13:34:57 +0200
commit4178ba9700ffd6619f995482a369bd5133276e2e (patch)
tree497223513f61a7162d78213e1c9fe7de16064e25 /sw-engine/src/test/kotlin/org
parentClarify message for unavailable resources (diff)
downloadseven-wonders-4178ba9700ffd6619f995482a369bd5133276e2e.tar.gz
seven-wonders-4178ba9700ffd6619f995482a369bd5133276e2e.tar.bz2
seven-wonders-4178ba9700ffd6619f995482a369bd5133276e2e.zip
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
Diffstat (limited to 'sw-engine/src/test/kotlin/org')
-rw-r--r--sw-engine/src/test/kotlin/org/luxons/sevenwonders/engine/resources/ProductionTest.kt41
1 files changed, 35 insertions, 6 deletions
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
@@ -228,12 +227,22 @@ class ProductionTest {
}
@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<Set<ResourceType>>()
+ val expected = mutableListOf<Set<ResourceType>>()
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<Set<ResourceType>>()
+ val expected = mutableListOf<Set<ResourceType>>()
+ 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<Set<ResourceType>>()
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
bgstack15