Test if initial melds are possible
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@265 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
4a98975b0d
commit
d5a8b2204c
5 changed files with 131 additions and 6 deletions
|
@ -82,4 +82,8 @@ public class MockHand implements IHand {
|
|||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isInitialMeldPossible() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ package jrummikub.model;
|
|||
*/
|
||||
public class MockPlayer implements IPlayer {
|
||||
/** */
|
||||
public Hand hand;
|
||||
public IHand hand;
|
||||
/** */
|
||||
public PlayerSettings playerSettings;
|
||||
/** */
|
||||
|
|
|
@ -74,4 +74,10 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
|||
|
||||
return points;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialMeldPossible() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,4 +27,6 @@ public interface IHand extends IStoneTray<Stone> {
|
|||
* @return points
|
||||
*/
|
||||
int getStonePoints();
|
||||
|
||||
public abstract boolean isInitialMeldPossible();
|
||||
}
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package jrummikub.model;
|
||||
|
||||
import static jrummikub.model.StoneColor.*;
|
||||
import static jrummikub.model.StoneColor.BLACK;
|
||||
import static jrummikub.model.StoneColor.BLUE;
|
||||
import static jrummikub.model.StoneColor.ORANGE;
|
||||
import static jrummikub.model.StoneColor.RED;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
|
@ -14,7 +19,7 @@ import org.junit.Test;
|
|||
*/
|
||||
public class HandTest {
|
||||
|
||||
Hand hand;
|
||||
IHand hand;
|
||||
|
||||
/** */
|
||||
@Before
|
||||
|
@ -104,14 +109,14 @@ public class HandTest {
|
|||
}
|
||||
Stone newStone = new Stone(RED);
|
||||
hand.drop(newStone, new Position(12.5f, 1));
|
||||
|
||||
|
||||
for (int i = 0; i < 13; i++) {
|
||||
assertEquals(new Position(i, 1), hand.getPosition(rowStones.get(i)));
|
||||
}
|
||||
assertEquals(new Position(13, 1), hand.getPosition(newStone));
|
||||
assertEquals(new Position(0, 2), hand.getPosition(rowStones.get(13)));
|
||||
}
|
||||
|
||||
|
||||
/** */
|
||||
@Test
|
||||
public void testCountPoints() {
|
||||
|
@ -123,7 +128,115 @@ public class HandTest {
|
|||
hand.drop(stone1, new Position(0, 0));
|
||||
hand.drop(stone2, new Position(0, 0));
|
||||
hand.drop(stone3, new Position(0, 0));
|
||||
|
||||
|
||||
assertEquals(56, hand.getStonePoints());
|
||||
}
|
||||
|
||||
private void testInitialMeld(boolean possible, List<Stone> handStones) {
|
||||
for (Stone stone : handStones) {
|
||||
hand.drop(stone, new Position(0, 0));
|
||||
}
|
||||
assertTrue(possible == hand.isInitialMeldPossible());
|
||||
}
|
||||
|
||||
/** */
|
||||
@Test
|
||||
public void testNoValid() {
|
||||
testInitialMeld(false, Arrays.asList(new Stone(8, RED), new Stone(9,
|
||||
RED), new Stone(10, RED), new Stone(12, RED),
|
||||
new Stone(13, RED)));
|
||||
testInitialMeld(false, Arrays.asList(new Stone(10, RED), new Stone(10,
|
||||
BLACK), new Stone(11, RED), new Stone(11, BLACK)));
|
||||
testInitialMeld(false, Arrays.asList(new Stone(10, RED), new Stone(10,
|
||||
RED), new Stone(10, BLACK), new Stone(11, RED), new Stone(11,
|
||||
BLACK)));
|
||||
|
||||
testInitialMeld(false, Arrays.asList(new Stone(10, RED), new Stone(11,
|
||||
BLACK), new Stone(12, RED)));
|
||||
}
|
||||
|
||||
/** */
|
||||
@Test
|
||||
public void testNotEnoughPoints() {
|
||||
testInitialMeld(false, Arrays.asList(new Stone(8, RED), new Stone(9,
|
||||
RED), new Stone(10, RED)));
|
||||
testInitialMeld(false, Arrays.asList(new Stone(1, RED), new Stone(2,
|
||||
RED), new Stone(3, RED), new Stone(4, RED)));
|
||||
testInitialMeld(false, Arrays.asList(new Stone(1, RED), new Stone(2,
|
||||
RED), new Stone(3, RED), new Stone(1, BLACK), new Stone(2,
|
||||
BLACK), new Stone(3, BLACK)));
|
||||
}
|
||||
|
||||
/** */
|
||||
@Test
|
||||
public void testNotEnoughPointsWithJoker() {
|
||||
testInitialMeld(false, Arrays.asList(new Stone(8, RED), new Stone(9,
|
||||
RED), new Stone(RED), new Stone(3, BLACK)));
|
||||
testInitialMeld(false, Arrays.asList(new Stone(4, RED), new Stone(5,
|
||||
RED), new Stone(4, BLACK), new Stone(5, BLACK), new Stone(RED)));
|
||||
}
|
||||
|
||||
/** */
|
||||
@Test
|
||||
public void testNotEnoughPointsWithTwoJokers() {
|
||||
testInitialMeld(false, Arrays.asList(new Stone(1, RED), new Stone(2,
|
||||
BLUE), new Stone(3, BLACK), new Stone(RED), new Stone(BLACK)));
|
||||
testInitialMeld(false, Arrays.asList(new Stone(8, RED), new Stone(RED),
|
||||
new Stone(BLACK)));
|
||||
}
|
||||
|
||||
/** */
|
||||
@Test
|
||||
public void testValid() {
|
||||
testInitialMeld(true, Arrays.asList(new Stone(11, RED), new Stone(12,
|
||||
RED), new Stone(13, RED)));
|
||||
testInitialMeld(true, Arrays.asList(new Stone(4, RED),
|
||||
new Stone(5, RED), new Stone(6, RED), new Stone(5, ORANGE),
|
||||
new Stone(5, BLACK), new Stone(5, BLUE)));
|
||||
testInitialMeld(true, Arrays.asList(new Stone(10, RED), new Stone(10,
|
||||
BLACK), new Stone(10, ORANGE)));
|
||||
}
|
||||
|
||||
/** */
|
||||
@Test
|
||||
public void testValidWithJoker() {
|
||||
testInitialMeld(true, Arrays.asList(new Stone(11, RED), new Stone(RED),
|
||||
new Stone(13, RED)));
|
||||
testInitialMeld(true, Arrays.asList(new Stone(10, RED),
|
||||
new Stone(BLACK), new Stone(10, ORANGE)));
|
||||
testInitialMeld(true, Arrays.asList(new Stone(4, RED),
|
||||
new Stone(5, RED), new Stone(6, RED), new Stone(5, BLACK),
|
||||
new Stone(5, BLUE), new Stone(RED)));
|
||||
}
|
||||
|
||||
/** */
|
||||
@Test
|
||||
public void testValidWithTwoJokers() {
|
||||
testInitialMeld(true, Arrays.asList(new Stone(9, RED), new Stone(RED),
|
||||
new Stone(BLACK)));
|
||||
}
|
||||
|
||||
/** */
|
||||
@Test
|
||||
public void testValidHuge() {
|
||||
List<Stone> stones = new ArrayList<Stone>();
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
stones.add(new Stone(i, RED));
|
||||
stones.add(new Stone(i, BLACK));
|
||||
}
|
||||
testInitialMeld(true, stones);
|
||||
}
|
||||
|
||||
/** */
|
||||
@Test
|
||||
public void testInvalidHuge() {
|
||||
testInitialMeld(false, Arrays.asList(new Stone(1, RED), new Stone(2,
|
||||
RED), new Stone(4, RED), new Stone(6, RED), new Stone(8, RED),
|
||||
new Stone(10, RED), new Stone(13, RED), new Stone(1, BLACK),
|
||||
new Stone(2, BLACK), new Stone(4, BLACK), new Stone(5, BLACK),
|
||||
new Stone(8, BLACK), new Stone(9, BLACK), new Stone(12, BLACK),
|
||||
new Stone(3, BLUE), new Stone(5, BLUE), new Stone(7, BLUE),
|
||||
new Stone(11, BLUE), new Stone(RED)));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue