summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jrummikub/model/Table.java13
-rw-r--r--test/jrummikub/model/TableTest.java13
2 files changed, 22 insertions, 4 deletions
diff --git a/src/jrummikub/model/Table.java b/src/jrummikub/model/Table.java
index 7787bea..df50bbf 100644
--- a/src/jrummikub/model/Table.java
+++ b/src/jrummikub/model/Table.java
@@ -27,7 +27,9 @@ public class Table extends StoneTray<StoneSet> implements ITable {
@Override
public Pair<StoneSet, StoneSet> pickUpStone(Stone stone) {
StoneInfo info = findStoneInfo(stone);
-
+
+ System.err.println("Stone: " + stone);
+
if (info == null) {
return null;
}
@@ -51,6 +53,7 @@ public class Table extends StoneTray<StoneSet> implements ITable {
}
stonePosition++;
}
+ set = null;
}
// Stone not found
if (set == null) {
@@ -73,10 +76,14 @@ public class Table extends StoneTray<StoneSet> implements ITable {
private Pair<StoneSet, StoneSet> splitSet(StoneSet set, Position setPosition,
int stonePosition) {
pickUp(set);
-
+
Pair<StoneSet, StoneSet> firstSplit = set.splitAt(stonePosition);
+ System.err.println("Size: " + set.size());
+ System.err.println("stonePosition: " + stonePosition);
+ System.err.println("Frist split: " + firstSplit.getFirst() + " " + firstSplit.getSecond());
Pair<StoneSet, StoneSet> secondSplit = firstSplit.getSecond().splitAt(1);
-
+ System.err.println("Second split: " + secondSplit.getFirst() + " " + secondSplit.getSecond());
+
StoneSet leftSet = firstSplit.getFirst();
StoneSet rightSet = secondSplit.getSecond();
diff --git a/test/jrummikub/model/TableTest.java b/test/jrummikub/model/TableTest.java
index e113ba7..a806e14 100644
--- a/test/jrummikub/model/TableTest.java
+++ b/test/jrummikub/model/TableTest.java
@@ -67,13 +67,24 @@ public class TableTest {
}
@Test
- public void testPickNonexistentStone() {
+ public void testPickStoneFromEmptyTable() {
Stone targetStone = new Stone(BLACK);
testTable.pickUpStone(targetStone);
assertEquals(0, testTable.getSize());
}
@Test
+ public void testPickNonexistentStone() {
+ Stone targetStone = new Stone(BLACK);
+ Stone droppedStone = new Stone(RED);
+ StoneSet set = new StoneSet(droppedStone);
+ testTable.drop(set, new Position(0, 0));
+ testTable.pickUpStone(targetStone);
+ assertEquals(1, testTable.getSize());
+ assertSame(testTable.findStoneSet(droppedStone), set);
+ }
+
+ @Test
@SuppressWarnings("unused")
public void testPickUpStoneRun() {
Stone targetStone = new Stone(BLACK);