This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
JRummikub/test/jrummikub/model/TableTest.java
Matthias Schiffer b57a2d5090 Allow calling pickUpStone for nonexistant stones
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@178 72836036-5685-4462-b002-a69064685172
2011-05-09 00:33:30 +02:00

104 lines
2.6 KiB
Java

package jrummikub.model;
import static jrummikub.model.StoneColor.BLACK;
import static jrummikub.model.StoneColor.RED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
public class TableTest {
Table testTable;
@Before
public void setup() {
testTable = new Table();
}
@Test
public void testIsValid() {
testTable.drop(
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));
assertTrue(testTable.isValid());
testTable.drop(new StoneSet(Arrays.asList(new Stone(5, RED))),
new Position(0, 0));
assertFalse(testTable.isValid());
}
@Test
public void testEmptyIsValid() {
assertTrue(testTable.isValid());
}
@Test
@SuppressWarnings("unused")
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));
assertTrue(testTable.isValid());
testTable.pickUpStone(targetStone);
assertFalse(testTable.isValid());
int counter = 0;
for (Object i : testTable) {
counter++;
}
assertEquals(1, counter);
}
@Test
public void testPickLonelyStone() {
Stone targetStone = new Stone(BLACK);
testTable.drop(new StoneSet(targetStone), new Position(0, 0));
testTable.pickUpStone(targetStone);
assertEquals(0, testTable.getSize());
}
@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));
assertTrue(testTable.isValid());
testTable.pickUpStone(targetStone);
assertFalse(testTable.isValid());
int counter = 0;
for (Object i : testTable) {
counter++;
}
assertEquals(2, counter);
}
@Test
public void testFindSet() {
Stone targetStone = new Stone(BLACK);
StoneSet testSet = new StoneSet(Arrays.asList(new Stone(1, RED),
targetStone, new Stone(3, RED)));
testTable.drop(testSet, new Position(0, 0));
StoneSet foundSet = testTable.findStoneSet(targetStone);
assertSame(testSet, foundSet);
}
}