Added toString and equals tests
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@210 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
9c056cfef7
commit
b14a707d4f
3 changed files with 67 additions and 41 deletions
|
@ -20,20 +20,6 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
|
||||
protected static enum Direction {
|
||||
LEFT, RIGHT, TOP, BOTTOM;
|
||||
|
||||
public Direction reverse() {
|
||||
switch (this) {
|
||||
case LEFT:
|
||||
return RIGHT;
|
||||
case RIGHT:
|
||||
return LEFT;
|
||||
case TOP:
|
||||
return BOTTOM;
|
||||
case BOTTOM:
|
||||
return TOP;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
29
test/jrummikub/model/PositionTest.java
Normal file
29
test/jrummikub/model/PositionTest.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package jrummikub.model;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class PositionTest {
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
Position pos = new Position(6, 2);
|
||||
assertEquals("Position[x=6.0,y=2.0]", pos.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsAndHashCode() {
|
||||
Position pos1 = new Position(0, 0);
|
||||
Position pos2 = new Position(0, 0);
|
||||
Position pos3 = new Position(0, 1);
|
||||
Set<Position> set = new HashSet<Position>();
|
||||
set.add(pos1);
|
||||
assertTrue(set.contains(pos1));
|
||||
assertTrue(set.contains(pos2));
|
||||
assertFalse(set.contains(pos3));
|
||||
}
|
||||
|
||||
}
|
|
@ -22,8 +22,8 @@ public class StoneSetTest {
|
|||
|
||||
@Test
|
||||
public void doubleJoker() {
|
||||
assertSet(GROUP, Arrays.asList(new Stone(RED), new Stone(BLACK),
|
||||
new Stone(1, BLACK)));
|
||||
assertSet(GROUP,
|
||||
Arrays.asList(new Stone(RED), new Stone(BLACK), new Stone(1, BLACK)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -36,62 +36,63 @@ public class StoneSetTest {
|
|||
|
||||
@Test
|
||||
public void runs() {
|
||||
assertSet(RUN, Arrays.asList(new Stone(1, RED), new Stone(2, RED),
|
||||
new Stone(3, RED)));
|
||||
assertSet(RUN,
|
||||
Arrays.asList(new Stone(1, RED), new Stone(2, RED), new Stone(3, RED)));
|
||||
assertSet(RUN, Arrays.asList(new Stone(4, BLUE), new Stone(5, BLUE),
|
||||
new Stone(6, BLUE)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleJoker() {
|
||||
assertSet(GROUP, Arrays.asList(new Stone(1, RED), new Stone(1, BLACK),
|
||||
new Stone(RED)));
|
||||
assertSet(RUN, Arrays.asList(new Stone(2, RED), new Stone(3, RED),
|
||||
new Stone(BLACK)));
|
||||
assertSet(GROUP,
|
||||
Arrays.asList(new Stone(1, RED), new Stone(1, BLACK), new Stone(RED)));
|
||||
assertSet(RUN,
|
||||
Arrays.asList(new Stone(2, RED), new Stone(3, RED), new Stone(BLACK)));
|
||||
}
|
||||
|
||||
// invalid
|
||||
|
||||
@Test
|
||||
public void outOfBounds() {
|
||||
assertSet(INVALID, Arrays.asList(new Stone(RED), new Stone(1, RED),
|
||||
new Stone(2, RED)));
|
||||
assertSet(INVALID, Arrays.asList(new Stone(12, RED), new Stone(13, RED),
|
||||
new Stone(RED)));
|
||||
assertSet(INVALID,
|
||||
Arrays.asList(new Stone(RED), new Stone(1, RED), new Stone(2, RED)));
|
||||
assertSet(INVALID,
|
||||
Arrays.asList(new Stone(12, RED), new Stone(13, RED), new Stone(RED)));
|
||||
assertSet(INVALID, Arrays.asList(new Stone(RED), new Stone(BLACK),
|
||||
new Stone(1, RED), new Stone(2, RED)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameColor() {
|
||||
assertSet(INVALID, Arrays.asList(new Stone(1, RED), new Stone(1, RED),
|
||||
new Stone(1, BLUE)));
|
||||
assertSet(INVALID,
|
||||
Arrays.asList(new Stone(1, RED), new Stone(1, RED), new Stone(1, BLUE)));
|
||||
assertSet(INVALID, Arrays.asList(new Stone(1, RED), new Stone(1, BLUE),
|
||||
new Stone(1, BLACK), new Stone(1, ORANGE), new Stone(RED)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void incorrectOrder() {
|
||||
assertSet(INVALID, Arrays.asList(new Stone(4, RED), new Stone(6, RED),
|
||||
new Stone(5, RED)));
|
||||
assertSet(INVALID, Arrays.asList(new Stone(4, RED), new Stone(6, RED),
|
||||
new Stone(RED)));
|
||||
assertSet(INVALID, Arrays.asList(new Stone(4, RED), new Stone(RED),
|
||||
new Stone(5, RED)));
|
||||
assertSet(INVALID,
|
||||
Arrays.asList(new Stone(4, RED), new Stone(6, RED), new Stone(5, RED)));
|
||||
assertSet(INVALID,
|
||||
Arrays.asList(new Stone(4, RED), new Stone(6, RED), new Stone(RED)));
|
||||
assertSet(INVALID,
|
||||
Arrays.asList(new Stone(4, RED), new Stone(RED), new Stone(5, RED)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void otherInvalid() {
|
||||
|
||||
assertSet(INVALID, Arrays.asList(new Stone(4, RED), new Stone(5, RED),
|
||||
new Stone(7, RED)));
|
||||
assertSet(INVALID, Arrays.asList(new Stone(4, RED), new Stone(5, BLUE),
|
||||
new Stone(6, RED)));
|
||||
assertSet(INVALID,
|
||||
Arrays.asList(new Stone(4, RED), new Stone(5, RED), new Stone(7, RED)));
|
||||
assertSet(INVALID,
|
||||
Arrays.asList(new Stone(4, RED), new Stone(5, BLUE), new Stone(6, RED)));
|
||||
assertSet(INVALID, Arrays.asList(new Stone(4, RED), new Stone(5, RED)));
|
||||
assertSet(INVALID, Arrays.asList(new Stone(4, BLUE), new Stone(5, RED),
|
||||
new Stone(6, RED)));
|
||||
assertSet(INVALID,
|
||||
Arrays.asList(new Stone(4, BLUE), new Stone(5, RED), new Stone(6, RED)));
|
||||
// Regression test:
|
||||
assertSet(INVALID, Arrays.asList(new Stone(12, ORANGE), new Stone(12, BLACK), new Stone(7, BLUE)));
|
||||
assertSet(INVALID, Arrays.asList(new Stone(12, ORANGE),
|
||||
new Stone(12, BLACK), new Stone(7, BLUE)));
|
||||
}
|
||||
|
||||
// invalid Split
|
||||
|
@ -159,4 +160,14 @@ public class StoneSetTest {
|
|||
|
||||
assertEquals(i, testSet.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
StoneSet testSet = new StoneSet(Arrays.asList(new Stone(2, BLUE),
|
||||
new Stone(3, BLUE), new Stone(4, BLUE)));
|
||||
|
||||
assertEquals(
|
||||
"StoneSet[Stone[value=2,color=BLUE],Stone[value=3,color=BLUE],Stone[value=4,color=BLUE]]",
|
||||
testSet.toString());
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue