diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java index f10eca0..09eecd5 100644 --- a/src/jrummikub/model/StoneSet.java +++ b/src/jrummikub/model/StoneSet.java @@ -91,14 +91,14 @@ public class StoneSet implements Iterable { * Splitting {@link Position} */ public Pair splitAt(int position) { - // Exception falls falscher index + // Exception in case of wrong index if (position == 0 || position == stones.size()) { - - } else { - + throw new IndexOutOfBoundsException(); } - return null; - + StoneSet firstSet = new StoneSet(stones.subList(0, position)); + StoneSet secondSet = new StoneSet(stones.subList(position, + stones.size())); + return new Pair(firstSet, secondSet); } /** @@ -108,8 +108,10 @@ public class StoneSet implements Iterable { * StoneSet to be joined to active StoneSet */ public StoneSet join(StoneSet other) { - return null; - + List joinedList = new ArrayList(); + joinedList.addAll(stones); + joinedList.addAll(other.stones); + return new StoneSet(joinedList); } public int size() { diff --git a/test/jrummikub/model/StoneSetTest.java b/test/jrummikub/model/StoneSetTest.java index b2d6a46..1b4e062 100644 --- a/test/jrummikub/model/StoneSetTest.java +++ b/test/jrummikub/model/StoneSetTest.java @@ -93,14 +93,14 @@ public class StoneSetTest { } // invalid Split - @Test(expected = AssertionError.class) + @Test(expected = IndexOutOfBoundsException.class) public void testSplitInvalidLow() { StoneSet testSet = createTestSet(); testSet.splitAt(0); } - @Test(expected = AssertionError.class) + @Test(expected = IndexOutOfBoundsException.class) public void testSplitInvalidHigh() { StoneSet testSet = createTestSet(); testSet.splitAt(3);