2011-05-09 21:56:29 +02:00
|
|
|
package jrummikub.model;
|
|
|
|
|
2011-05-09 22:33:34 +02:00
|
|
|
import static jrummikub.model.StoneColor.*;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
2011-05-09 21:56:29 +02:00
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
2011-05-10 03:54:48 +02:00
|
|
|
/**
|
|
|
|
* Test class for {@link Hand}
|
|
|
|
*/
|
2011-05-09 21:56:29 +02:00
|
|
|
public class HandTest {
|
|
|
|
|
|
|
|
Hand hand;
|
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/** */
|
2011-05-09 21:56:29 +02:00
|
|
|
@Before
|
|
|
|
public void setUp() {
|
|
|
|
hand = new Hand();
|
|
|
|
}
|
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/** */
|
2011-05-09 21:56:29 +02:00
|
|
|
@Test
|
|
|
|
public void testSimpleDrop() {
|
|
|
|
Stone stone1 = new Stone(1, RED);
|
|
|
|
Stone stone2 = new Stone(5, RED);
|
|
|
|
Stone stone3 = new Stone(2, RED);
|
|
|
|
|
|
|
|
hand.drop(stone1, new Position(2, 0));
|
|
|
|
hand.drop(stone2, new Position(3, 0));
|
|
|
|
hand.drop(stone3, new Position(2.5f, 0));
|
|
|
|
|
|
|
|
assertEquals(new Position(1.5f, 0), hand.getPosition(stone1));
|
|
|
|
assertEquals(new Position(3.5f, 0), hand.getPosition(stone2));
|
|
|
|
assertEquals(new Position(2.5f, 0), hand.getPosition(stone3));
|
|
|
|
}
|
2011-05-09 22:33:34 +02:00
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/** */
|
2011-05-09 22:33:34 +02:00
|
|
|
@Test
|
|
|
|
public void testSingleEdgeDrop() {
|
|
|
|
Stone stone1 = new Stone(2, RED);
|
|
|
|
Stone stone2 = new Stone(4, RED);
|
|
|
|
|
|
|
|
hand.drop(stone1, new Position(0, 0));
|
|
|
|
hand.drop(stone2, new Position(0.5f, 0));
|
|
|
|
|
|
|
|
assertEquals(new Position(0, 0), hand.getPosition(stone1));
|
|
|
|
assertEquals(new Position(1, 0), hand.getPosition(stone2));
|
|
|
|
}
|
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/** */
|
2011-05-09 22:33:34 +02:00
|
|
|
@Test
|
|
|
|
public void testNearEdgeDrop() {
|
|
|
|
Stone stone1 = new Stone(2, RED);
|
|
|
|
Stone stone2 = new Stone(4, RED);
|
|
|
|
|
|
|
|
hand.drop(stone1, new Position(0.25f, 0));
|
|
|
|
hand.drop(stone2, new Position(0.5f, 0));
|
|
|
|
|
|
|
|
assertEquals(new Position(0, 0), hand.getPosition(stone1));
|
|
|
|
assertEquals(new Position(1, 0), hand.getPosition(stone2));
|
|
|
|
}
|
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/** */
|
2011-05-09 22:33:34 +02:00
|
|
|
@Test
|
|
|
|
public void testNearEdgeMiddleDrop() {
|
|
|
|
Stone stone1 = new Stone(1, RED);
|
|
|
|
Stone stone2 = new Stone(5, RED);
|
|
|
|
Stone stone3 = new Stone(2, RED);
|
|
|
|
|
|
|
|
hand.drop(stone1, new Position(0.25f, 0));
|
|
|
|
hand.drop(stone2, new Position(1.25f, 0));
|
|
|
|
hand.drop(stone3, new Position(0.5f, 0));
|
|
|
|
|
|
|
|
assertEquals(new Position(0, 0), hand.getPosition(stone1));
|
|
|
|
assertEquals(new Position(2, 0), hand.getPosition(stone2));
|
|
|
|
assertEquals(new Position(1, 0), hand.getPosition(stone3));
|
|
|
|
}
|
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/** */
|
2011-05-09 22:33:34 +02:00
|
|
|
@Test
|
|
|
|
public void testNearRightEdgeDrop() {
|
|
|
|
Stone stone1 = new Stone(2, BLUE);
|
|
|
|
Stone stone2 = new Stone(4, BLUE);
|
|
|
|
|
2011-05-09 23:28:52 +02:00
|
|
|
hand.drop(stone1, new Position(12.75f, 1));
|
|
|
|
hand.drop(stone2, new Position(12.5f, 1));
|
|
|
|
|
|
|
|
assertEquals(new Position(13, 1), hand.getPosition(stone1));
|
|
|
|
assertEquals(new Position(12, 1), hand.getPosition(stone2));
|
|
|
|
}
|
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/** */
|
2011-05-09 23:28:52 +02:00
|
|
|
@Test
|
|
|
|
public void testRightWrapDrop() {
|
|
|
|
Stone stone1 = new Stone(12, ORANGE);
|
|
|
|
Stone stone2 = new Stone(13, ORANGE);
|
|
|
|
|
|
|
|
hand.drop(stone1, new Position(13, 0));
|
2011-05-09 22:33:34 +02:00
|
|
|
hand.drop(stone2, new Position(12.5f, 0));
|
|
|
|
|
2011-05-09 23:29:01 +02:00
|
|
|
assertEquals(new Position(0, 1), hand.getPosition(stone1));
|
|
|
|
assertEquals(new Position(12.5f, 0), hand.getPosition(stone2));
|
2011-05-09 23:28:52 +02:00
|
|
|
}
|
|
|
|
|
2011-05-10 03:54:48 +02:00
|
|
|
/** */
|
2011-05-09 23:28:52 +02:00
|
|
|
@Test
|
|
|
|
public void testLeftWrapDrop() {
|
|
|
|
Stone stone1 = new Stone(1, ORANGE);
|
|
|
|
Stone stone2 = new Stone(2, ORANGE);
|
|
|
|
|
|
|
|
hand.drop(stone1, new Position(0, 1));
|
|
|
|
hand.drop(stone2, new Position(0.25f, 1));
|
|
|
|
|
2011-05-09 22:33:34 +02:00
|
|
|
assertEquals(new Position(13, 0), hand.getPosition(stone1));
|
2011-05-09 23:28:52 +02:00
|
|
|
assertEquals(new Position(0.25f, 1), hand.getPosition(stone2));
|
2011-05-09 22:33:34 +02:00
|
|
|
}
|
2011-05-09 21:56:29 +02:00
|
|
|
}
|