Allow calling pickUpStone for nonexistant stones
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@178 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
ec2936a034
commit
b57a2d5090
2 changed files with 19 additions and 9 deletions
|
@ -28,6 +28,10 @@ public class Table extends StoneTray<StoneSet> implements ITable {
|
||||||
public Pair<StoneSet, StoneSet> pickUpStone(Stone stone) {
|
public Pair<StoneSet, StoneSet> pickUpStone(Stone stone) {
|
||||||
StoneInfo info = findStoneInfo(stone);
|
StoneInfo info = findStoneInfo(stone);
|
||||||
|
|
||||||
|
if (info == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return splitSet(info.set, info.setPosition, info.stonePosition);
|
return splitSet(info.set, info.setPosition, info.stonePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,12 +23,11 @@ public class TableTest {
|
||||||
@Test
|
@Test
|
||||||
public void testIsValid() {
|
public void testIsValid() {
|
||||||
testTable.drop(
|
testTable.drop(
|
||||||
new StoneSet(Arrays.asList(new Stone(RED), new Stone(BLACK),
|
new StoneSet(Arrays.asList(new Stone(RED), new Stone(BLACK), new Stone(
|
||||||
new Stone(1, BLACK))), new Position(0, 0));
|
1, BLACK))), new Position(0, 0));
|
||||||
testTable.drop(
|
testTable.drop(
|
||||||
new StoneSet(Arrays.asList(new Stone(1, RED),
|
new StoneSet(Arrays.asList(new Stone(1, RED), new Stone(2, RED),
|
||||||
new Stone(2, RED), new Stone(3, RED))), new Position(0,
|
new Stone(3, RED))), new Position(0, 0));
|
||||||
0));
|
|
||||||
assertTrue(testTable.isValid());
|
assertTrue(testTable.isValid());
|
||||||
|
|
||||||
testTable.drop(new StoneSet(Arrays.asList(new Stone(5, RED))),
|
testTable.drop(new StoneSet(Arrays.asList(new Stone(5, RED))),
|
||||||
|
@ -46,8 +45,8 @@ public class TableTest {
|
||||||
public void testPickUpStoneGroup() {
|
public void testPickUpStoneGroup() {
|
||||||
Stone targetStone = new Stone(BLACK);
|
Stone targetStone = new Stone(BLACK);
|
||||||
testTable.drop(
|
testTable.drop(
|
||||||
new StoneSet(Arrays.asList(new Stone(RED), targetStone,
|
new StoneSet(Arrays.asList(new Stone(RED), targetStone, new Stone(1,
|
||||||
new Stone(1, BLACK))), new Position(0, 0));
|
BLACK))), new Position(0, 0));
|
||||||
assertTrue(testTable.isValid());
|
assertTrue(testTable.isValid());
|
||||||
testTable.pickUpStone(targetStone);
|
testTable.pickUpStone(targetStone);
|
||||||
assertFalse(testTable.isValid());
|
assertFalse(testTable.isValid());
|
||||||
|
@ -67,13 +66,20 @@ public class TableTest {
|
||||||
assertEquals(0, testTable.getSize());
|
assertEquals(0, testTable.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPickNonexistentStone() {
|
||||||
|
Stone targetStone = new Stone(BLACK);
|
||||||
|
testTable.pickUpStone(targetStone);
|
||||||
|
assertEquals(0, testTable.getSize());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public void testPickUpStoneRun() {
|
public void testPickUpStoneRun() {
|
||||||
Stone targetStone = new Stone(BLACK);
|
Stone targetStone = new Stone(BLACK);
|
||||||
testTable.drop(
|
testTable.drop(
|
||||||
new StoneSet(Arrays.asList(new Stone(1, RED), targetStone,
|
new StoneSet(Arrays.asList(new Stone(1, RED), targetStone, new Stone(3,
|
||||||
new Stone(3, RED))), new Position(0, 0));
|
RED))), new Position(0, 0));
|
||||||
assertTrue(testTable.isValid());
|
assertTrue(testTable.isValid());
|
||||||
testTable.pickUpStone(targetStone);
|
testTable.pickUpStone(targetStone);
|
||||||
assertFalse(testTable.isValid());
|
assertFalse(testTable.isValid());
|
||||||
|
|
Reference in a new issue