summaryrefslogtreecommitdiffstats
path: root/test/jrummikub
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-05-18 17:07:50 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-05-18 17:07:50 +0200
commit39d3c143b202126faa14509aae132597c469f93d (patch)
tree4ca67e3a479208f1c99e692aefda310acf3d524a /test/jrummikub
parente76977652d55463b98f847ce261926f0d9d7c0de (diff)
downloadJRummikub-39d3c143b202126faa14509aae132597c469f93d.tar
JRummikub-39d3c143b202126faa14509aae132597c469f93d.zip
Ein von fünf Tests fertig für laidOut
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@254 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'test/jrummikub')
-rw-r--r--test/jrummikub/control/RoundControlTest.java251
1 files changed, 196 insertions, 55 deletions
diff --git a/test/jrummikub/control/RoundControlTest.java b/test/jrummikub/control/RoundControlTest.java
index 4cfb03f..735c631 100644
--- a/test/jrummikub/control/RoundControlTest.java
+++ b/test/jrummikub/control/RoundControlTest.java
@@ -11,6 +11,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
@@ -23,6 +24,7 @@ import jrummikub.model.ITable;
import jrummikub.model.MockRoundState;
import jrummikub.model.MockTable;
import jrummikub.model.Position;
+import jrummikub.model.RoundState;
import jrummikub.model.Stone;
import jrummikub.model.StoneSet;
import jrummikub.model.Table;
@@ -37,9 +39,9 @@ import org.junit.Test;
*/
public class RoundControlTest {
private MockView view;
- private MockRoundState testGameState;
+ private MockRoundState testRoundState;
private RoundControl testRound;
- private MockTable newTable;
+ private MockTable testTable;
/**
* For each test create a round control initialized by a mock model and view
@@ -47,20 +49,22 @@ public class RoundControlTest {
@Before
public void setup() {
view = new MockView();
- testGameState = new MockRoundState();
- testRound = new RoundControl(testGameState, view);
- Stone stone = testGameState.getGameHeap().drawStone();
- testGameState.table.drop(new StoneSet(stone), new Position(5, 0));
- newTable = new MockTable();
- newTable.sets.add(testGameState.table.sets.get(0));
- testGameState.table.clonedTable = newTable;
+ testRoundState = new MockRoundState();
+ testRound = new RoundControl(testRoundState, view);
+ Stone stone = testRoundState.getGameHeap().drawStone();
+ testRoundState.table.drop(new StoneSet(stone), new Position(5, 0));
+ testTable = new MockTable();
+ testTable.sets.add(testRoundState.table.sets.get(0));
+ testRoundState.table.clonedTable = testTable;
}
private void checkCorrectlyDealed() {
- assertEquals(106 - testGameState.getPlayerCount() * 14
- - testGameState.table.getSize(), testGameState.getGameHeap().getSize());
- for (int i = 0; i < testGameState.getPlayerCount(); i++) {
- assertEquals(14, testGameState.getNthNextPlayer(i).getHand().getSize());
+ assertEquals(106 - testRoundState.getPlayerCount() * 14
+ - testRoundState.table.getSize(), testRoundState.getGameHeap()
+ .getSize());
+ for (int i = 0; i < testRoundState.getPlayerCount(); i++) {
+ assertEquals(14, testRoundState.getNthNextPlayer(i).getHand()
+ .getSize());
}
}
@@ -78,7 +82,7 @@ public class RoundControlTest {
private void checkTableDisplay() {
Iterator<Pair<StoneSet, Position>> stoneSetsView = view.tablePanel.stoneSets
.iterator();
- Iterator<Pair<StoneSet, Position>> stoneSetsModel = testGameState.table
+ Iterator<Pair<StoneSet, Position>> stoneSetsModel = testRoundState.table
.clone().sets.iterator();
while (stoneSetsView.hasNext()) {
@@ -96,15 +100,149 @@ public class RoundControlTest {
view.displayStartTurnPanel = false;
}
+ // laidOut test cases
/** */
@Test
- public void playerCameOutCorrectly() {
- MockTable oldTable = new MockTable();
- MockTable newTable = new MockTable();
- Stone blueTen = new Stone(10, BLUE);
+ public void laidOutValidTooFew() {
+ Stone blueOne = new Stone(1, BLUE);
+ Stone blueTwo = new Stone(2, BLUE);
+ Stone blueThree = new Stone(3, BLUE);
+
+ RoundState roundState = new RoundState();
+ RoundControl roundControl = new RoundControl(roundState, view);
+
+ IHand hand = roundState.getActivePlayer().getHand();
+ hand.drop(blueOne, new Position(0, 0));
+ hand.drop(blueTwo, new Position(0, 0));
+ hand.drop(blueThree, new Position(0, 0));
+
+ assertFalse(roundState.getActivePlayer().getLaidOut());
+
+ hand.pickUp(blueOne);
+ hand.pickUp(blueTwo);
+ hand.pickUp(blueThree);
+
+ roundState.getTable().drop(
+ new StoneSet(Arrays.asList(blueOne, blueTwo, blueThree)),
+ new Position(0, 0));
+
+ }
+
+ /** */
+ @Test
+ public void laidOutInvalidEnough() {
+ Stone blueOne = new Stone(1, BLUE);
+ Stone blueTwo = new Stone(2, BLUE);
+ Stone blueThree = new Stone(3, BLUE);
+
+ Stone redEight = new Stone(8, RED);
+ Stone redNine = new Stone(9, RED);
Stone redTen = new Stone(10, RED);
- Stone blackTen = new Stone(10, BLACK);
+ Stone orangeOne = new Stone(1, ORANGE);
+
+ RoundState roundState = new RoundState();
+ RoundControl roundControl = new RoundControl(roundState, view);
+
+ IHand hand = roundState.getActivePlayer().getHand();
+ hand.drop(blueOne, new Position(0, 0));
+ hand.drop(blueTwo, new Position(0, 0));
+ hand.drop(blueThree, new Position(0, 0));
+
+ hand.drop(redEight, new Position(0, 0));
+ hand.drop(redNine, new Position(0, 0));
+ hand.drop(redTen, new Position(0, 0));
+
+ hand.drop(orangeOne, new Position(0, 0));
+ }
+
+ /** */
+ @Test
+ public void laidOutEnoughChangedTable() {
+ Stone redEight = new Stone(8, RED);
+ Stone redNine = new Stone(9, RED);
+ Stone redTen = new Stone(10, RED);
+
+ Stone blueSeven = new Stone(7, BLUE);
+ Stone blackSeven = new Stone(7, BLACK);
+ Stone redSeven = new Stone(7, RED);
+ Stone orangeSeven = new Stone(7, ORANGE);
+
+ StoneSet sevenSet = new StoneSet(Arrays.asList(blueSeven, blackSeven,
+ redSeven, orangeSeven));
+
+ RoundState roundState = new RoundState();
+ RoundControl roundControl = new RoundControl(roundState, view);
+
+ }
+
+ /** */
+ @Test
+ public void laidOutTooFewChangedTable() {
+ Stone redEight = new Stone(8, RED);
+ Stone redNine = new Stone(9, RED);
+ Stone redTen = new Stone(10, RED);
+ Stone redEleven = new Stone(11, RED);
+
+ Stone blueSeven = new Stone(7, BLUE);
+ Stone blackSeven = new Stone(7, BLACK);
+ Stone redSeven = new Stone(7, RED);
+ Stone orangeSeven = new Stone(7, ORANGE);
+
+ StoneSet sevenSet = new StoneSet(Arrays.asList(blueSeven, blackSeven,
+ redSeven, orangeSeven));
+
+ RoundState roundState = new RoundState();
+ RoundControl roundControl = new RoundControl(roundState, view);
+
+ }
+
+ /** */
+ @Test
+ public void laidOutValid() {
+
+ Stone blueOne = new Stone(1, BLUE);
+ Stone blueTwo = new Stone(2, BLUE);
+ Stone blueThree = new Stone(3, BLUE);
+
+ Stone redEight = new Stone(8, RED);
+ Stone redNine = new Stone(9, RED);
+ Stone redTen = new Stone(10, RED);
+
+ RoundState roundState = new RoundState();
+ RoundControl roundControl = new RoundControl(roundState, view);
+
+ IHand hand = roundState.getActivePlayer().getHand();
+ hand.drop(blueOne, new Position(0, 0));
+ hand.drop(blueTwo, new Position(0, 0));
+ hand.drop(blueThree, new Position(0, 0));
+
+ hand.drop(redEight, new Position(0, 0));
+ hand.drop(redNine, new Position(0, 0));
+ hand.drop(redTen, new Position(0, 0));
+
+ assertFalse(roundState.getActivePlayer().getLaidOut());
+
+ hand.pickUp(blueOne);
+ hand.pickUp(blueTwo);
+ hand.pickUp(blueThree);
+
+ roundState.getTable().drop(
+ new StoneSet(Arrays.asList(blueOne, blueTwo, blueThree)),
+ new Position(0, 0));
+
+ hand.pickUp(redEight);
+ hand.pickUp(redNine);
+ hand.pickUp(redTen);
+
+ roundState.getTable().drop(
+ new StoneSet(Arrays.asList(redEight, redNine, redTen)),
+ new Position(0, 0));
+
+ view.playerPanel.endTurnEvent.emit();
+
+ assertTrue(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1)
+ .getLaidOut());
}
/** */
@@ -115,7 +253,7 @@ public class RoundControlTest {
for (int i = 0; i < 14; i++) {
testRound.dealStones(2);
}
- assertEquals(2 * 14 + 14, testGameState.getActivePlayer().getHand()
+ assertEquals(2 * 14 + 14, testRoundState.getActivePlayer().getHand()
.getSize());
}
@@ -149,20 +287,20 @@ public class RoundControlTest {
@Test
public void testTableValidHandChanged() {
testRound.startRound();
- MockTable oldTable = testGameState.table;
- newTable.valid = true;
- oldTable.clonedTable = newTable;
+ MockTable oldTable = testRoundState.table;
+ testTable.valid = true;
+ oldTable.clonedTable = testTable;
view.startTurnEvent.emit();
assertFalse(view.displayStartTurnPanel);
- IHand hand = testGameState.players.get(0).hand;
+ IHand hand = testRoundState.players.get(0).hand;
hand.pickUp(hand.iterator().next().getFirst());
resetTurnStart();
view.getPlayerPanel().endTurnEvent.emit();
- assertSame(newTable, testGameState.setTable);
- assertEquals(1, testGameState.activePlayer);
+ assertSame(testTable, testRoundState.setTable);
+ assertEquals(1, testRoundState.activePlayer);
checkTurnStartSetUp();
}
@@ -171,22 +309,22 @@ public class RoundControlTest {
@Test
public void testTableInvalidHandChanged() {
testRound.startRound();
- MockTable oldTable = testGameState.table;
- newTable.valid = false;
- oldTable.clonedTable = newTable;
+ MockTable oldTable = testRoundState.table;
+ testTable.valid = false;
+ oldTable.clonedTable = testTable;
view.startTurnEvent.emit();
assertFalse(view.displayStartTurnPanel);
- IHand hand = testGameState.players.get(0).hand;
+ IHand hand = testRoundState.players.get(0).hand;
Stone stone = hand.iterator().next().getFirst();
hand.pickUp(stone);
- newTable.drop(new StoneSet(stone), new Position(0, 0));
+ testTable.drop(new StoneSet(stone), new Position(0, 0));
resetTurnStart();
view.getPlayerPanel().endTurnEvent.emit();
- assertNull(testGameState.setTable);
- assertEquals(1, testGameState.activePlayer);
- assertEquals(14 + 3, testGameState.players.get(0).hand.getSize());
+ assertNull(testRoundState.setTable);
+ assertEquals(1, testRoundState.activePlayer);
+ assertEquals(14 + 3, testRoundState.players.get(0).hand.getSize());
checkTurnStartSetUp();
}
@@ -194,18 +332,18 @@ public class RoundControlTest {
@Test
public void testTableValidHandUnchanged() {
testRound.startRound();
- MockTable oldTable = testGameState.table;
- newTable.valid = true;
- oldTable.clonedTable = newTable;
+ MockTable oldTable = testRoundState.table;
+ testTable.valid = true;
+ oldTable.clonedTable = testTable;
view.startTurnEvent.emit();
assertFalse(view.displayStartTurnPanel);
resetTurnStart();
view.getPlayerPanel().endTurnEvent.emit();
- assertSame(newTable, testGameState.setTable);
- assertEquals(14 + 1, testGameState.players.get(0).hand.getSize());
- assertEquals(1, testGameState.activePlayer);
+ assertSame(testTable, testRoundState.setTable);
+ assertEquals(14 + 1, testRoundState.players.get(0).hand.getSize());
+ assertEquals(1, testRoundState.activePlayer);
checkTurnStartSetUp();
}
@@ -214,18 +352,18 @@ public class RoundControlTest {
@Test
public void testTableInvalidHandUnchanged() {
testRound.startRound();
- MockTable oldTable = testGameState.table;
- newTable.valid = false;
- oldTable.clonedTable = newTable;
+ MockTable oldTable = testRoundState.table;
+ testTable.valid = false;
+ oldTable.clonedTable = testTable;
view.startTurnEvent.emit();
assertFalse(view.displayStartTurnPanel);
resetTurnStart();
view.getPlayerPanel().endTurnEvent.emit();
- assertNull(testGameState.setTable);
- assertEquals(14 + 1, testGameState.players.get(0).hand.getSize());
- assertEquals(1, testGameState.activePlayer);
+ assertNull(testRoundState.setTable);
+ assertEquals(14 + 1, testRoundState.players.get(0).hand.getSize());
+ assertEquals(1, testRoundState.activePlayer);
checkTurnStartSetUp();
}
@@ -234,17 +372,17 @@ public class RoundControlTest {
@Test
public void testWinning() {
testRound.startRound();
- MockTable oldTable = testGameState.table;
- newTable.valid = true;
- oldTable.clonedTable = newTable;
+ MockTable oldTable = testRoundState.table;
+ testTable.valid = true;
+ oldTable.clonedTable = testTable;
view.startTurnEvent.emit();
assertFalse(view.displayStartTurnPanel);
- IHand hand = testGameState.players.get(0).hand;
+ IHand hand = testRoundState.players.get(0).hand;
Stone stone = hand.iterator().next().getFirst();
hand.pickUp(stone);
- newTable.drop(new StoneSet(stone), new Position(0, 0));
- testGameState.players.get(0).hand = new Hand();
+ testTable.drop(new StoneSet(stone), new Position(0, 0));
+ testRoundState.players.get(0).hand = new Hand();
resetTurnStart();
view.getPlayerPanel().endTurnEvent.emit();
@@ -262,12 +400,15 @@ public class RoundControlTest {
Stone blueTwo = new Stone(2, BLUE);
Stone blueThree = new Stone(3, BLUE);
Stone blueFour = new Stone(4, BLUE);
- StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne));
+ StoneSet oldSet1 = new StoneSet(
+ Arrays.asList(blueOne, redOne, blackOne));
StoneSet oldSet2 = new StoneSet(blueTwo);
oldTable.drop(oldSet1, new Position(0, 0));
oldTable.drop(oldSet2, new Position(0, 0));
- StoneSet newSet1 = new StoneSet(Arrays.asList(blueOne, blueTwo, blueFour));
- StoneSet newSet2 = new StoneSet(Arrays.asList(redOne, blackOne, blueThree));
+ StoneSet newSet1 = new StoneSet(Arrays.asList(blueOne, blueTwo,
+ blueFour));
+ StoneSet newSet2 = new StoneSet(Arrays.asList(redOne, blackOne,
+ blueThree));
newTable.drop(newSet1, new Position(0, 0));
newTable.drop(newSet2, new Position(0, 0));