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
|
// TODO Auto-generated method stub
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isInitialMeldPossible() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ package jrummikub.model;
|
||||||
*/
|
*/
|
||||||
public class MockPlayer implements IPlayer {
|
public class MockPlayer implements IPlayer {
|
||||||
/** */
|
/** */
|
||||||
public Hand hand;
|
public IHand hand;
|
||||||
/** */
|
/** */
|
||||||
public PlayerSettings playerSettings;
|
public PlayerSettings playerSettings;
|
||||||
/** */
|
/** */
|
||||||
|
|
|
@ -74,4 +74,10 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
||||||
|
|
||||||
return points;
|
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
|
* @return points
|
||||||
*/
|
*/
|
||||||
int getStonePoints();
|
int getStonePoints();
|
||||||
|
|
||||||
|
public abstract boolean isInitialMeldPossible();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
package jrummikub.model;
|
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.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -14,7 +19,7 @@ import org.junit.Test;
|
||||||
*/
|
*/
|
||||||
public class HandTest {
|
public class HandTest {
|
||||||
|
|
||||||
Hand hand;
|
IHand hand;
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
@Before
|
@Before
|
||||||
|
@ -126,4 +131,112 @@ public class HandTest {
|
||||||
|
|
||||||
assertEquals(56, hand.getStonePoints());
|
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