summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-05-01 01:23:15 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-05-01 01:23:15 +0200
commit22b163ca9c31c750f4701f01c472ee04f8f2ed14 (patch)
treef9ca8cd27145dc9d27d826a384d81aa3febfff26
parent027656acf714c8c2015cd7a8d3b84367e4b97640 (diff)
downloadJRummikub-22b163ca9c31c750f4701f01c472ee04f8f2ed14.tar
JRummikub-22b163ca9c31c750f4701f01c472ee04f8f2ed14.zip
StoneSet fertig und getestet :-)
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@47 72836036-5685-4462-b002-a69064685172
-rw-r--r--src/jrummikub/model/StoneSet.java18
-rw-r--r--test/jrummikub/model/StoneSetTest.java4
2 files changed, 12 insertions, 10 deletions
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<Stone> {
* Splitting {@link Position}
*/
public Pair<StoneSet, StoneSet> 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<StoneSet, StoneSet>(firstSet, secondSet);
}
/**
@@ -108,8 +108,10 @@ public class StoneSet implements Iterable<Stone> {
* StoneSet to be joined to active StoneSet
*/
public StoneSet join(StoneSet other) {
- return null;
-
+ List<Stone> joinedList = new ArrayList<Stone>();
+ 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);