diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2016-12-07 03:53:36 +0100 |
---|---|---|
committer | Joffrey BION <joffrey.bion@gmail.com> | 2016-12-08 02:09:42 +0100 |
commit | 086c18d3ac0c57e3641c5c1c655d6c55b2d6e23b (patch) | |
tree | 14a378456a932faa58b72da3da5d42bf3a21dd99 /src/test/java/org/luxons/sevenwonders | |
parent | Add game card and wonders data (diff) | |
download | seven-wonders-086c18d3ac0c57e3641c5c1c655d6c55b2d6e23b.tar.gz seven-wonders-086c18d3ac0c57e3641c5c1c655d6c55b2d6e23b.tar.bz2 seven-wonders-086c18d3ac0c57e3641c5c1c655d6c55b2d6e23b.zip |
First draft of resource production elements
Diffstat (limited to 'src/test/java/org/luxons/sevenwonders')
-rw-r--r-- | src/test/java/org/luxons/sevenwonders/game/resources/ProductionTest.java | 221 | ||||
-rw-r--r-- | src/test/java/org/luxons/sevenwonders/game/resources/ResourcesTest.java | 387 |
2 files changed, 608 insertions, 0 deletions
diff --git a/src/test/java/org/luxons/sevenwonders/game/resources/ProductionTest.java b/src/test/java/org/luxons/sevenwonders/game/resources/ProductionTest.java new file mode 100644 index 00000000..58b82dc1 --- /dev/null +++ b/src/test/java/org/luxons/sevenwonders/game/resources/ProductionTest.java @@ -0,0 +1,221 @@ +package org.luxons.sevenwonders.game.resources; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class ProductionTest { + + private Resources emptyResources; + + private Resources resources1Wood; + + private Resources resources1Stone; + + private Resources resources1Stone1Wood; + + private Resources resources2Stones; + + private Resources resources2Stones3Clay; + + @Before + public void init() { + emptyResources = new Resources(); + + resources1Wood = new Resources(); + resources1Wood.add(ResourceType.WOOD, 1); + + resources1Stone = new Resources(); + resources1Stone.add(ResourceType.STONE, 1); + + resources1Stone1Wood = new Resources(); + resources1Stone1Wood.add(ResourceType.STONE, 1); + resources1Stone1Wood.add(ResourceType.WOOD, 1); + + resources2Stones = new Resources(); + resources2Stones.add(ResourceType.STONE, 2); + + resources2Stones3Clay = new Resources(); + resources2Stones3Clay.add(ResourceType.STONE, 2); + resources2Stones3Clay.add(ResourceType.CLAY, 3); + } + + @Test + public void contains_newProductionContainsEmpty() throws Exception { + Production production = new Production(); + assertTrue(production.contains(emptyResources)); + } + + @Test + public void contains_singleFixedResource_noneAtAll() throws Exception { + Production production = new Production(); + assertFalse(production.contains(resources2Stones)); + } + + @Test + public void contains_singleFixedResource_notEnough() throws Exception { + Production production = new Production(); + production.addFixedResource(ResourceType.STONE, 1); + assertFalse(production.contains(resources2Stones)); + } + + @Test + public void contains_singleFixedResource_justEnough() throws Exception { + Production production = new Production(); + production.addFixedResource(ResourceType.STONE, 2); + assertTrue(production.contains(resources2Stones)); + } + + @Test + public void contains_singleFixedResource_moreThanEnough() throws Exception { + Production production = new Production(); + production.addFixedResource(ResourceType.STONE, 3); + assertTrue(production.contains(resources2Stones)); + } + + @Test + public void contains_singleFixedResource_moreThanEnough_amongOthers() throws Exception { + Production production = new Production(); + production.addFixedResource(ResourceType.STONE, 3); + production.addFixedResource(ResourceType.CLAY, 2); + assertTrue(production.contains(resources2Stones)); + } + + @Test + public void contains_multipleFixedResources_notEnoughOfOne() throws Exception { + Production production = new Production(); + production.addFixedResource(ResourceType.STONE, 3); + production.addFixedResource(ResourceType.CLAY, 1); + assertFalse(production.contains(resources2Stones3Clay)); + } + + @Test + public void contains_multipleFixedResources_notEnoughOfBoth() throws Exception { + Production production = new Production(); + production.addFixedResource(ResourceType.STONE, 1); + production.addFixedResource(ResourceType.CLAY, 1); + assertFalse(production.contains(resources2Stones3Clay)); + } + + @Test + public void contains_multipleFixedResources_moreThanEnough() throws Exception { + Production production = new Production(); + production.addFixedResource(ResourceType.STONE, 3); + production.addFixedResource(ResourceType.CLAY, 5); + assertTrue(production.contains(resources2Stones3Clay)); + } + + @Test + public void contains_singleChoice_containsEmpty() throws Exception { + Production production = new Production(); + production.addChoice(ResourceType.STONE, ResourceType.CLAY); + assertTrue(production.contains(emptyResources)); + } + + @Test + public void contains_singleChoice_enough() throws Exception { + Production production = new Production(); + production.addChoice(ResourceType.STONE, ResourceType.WOOD); + assertTrue(production.contains(resources1Wood)); + assertTrue(production.contains(resources1Stone)); + } + + @Test + public void contains_multipleChoices_notBoth() throws Exception { + Production production = new Production(); + production.addChoice(ResourceType.STONE, ResourceType.CLAY); + production.addChoice(ResourceType.STONE, ResourceType.CLAY); + production.addChoice(ResourceType.STONE, ResourceType.CLAY); + assertFalse(production.contains(resources2Stones3Clay)); + } + + @Test + public void contains_multipleChoices_enough() throws Exception { + Production production = new Production(); + production.addChoice(ResourceType.STONE, ResourceType.ORE); + production.addChoice(ResourceType.STONE, ResourceType.WOOD); + assertTrue(production.contains(resources1Stone1Wood)); + } + + @Test + public void contains_multipleChoices_enoughReverseOrder() throws Exception { + Production production = new Production(); + production.addChoice(ResourceType.STONE, ResourceType.WOOD); + production.addChoice(ResourceType.STONE, ResourceType.ORE); + assertTrue(production.contains(resources1Stone1Wood)); + } + + @Test + public void contains_multipleChoices_moreThanEnough() throws Exception { + Production production = new Production(); + production.addChoice(ResourceType.LINEN, ResourceType.GLASS, ResourceType.PAPYRUS); + production.addChoice(ResourceType.STONE, ResourceType.ORE); + production.addChoice(ResourceType.STONE, ResourceType.WOOD); + assertTrue(production.contains(resources1Stone1Wood)); + } + + @Test + public void contains_mixedFixedAndChoice_enough() throws Exception { + Production production = new Production(); + production.addFixedResource(ResourceType.WOOD, 1); + production.addChoice(ResourceType.STONE, ResourceType.WOOD); + assertTrue(production.contains(resources1Stone1Wood)); + } + + @Test + public void addAll_empty() throws Exception { + Production production = new Production(); + production.addAll(emptyResources); + assertTrue(production.contains(emptyResources)); + } + + @Test + public void addAll_singleResource() throws Exception { + Production production = new Production(); + production.addAll(resources1Stone); + assertTrue(production.contains(resources1Stone)); + } + + @Test + public void addAll_multipleResources() throws Exception { + Production production = new Production(); + production.addAll(resources2Stones3Clay); + assertTrue(production.contains(resources2Stones3Clay)); + } + + @Test + public void addAll_production_multipleFixedResources() throws Exception { + Production production = new Production(); + production.addAll(resources2Stones3Clay); + + Production production2 = new Production(); + production2.addAll(production); + + assertTrue(production2.contains(resources2Stones3Clay)); + } + + @Test + public void addAll_production_multipleChoices() throws Exception { + Production production = new Production(); + production.addChoice(ResourceType.STONE, ResourceType.WOOD); + production.addChoice(ResourceType.STONE, ResourceType.ORE); + + Production production2 = new Production(); + production2.addAll(production); + assertTrue(production.contains(resources1Stone1Wood)); + } + + @Test + public void addAll_production_mixedFixedResourcesAndChoices() throws Exception { + Production production = new Production(); + production.addFixedResource(ResourceType.WOOD, 1); + production.addChoice(ResourceType.STONE, ResourceType.WOOD); + + Production production2 = new Production(); + production2.addAll(production); + + assertTrue(production.contains(resources1Stone1Wood)); + } +}
\ No newline at end of file diff --git a/src/test/java/org/luxons/sevenwonders/game/resources/ResourcesTest.java b/src/test/java/org/luxons/sevenwonders/game/resources/ResourcesTest.java new file mode 100644 index 00000000..efcea74e --- /dev/null +++ b/src/test/java/org/luxons/sevenwonders/game/resources/ResourcesTest.java @@ -0,0 +1,387 @@ +package org.luxons.sevenwonders.game.resources; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class ResourcesTest { + + @Test + public void init_shouldBeEmpty() { + Resources resources = new Resources(); + for (ResourceType resourceType : ResourceType.values()) { + assertEquals(0, resources.getQuantity(resourceType)); + } + } + + @Test + public void add_zero() { + Resources resources = new Resources(); + resources.add(ResourceType.CLAY, 0); + assertEquals(0, resources.getQuantity(ResourceType.CLAY)); + } + + @Test + public void add_simple() { + Resources resources = new Resources(); + resources.add(ResourceType.WOOD, 3); + assertEquals(3, resources.getQuantity(ResourceType.WOOD)); + } + + @Test + public void add_multipleCallsStacked() { + Resources resources = new Resources(); + resources.add(ResourceType.ORE, 3); + resources.add(ResourceType.ORE, 2); + assertEquals(5, resources.getQuantity(ResourceType.ORE)); + } + + @Test + public void add_interlaced() { + Resources resources = new Resources(); + resources.add(ResourceType.GLASS, 3); + resources.add(ResourceType.STONE, 1); + resources.add(ResourceType.WOOD, 4); + resources.add(ResourceType.GLASS, 2); + assertEquals(5, resources.getQuantity(ResourceType.GLASS)); + } + + @Test + public void addAll_empty() { + Resources resources = new Resources(); + resources.add(ResourceType.STONE, 1); + resources.add(ResourceType.CLAY, 3); + + Resources emptyResources = new Resources(); + + resources.addAll(emptyResources); + assertEquals(1, resources.getQuantity(ResourceType.STONE)); + assertEquals(3, resources.getQuantity(ResourceType.CLAY)); + assertEquals(0, resources.getQuantity(ResourceType.ORE)); + assertEquals(0, resources.getQuantity(ResourceType.GLASS)); + assertEquals(0, resources.getQuantity(ResourceType.LINEN)); + } + + @Test + public void addAll_zeros() { + Resources resources = new Resources(); + resources.add(ResourceType.STONE, 1); + resources.add(ResourceType.CLAY, 3); + + Resources emptyResources = new Resources(); + emptyResources.add(ResourceType.STONE, 0); + emptyResources.add(ResourceType.CLAY, 0); + + resources.addAll(emptyResources); + assertEquals(1, resources.getQuantity(ResourceType.STONE)); + assertEquals(3, resources.getQuantity(ResourceType.CLAY)); + assertEquals(0, resources.getQuantity(ResourceType.ORE)); + assertEquals(0, resources.getQuantity(ResourceType.GLASS)); + assertEquals(0, resources.getQuantity(ResourceType.LINEN)); + } + + @Test + public void addAll_same() { + Resources resources = new Resources(); + resources.add(ResourceType.STONE, 1); + resources.add(ResourceType.CLAY, 3); + + Resources resources2 = new Resources(); + resources.add(ResourceType.STONE, 2); + resources.add(ResourceType.CLAY, 6); + + resources.addAll(resources2); + assertEquals(3, resources.getQuantity(ResourceType.STONE)); + assertEquals(9, resources.getQuantity(ResourceType.CLAY)); + assertEquals(0, resources.getQuantity(ResourceType.ORE)); + assertEquals(0, resources.getQuantity(ResourceType.GLASS)); + assertEquals(0, resources.getQuantity(ResourceType.LINEN)); + } + + @Test + public void addAll_overlap() { + Resources resources = new Resources(); + resources.add(ResourceType.STONE, 1); + resources.add(ResourceType.CLAY, 3); + + Resources resources2 = new Resources(); + resources.add(ResourceType.CLAY, 6); + resources.add(ResourceType.ORE, 4); + + resources.addAll(resources2); + assertEquals(1, resources.getQuantity(ResourceType.STONE)); + assertEquals(9, resources.getQuantity(ResourceType.CLAY)); + assertEquals(4, resources.getQuantity(ResourceType.ORE)); + assertEquals(0, resources.getQuantity(ResourceType.GLASS)); + assertEquals(0, resources.getQuantity(ResourceType.LINEN)); + } + + @Test + public void contains_emptyContainsEmpty() { + Resources emptyResources = new Resources(); + Resources emptyResources2 = new Resources(); + assertTrue(emptyResources.contains(emptyResources2)); + } + + @Test + public void contains_singleTypeContainsEmpty() { + Resources resources = new Resources(); + resources.add(ResourceType.STONE, 1); + + Resources emptyResources = new Resources(); + + assertTrue(resources.contains(emptyResources)); + } + + @Test + public void contains_multipleTypesContainsEmpty() { + Resources resources = new Resources(); + resources.add(ResourceType.STONE, 1); + resources.add(ResourceType.CLAY, 3); + + Resources emptyResources = new Resources(); + + assertTrue(resources.contains(emptyResources)); + } + + @Test + public void contains_self() { + Resources resources = new Resources(); + resources.add(ResourceType.STONE, 1); + resources.add(ResourceType.CLAY, 3); + + assertTrue(resources.contains(resources)); + } + + @Test + public void contains_allOfEachType() { + Resources resources = new Resources(); + resources.add(ResourceType.STONE, 1); + resources.add(ResourceType.CLAY, 3); + + Resources resources2 = new Resources(); + resources2.add(ResourceType.STONE, 1); + resources2.add(ResourceType.CLAY, 3); + + assertTrue(resources.contains(resources2)); + } + + @Test + public void contains_someOfEachType() { + Resources resources = new Resources(); + resources.add(ResourceType.STONE, 2); + resources.add(ResourceType.CLAY, 4); + + Resources resources2 = new Resources(); + resources2.add(ResourceType.STONE, 1); + resources2.add(ResourceType.CLAY, 3); + + assertTrue(resources.contains(resources2)); + } + + @Test + public void contains_someOfSomeTypes() { + Resources resources = new Resources(); + resources.add(ResourceType.STONE, 2); + resources.add(ResourceType.CLAY, 4); + + Resources resources2 = new Resources(); + resources2.add(ResourceType.CLAY, 3); + + assertTrue(resources.contains(resources2)); + } + + @Test + public void contains_allOfSomeTypes() { + Resources resources = new Resources(); + resources.add(ResourceType.STONE, 2); + resources.add(ResourceType.CLAY, 4); + + Resources resources2 = new Resources(); + resources2.add(ResourceType.CLAY, 4); + + assertTrue(resources.contains(resources2)); + } + + @Test + public void minus_empty() { + Resources resources = new Resources(); + resources.add(ResourceType.STONE, 1); + resources.add(ResourceType.CLAY, 3); + + Resources emptyResources = new Resources(); + + Resources diff = resources.minus(emptyResources); + assertEquals(1, diff.getQuantity(ResourceType.STONE)); + assertEquals(3, diff.getQuantity(ResourceType.CLAY)); + assertEquals(0, diff.getQuantity(ResourceType.ORE)); + assertEquals(0, diff.getQuantity(ResourceType.GLASS)); + assertEquals(0, diff.getQuantity(ResourceType.LINEN)); + } + + @Test + public void minus_self() { + Resources resources = new Resources(); + resources.add(ResourceType.STONE, 1); + resources.add(ResourceType.CLAY, 3); + + Resources diff = resources.minus(resources); + assertEquals(0, diff.getQuantity(ResourceType.STONE)); + assertEquals(0, diff.getQuantity(ResourceType.CLAY)); + assertEquals(0, diff.getQuantity(ResourceType.ORE)); + assertEquals(0, diff.getQuantity(ResourceType.GLASS)); + assertEquals(0, diff.getQuantity(ResourceType.LINEN)); + } + + @Test + public void minus_allOfEachType() { + Resources resources = new Resources(); + resources.add(ResourceType.STONE, 1); + resources.add(ResourceType.CLAY, 3); + + Resources resources2 = new Resources(); + resources2.add(ResourceType.STONE, 1); + resources2.add(ResourceType.CLAY, 3); + + Resources diff = resources.minus(resources2); + assertEquals(0, diff.getQuantity(ResourceType.STONE)); + assertEquals(0, diff.getQuantity(ResourceType.CLAY)); + assertEquals(0, diff.getQuantity(ResourceType.ORE)); + assertEquals(0, diff.getQuantity(ResourceType.GLASS)); + assertEquals(0, diff.getQuantity(ResourceType.LINEN)); + } + + @Test + public void minus_someOfEachType() { + Resources resources = new Resources(); + resources.add(ResourceType.STONE, 2); + resources.add(ResourceType.CLAY, 4); + + Resources resources2 = new Resources(); + resources2.add(ResourceType.STONE, 1); + resources2.add(ResourceType.CLAY, 3); + + Resources diff = resources.minus(resources2); + assertEquals(1, diff.getQuantity(ResourceType.STONE)); + assertEquals(1, diff.getQuantity(ResourceType.CLAY)); + assertEquals(0, diff.getQuantity(ResourceType.ORE)); + assertEquals(0, diff.getQuantity(ResourceType.GLASS)); + assertEquals(0, diff.getQuantity(ResourceType.LINEN)); + } + + @Test + public void minus_someOfSomeTypes() { + Resources resources = new Resources(); + resources.add(ResourceType.STONE, 2); + resources.add(ResourceType.CLAY, 4); + + Resources resources2 = new Resources(); + resources2.add(ResourceType.CLAY, 3); + + Resources diff = resources.minus(resources2); + assertEquals(2, diff.getQuantity(ResourceType.STONE)); + assertEquals(1, diff.getQuantity(ResourceType.CLAY)); + assertEquals(0, diff.getQuantity(ResourceType.ORE)); + assertEquals(0, diff.getQuantity(ResourceType.GLASS)); + assertEquals(0, diff.getQuantity(ResourceType.LINEN)); + } + + @Test + public void minus_allOfSomeTypes() { + Resources resources = new Resources(); + resources.add(ResourceType.STONE, 2); + resources.add(ResourceType.CLAY, 4); + + Resources resources2 = new Resources(); + resources2.add(ResourceType.CLAY, 4); + + Resources diff = resources.minus(resources2); + assertEquals(2, diff.getQuantity(ResourceType.STONE)); + assertEquals(0, diff.getQuantity(ResourceType.CLAY)); + assertEquals(0, diff.getQuantity(ResourceType.ORE)); + assertEquals(0, diff.getQuantity(ResourceType.GLASS)); + assertEquals(0, diff.getQuantity(ResourceType.LINEN)); + } + + @Test + public void minus_tooMuchOfExistingType() { + Resources resources = new Resources(); + resources.add(ResourceType.CLAY, 4); + + Resources resources2 = new Resources(); + resources2.add(ResourceType.CLAY, 5); + + Resources diff = resources.minus(resources2); + assertEquals(0, diff.getQuantity(ResourceType.CLAY)); + } + + @Test + public void minus_someOfAnAbsentType() { + Resources resources = new Resources(); + + Resources resources2 = new Resources(); + resources2.add(ResourceType.LINEN, 5); + + Resources diff = resources.minus(resources2); + assertEquals(0, diff.getQuantity(ResourceType.LINEN)); + } + + @Test + public void minus_someOfATypeWithZero() { + Resources resources = new Resources(); + resources.add(ResourceType.LINEN, 0); + + Resources resources2 = new Resources(); + resources2.add(ResourceType.LINEN, 5); + + Resources diff = resources.minus(resources2); + assertEquals(0, diff.getQuantity(ResourceType.LINEN)); + } + + @Test + public void isEmpty_noElement() { + Resources resources = new Resources(); + assertTrue(resources.isEmpty()); + } + + @Test + public void isEmpty_singleZeroElement() { + Resources resources = new Resources(); + resources.add(ResourceType.LINEN, 0); + assertTrue(resources.isEmpty()); + } + + @Test + public void isEmpty_multipleZeroElements() { + Resources resources = new Resources(); + resources.add(ResourceType.WOOD, 0); + resources.add(ResourceType.ORE, 0); + resources.add(ResourceType.LINEN, 0); + assertTrue(resources.isEmpty()); + } + + @Test + public void isEmpty_singleElementMoreThanZero() { + Resources resources = new Resources(); + resources.add(ResourceType.LINEN, 3); + assertFalse(resources.isEmpty()); + } + + @Test + public void isEmpty_mixedZeroAndNonZeroElements() { + Resources resources = new Resources(); + resources.add(ResourceType.WOOD, 0); + resources.add(ResourceType.LINEN, 3); + assertFalse(resources.isEmpty()); + } + + @Test + public void isEmpty_mixedZeroAndNonZeroElements_reverseOrder() { + Resources resources = new Resources(); + resources.add(ResourceType.ORE, 3); + resources.add(ResourceType.PAPYRUS, 0); + assertFalse(resources.isEmpty()); + } +}
\ No newline at end of file |