summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jrummikub/model/StoneTray.java14
-rw-r--r--test/jrummikub/model/PositionTest.java29
-rw-r--r--test/jrummikub/model/StoneSetTest.java65
3 files changed, 67 insertions, 41 deletions
diff --git a/src/jrummikub/model/StoneTray.java b/src/jrummikub/model/StoneTray.java
index 6b54e3e..16ffa46 100644
--- a/src/jrummikub/model/StoneTray.java
+++ b/src/jrummikub/model/StoneTray.java
@@ -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
diff --git a/test/jrummikub/model/PositionTest.java b/test/jrummikub/model/PositionTest.java
new file mode 100644
index 0000000..2812f9c
--- /dev/null
+++ b/test/jrummikub/model/PositionTest.java
@@ -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));
+ }
+
+}
diff --git a/test/jrummikub/model/StoneSetTest.java b/test/jrummikub/model/StoneSetTest.java
index e7998e4..b98d3d8 100644
--- a/test/jrummikub/model/StoneSetTest.java
+++ b/test/jrummikub/model/StoneSetTest.java
@@ -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());
+ }
}