diff options
Diffstat (limited to 'test/jrummikub')
-rw-r--r-- | test/jrummikub/model/StoneSetTest.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/jrummikub/model/StoneSetTest.java b/test/jrummikub/model/StoneSetTest.java index fc7ebda..c70dc59 100644 --- a/test/jrummikub/model/StoneSetTest.java +++ b/test/jrummikub/model/StoneSetTest.java @@ -1,6 +1,66 @@ package jrummikub.model; +import java.util.ArrayList; +import java.util.List; + +import jrummikub.util.Pair; +import static jrummikub.model.StoneColor.*; + +import org.junit.*; +import static org.junit.Assert.*; public class StoneSetTest { + // invalid Split + @Test(expected = AssertionError.class) + public void testSplitInvalidLow() { + StoneSet testSet = createTestSet(); + testSet.splitAt(0); + + } + + @Test(expected = AssertionError.class) + public void testSplitInvalidHigh() { + StoneSet testSet = createTestSet(); + testSet.splitAt(3); + + } + + // valid Split + @Test + public void testSplitValid() { + StoneSet testSet = createTestSet(); + Pair<StoneSet, StoneSet> newSets = testSet.splitAt(1); + // Sets have right size + assertEquals(1, newSets.getFirst().size()); + assertEquals(2, newSets.getSecond().size()); + // Set have right Stones + assertSame(testSet.get(0), newSets.getFirst().get(0)); + assertSame(testSet.get(1), newSets.getSecond().get(0)); + assertSame(testSet.get(2), newSets.getSecond().get(1)); + } + + private StoneSet createTestSet() { + List<Stone> stones = new ArrayList<Stone>(); + stones.add(new Stone(1, BLUE, false)); + stones.add(new Stone(1, RED, false)); + stones.add(new Stone(1, BLACK, false)); + StoneSet testSet = new StoneSet(stones); + return testSet; + } + + // join + @Test + public void testJoin() { + StoneSet testSet = createTestSet(); + StoneSet secondSet = new StoneSet(new Stone(2, BLUE, false)); + StoneSet joinedSet = testSet.join(secondSet); + // Sets have right size + assertEquals(4, joinedSet.size()); + // Set have right Stones + assertSame(testSet.get(0), joinedSet.get(0)); + assertSame(testSet.get(1), joinedSet.get(1)); + assertSame(testSet.get(2), joinedSet.get(2)); + assertSame(secondSet.get(0), joinedSet.get(3)); + } } |