StoneSetTest fertig

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@42 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Ida Massow 2011-05-01 00:13:22 +02:00
parent d262d91b07
commit b8fa08c9bb
3 changed files with 100 additions and 12 deletions

View file

@ -7,6 +7,18 @@ public class Stone {
private StoneColor color;
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) {
this.value = value;
this.color = color;

View file

@ -1,6 +1,7 @@
package jrummikub.model;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import jrummikub.util.Pair;
@ -11,6 +12,82 @@ import static org.junit.Assert.*;
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
@Test(expected = AssertionError.class)
public void testSplitInvalidLow() {
@ -63,18 +140,18 @@ public class StoneSetTest {
assertSame(testSet.get(2), joinedSet.get(2));
assertSame(secondSet.get(0), joinedSet.get(3));
}
//iterator
// iterator
@Test
public void testIterator() {
StoneSet testSet = createTestSet();
int i = 0;
for(Stone stone : testSet) {
assertSame(stone,testSet.get(i));
i++;
}
assertEquals(i, testSet.size());
StoneSet testSet = createTestSet();
int i = 0;
for (Stone stone : testSet) {
assertSame(stone, testSet.get(i));
i++;
}
assertEquals(i, testSet.size());
}
}

View file

@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.List;
import jrummikub.util.Pair;
import static jrummikub.model.StoneColor.*;
import org.junit.*;
import static org.junit.Assert.*;