diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-05-09 00:33:30 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-05-09 00:33:30 +0200 |
commit | b57a2d5090cc1c6460b1ce806713964af9ec60f4 (patch) | |
tree | b49485a5746ce8f09fb20ac282f847864b08b83c | |
parent | ec2936a034c845d2c1e561ee1bc1860be0964933 (diff) | |
download | JRummikub-b57a2d5090cc1c6460b1ce806713964af9ec60f4.tar JRummikub-b57a2d5090cc1c6460b1ce806713964af9ec60f4.zip |
Allow calling pickUpStone for nonexistant stones
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@178 72836036-5685-4462-b002-a69064685172
-rw-r--r-- | src/jrummikub/model/Table.java | 4 | ||||
-rw-r--r-- | test/jrummikub/model/TableTest.java | 24 |
2 files changed, 19 insertions, 9 deletions
diff --git a/src/jrummikub/model/Table.java b/src/jrummikub/model/Table.java index a763bef..7787bea 100644 --- a/src/jrummikub/model/Table.java +++ b/src/jrummikub/model/Table.java @@ -28,6 +28,10 @@ public class Table extends StoneTray<StoneSet> implements ITable { public Pair<StoneSet, StoneSet> pickUpStone(Stone stone) { StoneInfo info = findStoneInfo(stone); + if (info == null) { + return null; + } + return splitSet(info.set, info.setPosition, info.stonePosition); } diff --git a/test/jrummikub/model/TableTest.java b/test/jrummikub/model/TableTest.java index 44605e2..e113ba7 100644 --- a/test/jrummikub/model/TableTest.java +++ b/test/jrummikub/model/TableTest.java @@ -23,12 +23,11 @@ public class TableTest { @Test public void testIsValid() { testTable.drop( - new StoneSet(Arrays.asList(new Stone(RED), new Stone(BLACK), - new Stone(1, BLACK))), new Position(0, 0)); + new StoneSet(Arrays.asList(new Stone(RED), new Stone(BLACK), new Stone( + 1, BLACK))), new Position(0, 0)); testTable.drop( - new StoneSet(Arrays.asList(new Stone(1, RED), - new Stone(2, RED), new Stone(3, RED))), new Position(0, - 0)); + new StoneSet(Arrays.asList(new Stone(1, RED), new Stone(2, RED), + new Stone(3, RED))), new Position(0, 0)); assertTrue(testTable.isValid()); testTable.drop(new StoneSet(Arrays.asList(new Stone(5, RED))), @@ -46,8 +45,8 @@ public class TableTest { public void testPickUpStoneGroup() { Stone targetStone = new Stone(BLACK); testTable.drop( - new StoneSet(Arrays.asList(new Stone(RED), targetStone, - new Stone(1, BLACK))), new Position(0, 0)); + new StoneSet(Arrays.asList(new Stone(RED), targetStone, new Stone(1, + BLACK))), new Position(0, 0)); assertTrue(testTable.isValid()); testTable.pickUpStone(targetStone); assertFalse(testTable.isValid()); @@ -68,12 +67,19 @@ public class TableTest { } @Test + public void testPickNonexistentStone() { + Stone targetStone = new Stone(BLACK); + testTable.pickUpStone(targetStone); + assertEquals(0, testTable.getSize()); + } + + @Test @SuppressWarnings("unused") public void testPickUpStoneRun() { Stone targetStone = new Stone(BLACK); testTable.drop( - new StoneSet(Arrays.asList(new Stone(1, RED), targetStone, - new Stone(3, RED))), new Position(0, 0)); + new StoneSet(Arrays.asList(new Stone(1, RED), targetStone, new Stone(3, + RED))), new Position(0, 0)); assertTrue(testTable.isValid()); testTable.pickUpStone(targetStone); assertFalse(testTable.isValid()); |