StoneSetTest fertig
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@42 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
d262d91b07
commit
b8fa08c9bb
3 changed files with 100 additions and 12 deletions
|
@ -7,6 +7,18 @@ public class Stone {
|
||||||
private StoneColor color;
|
private StoneColor color;
|
||||||
private final boolean joker;
|
private final boolean joker;
|
||||||
|
|
||||||
|
public Stone(StoneColor color) {
|
||||||
|
this.value = 0;
|
||||||
|
this.color = color;
|
||||||
|
this.joker = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stone(int value, StoneColor color) {
|
||||||
|
this.value = value;
|
||||||
|
this.color = color;
|
||||||
|
this.joker = false;
|
||||||
|
}
|
||||||
|
|
||||||
public Stone(int value, StoneColor color, boolean joker) {
|
public Stone(int value, StoneColor color, boolean joker) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package jrummikub.model;
|
package jrummikub.model;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
|
@ -11,6 +12,82 @@ import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class StoneSetTest {
|
public class StoneSetTest {
|
||||||
|
|
||||||
|
// Is Valid-Test
|
||||||
|
// valid
|
||||||
|
public void assertSet(boolean valid, List<Stone> stones) {
|
||||||
|
StoneSet set = new StoneSet(stones);
|
||||||
|
assertTrue(valid == set.isValid());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void doubleJoker() {
|
||||||
|
assertSet(true, Arrays.asList(new Stone(RED), new Stone(BLACK),
|
||||||
|
new Stone(1, BLACK)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void groups() {
|
||||||
|
assertSet(true, Arrays.asList(new Stone(1, RED), new Stone(1, BLACK),
|
||||||
|
new Stone(1, BLUE)));
|
||||||
|
assertSet(true, Arrays.asList(new Stone(1, RED), new Stone(1, BLACK),
|
||||||
|
new Stone(1, BLUE), new Stone(1, ORANGE)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void runs() {
|
||||||
|
assertSet(true, Arrays.asList(new Stone(1, RED), new Stone(2, RED),
|
||||||
|
new Stone(3, RED)));
|
||||||
|
assertSet(true, Arrays.asList(new Stone(4, BLUE), new Stone(5, BLUE),
|
||||||
|
new Stone(6, BLUE)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void singleJoker() {
|
||||||
|
assertSet(true, Arrays.asList(new Stone(1, RED), new Stone(1, BLACK),
|
||||||
|
new Stone(RED)));
|
||||||
|
assertSet(true, Arrays.asList(new Stone(2, RED), new Stone(3, RED),
|
||||||
|
new Stone(BLACK)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// invalid
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void outOfBounds() {
|
||||||
|
assertSet(false, Arrays.asList(new Stone(RED), new Stone(1, RED),
|
||||||
|
new Stone(2, RED)));
|
||||||
|
assertSet(false, Arrays.asList(new Stone(12, RED), new Stone(13, RED),
|
||||||
|
new Stone(RED)));
|
||||||
|
assertSet(false, Arrays.asList(new Stone(RED), new Stone(BLACK),
|
||||||
|
new Stone(1, RED), new Stone(2, RED)));
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void sameColor() {
|
||||||
|
assertSet(false, Arrays.asList(new Stone(1, RED), new Stone(1, RED),
|
||||||
|
new Stone(1, BLUE)));
|
||||||
|
assertSet(false, 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(false, Arrays.asList(new Stone(4, RED), new Stone(6, RED),
|
||||||
|
new Stone(5, RED)));
|
||||||
|
assertSet(false, Arrays.asList(new Stone(4, RED), new Stone(6, RED),
|
||||||
|
new Stone(RED)));
|
||||||
|
assertSet(false, Arrays.asList(new Stone(4, RED), new Stone(RED),
|
||||||
|
new Stone(5, RED)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void otherInvalid() {
|
||||||
|
|
||||||
|
assertSet(false, Arrays.asList(new Stone(4, RED), new Stone(5, RED),
|
||||||
|
new Stone(7, RED)));
|
||||||
|
assertSet(false, Arrays.asList(new Stone(4, RED), new Stone(5, BLUE),
|
||||||
|
new Stone(6, RED)));
|
||||||
|
assertSet(false, Arrays.asList(new Stone(4, RED), new Stone(5, RED)));
|
||||||
|
|
||||||
|
}
|
||||||
// invalid Split
|
// invalid Split
|
||||||
@Test(expected = AssertionError.class)
|
@Test(expected = AssertionError.class)
|
||||||
public void testSplitInvalidLow() {
|
public void testSplitInvalidLow() {
|
||||||
|
@ -64,14 +141,14 @@ public class StoneSetTest {
|
||||||
assertSame(secondSet.get(0), joinedSet.get(3));
|
assertSame(secondSet.get(0), joinedSet.get(3));
|
||||||
}
|
}
|
||||||
|
|
||||||
//iterator
|
// iterator
|
||||||
@Test
|
@Test
|
||||||
public void testIterator() {
|
public void testIterator() {
|
||||||
StoneSet testSet = createTestSet();
|
StoneSet testSet = createTestSet();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for(Stone stone : testSet) {
|
for (Stone stone : testSet) {
|
||||||
assertSame(stone,testSet.get(i));
|
assertSame(stone, testSet.get(i));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
import static jrummikub.model.StoneColor.*;
|
|
||||||
|
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
Reference in a new issue