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
This commit is contained in:
parent
e76977652d
commit
39d3c143b2
2 changed files with 198 additions and 58 deletions
|
@ -61,9 +61,8 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
|
||||||
*
|
*
|
||||||
* @return GROUP or RUN for valid sets, INVALID otherwise
|
* @return GROUP or RUN for valid sets, INVALID otherwise
|
||||||
*/
|
*/
|
||||||
// TODO: Vernünftige Werte Returnen
|
|
||||||
public Pair<Type, Integer> classify() {
|
public Pair<Type, Integer> classify() {
|
||||||
// TODO: extend this for score calculation (release 2...)
|
|
||||||
if (stones.size() < 3) {
|
if (stones.size() < 3) {
|
||||||
return new Pair<Type, Integer>(INVALID, 0);
|
return new Pair<Type, Integer>(INVALID, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -23,6 +24,7 @@ import jrummikub.model.ITable;
|
||||||
import jrummikub.model.MockRoundState;
|
import jrummikub.model.MockRoundState;
|
||||||
import jrummikub.model.MockTable;
|
import jrummikub.model.MockTable;
|
||||||
import jrummikub.model.Position;
|
import jrummikub.model.Position;
|
||||||
|
import jrummikub.model.RoundState;
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
import jrummikub.model.StoneSet;
|
import jrummikub.model.StoneSet;
|
||||||
import jrummikub.model.Table;
|
import jrummikub.model.Table;
|
||||||
|
@ -37,9 +39,9 @@ import org.junit.Test;
|
||||||
*/
|
*/
|
||||||
public class RoundControlTest {
|
public class RoundControlTest {
|
||||||
private MockView view;
|
private MockView view;
|
||||||
private MockRoundState testGameState;
|
private MockRoundState testRoundState;
|
||||||
private RoundControl testRound;
|
private RoundControl testRound;
|
||||||
private MockTable newTable;
|
private MockTable testTable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For each test create a round control initialized by a mock model and view
|
* For each test create a round control initialized by a mock model and view
|
||||||
|
@ -47,20 +49,22 @@ public class RoundControlTest {
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
view = new MockView();
|
view = new MockView();
|
||||||
testGameState = new MockRoundState();
|
testRoundState = new MockRoundState();
|
||||||
testRound = new RoundControl(testGameState, view);
|
testRound = new RoundControl(testRoundState, view);
|
||||||
Stone stone = testGameState.getGameHeap().drawStone();
|
Stone stone = testRoundState.getGameHeap().drawStone();
|
||||||
testGameState.table.drop(new StoneSet(stone), new Position(5, 0));
|
testRoundState.table.drop(new StoneSet(stone), new Position(5, 0));
|
||||||
newTable = new MockTable();
|
testTable = new MockTable();
|
||||||
newTable.sets.add(testGameState.table.sets.get(0));
|
testTable.sets.add(testRoundState.table.sets.get(0));
|
||||||
testGameState.table.clonedTable = newTable;
|
testRoundState.table.clonedTable = testTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkCorrectlyDealed() {
|
private void checkCorrectlyDealed() {
|
||||||
assertEquals(106 - testGameState.getPlayerCount() * 14
|
assertEquals(106 - testRoundState.getPlayerCount() * 14
|
||||||
- testGameState.table.getSize(), testGameState.getGameHeap().getSize());
|
- testRoundState.table.getSize(), testRoundState.getGameHeap()
|
||||||
for (int i = 0; i < testGameState.getPlayerCount(); i++) {
|
.getSize());
|
||||||
assertEquals(14, testGameState.getNthNextPlayer(i).getHand().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() {
|
private void checkTableDisplay() {
|
||||||
Iterator<Pair<StoneSet, Position>> stoneSetsView = view.tablePanel.stoneSets
|
Iterator<Pair<StoneSet, Position>> stoneSetsView = view.tablePanel.stoneSets
|
||||||
.iterator();
|
.iterator();
|
||||||
Iterator<Pair<StoneSet, Position>> stoneSetsModel = testGameState.table
|
Iterator<Pair<StoneSet, Position>> stoneSetsModel = testRoundState.table
|
||||||
.clone().sets.iterator();
|
.clone().sets.iterator();
|
||||||
|
|
||||||
while (stoneSetsView.hasNext()) {
|
while (stoneSetsView.hasNext()) {
|
||||||
|
@ -96,15 +100,149 @@ public class RoundControlTest {
|
||||||
view.displayStartTurnPanel = false;
|
view.displayStartTurnPanel = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// laidOut test cases
|
||||||
/** */
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void playerCameOutCorrectly() {
|
public void laidOutValidTooFew() {
|
||||||
MockTable oldTable = new MockTable();
|
Stone blueOne = new Stone(1, BLUE);
|
||||||
MockTable newTable = new MockTable();
|
Stone blueTwo = new Stone(2, BLUE);
|
||||||
Stone blueTen = new Stone(10, BLUE);
|
Stone blueThree = new Stone(3, BLUE);
|
||||||
Stone redTen = new Stone(10, RED);
|
|
||||||
Stone blackTen = new Stone(10, BLACK);
|
|
||||||
|
|
||||||
|
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 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++) {
|
for (int i = 0; i < 14; i++) {
|
||||||
testRound.dealStones(2);
|
testRound.dealStones(2);
|
||||||
}
|
}
|
||||||
assertEquals(2 * 14 + 14, testGameState.getActivePlayer().getHand()
|
assertEquals(2 * 14 + 14, testRoundState.getActivePlayer().getHand()
|
||||||
.getSize());
|
.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,20 +287,20 @@ public class RoundControlTest {
|
||||||
@Test
|
@Test
|
||||||
public void testTableValidHandChanged() {
|
public void testTableValidHandChanged() {
|
||||||
testRound.startRound();
|
testRound.startRound();
|
||||||
MockTable oldTable = testGameState.table;
|
MockTable oldTable = testRoundState.table;
|
||||||
newTable.valid = true;
|
testTable.valid = true;
|
||||||
oldTable.clonedTable = newTable;
|
oldTable.clonedTable = testTable;
|
||||||
|
|
||||||
view.startTurnEvent.emit();
|
view.startTurnEvent.emit();
|
||||||
assertFalse(view.displayStartTurnPanel);
|
assertFalse(view.displayStartTurnPanel);
|
||||||
|
|
||||||
IHand hand = testGameState.players.get(0).hand;
|
IHand hand = testRoundState.players.get(0).hand;
|
||||||
hand.pickUp(hand.iterator().next().getFirst());
|
hand.pickUp(hand.iterator().next().getFirst());
|
||||||
resetTurnStart();
|
resetTurnStart();
|
||||||
view.getPlayerPanel().endTurnEvent.emit();
|
view.getPlayerPanel().endTurnEvent.emit();
|
||||||
|
|
||||||
assertSame(newTable, testGameState.setTable);
|
assertSame(testTable, testRoundState.setTable);
|
||||||
assertEquals(1, testGameState.activePlayer);
|
assertEquals(1, testRoundState.activePlayer);
|
||||||
|
|
||||||
checkTurnStartSetUp();
|
checkTurnStartSetUp();
|
||||||
}
|
}
|
||||||
|
@ -171,22 +309,22 @@ public class RoundControlTest {
|
||||||
@Test
|
@Test
|
||||||
public void testTableInvalidHandChanged() {
|
public void testTableInvalidHandChanged() {
|
||||||
testRound.startRound();
|
testRound.startRound();
|
||||||
MockTable oldTable = testGameState.table;
|
MockTable oldTable = testRoundState.table;
|
||||||
newTable.valid = false;
|
testTable.valid = false;
|
||||||
oldTable.clonedTable = newTable;
|
oldTable.clonedTable = testTable;
|
||||||
|
|
||||||
view.startTurnEvent.emit();
|
view.startTurnEvent.emit();
|
||||||
assertFalse(view.displayStartTurnPanel);
|
assertFalse(view.displayStartTurnPanel);
|
||||||
IHand hand = testGameState.players.get(0).hand;
|
IHand hand = testRoundState.players.get(0).hand;
|
||||||
Stone stone = hand.iterator().next().getFirst();
|
Stone stone = hand.iterator().next().getFirst();
|
||||||
hand.pickUp(stone);
|
hand.pickUp(stone);
|
||||||
newTable.drop(new StoneSet(stone), new Position(0, 0));
|
testTable.drop(new StoneSet(stone), new Position(0, 0));
|
||||||
resetTurnStart();
|
resetTurnStart();
|
||||||
view.getPlayerPanel().endTurnEvent.emit();
|
view.getPlayerPanel().endTurnEvent.emit();
|
||||||
|
|
||||||
assertNull(testGameState.setTable);
|
assertNull(testRoundState.setTable);
|
||||||
assertEquals(1, testGameState.activePlayer);
|
assertEquals(1, testRoundState.activePlayer);
|
||||||
assertEquals(14 + 3, testGameState.players.get(0).hand.getSize());
|
assertEquals(14 + 3, testRoundState.players.get(0).hand.getSize());
|
||||||
checkTurnStartSetUp();
|
checkTurnStartSetUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,18 +332,18 @@ public class RoundControlTest {
|
||||||
@Test
|
@Test
|
||||||
public void testTableValidHandUnchanged() {
|
public void testTableValidHandUnchanged() {
|
||||||
testRound.startRound();
|
testRound.startRound();
|
||||||
MockTable oldTable = testGameState.table;
|
MockTable oldTable = testRoundState.table;
|
||||||
newTable.valid = true;
|
testTable.valid = true;
|
||||||
oldTable.clonedTable = newTable;
|
oldTable.clonedTable = testTable;
|
||||||
|
|
||||||
view.startTurnEvent.emit();
|
view.startTurnEvent.emit();
|
||||||
assertFalse(view.displayStartTurnPanel);
|
assertFalse(view.displayStartTurnPanel);
|
||||||
resetTurnStart();
|
resetTurnStart();
|
||||||
view.getPlayerPanel().endTurnEvent.emit();
|
view.getPlayerPanel().endTurnEvent.emit();
|
||||||
|
|
||||||
assertSame(newTable, testGameState.setTable);
|
assertSame(testTable, testRoundState.setTable);
|
||||||
assertEquals(14 + 1, testGameState.players.get(0).hand.getSize());
|
assertEquals(14 + 1, testRoundState.players.get(0).hand.getSize());
|
||||||
assertEquals(1, testGameState.activePlayer);
|
assertEquals(1, testRoundState.activePlayer);
|
||||||
|
|
||||||
checkTurnStartSetUp();
|
checkTurnStartSetUp();
|
||||||
}
|
}
|
||||||
|
@ -214,18 +352,18 @@ public class RoundControlTest {
|
||||||
@Test
|
@Test
|
||||||
public void testTableInvalidHandUnchanged() {
|
public void testTableInvalidHandUnchanged() {
|
||||||
testRound.startRound();
|
testRound.startRound();
|
||||||
MockTable oldTable = testGameState.table;
|
MockTable oldTable = testRoundState.table;
|
||||||
newTable.valid = false;
|
testTable.valid = false;
|
||||||
oldTable.clonedTable = newTable;
|
oldTable.clonedTable = testTable;
|
||||||
|
|
||||||
view.startTurnEvent.emit();
|
view.startTurnEvent.emit();
|
||||||
assertFalse(view.displayStartTurnPanel);
|
assertFalse(view.displayStartTurnPanel);
|
||||||
resetTurnStart();
|
resetTurnStart();
|
||||||
view.getPlayerPanel().endTurnEvent.emit();
|
view.getPlayerPanel().endTurnEvent.emit();
|
||||||
|
|
||||||
assertNull(testGameState.setTable);
|
assertNull(testRoundState.setTable);
|
||||||
assertEquals(14 + 1, testGameState.players.get(0).hand.getSize());
|
assertEquals(14 + 1, testRoundState.players.get(0).hand.getSize());
|
||||||
assertEquals(1, testGameState.activePlayer);
|
assertEquals(1, testRoundState.activePlayer);
|
||||||
|
|
||||||
checkTurnStartSetUp();
|
checkTurnStartSetUp();
|
||||||
}
|
}
|
||||||
|
@ -234,17 +372,17 @@ public class RoundControlTest {
|
||||||
@Test
|
@Test
|
||||||
public void testWinning() {
|
public void testWinning() {
|
||||||
testRound.startRound();
|
testRound.startRound();
|
||||||
MockTable oldTable = testGameState.table;
|
MockTable oldTable = testRoundState.table;
|
||||||
newTable.valid = true;
|
testTable.valid = true;
|
||||||
oldTable.clonedTable = newTable;
|
oldTable.clonedTable = testTable;
|
||||||
|
|
||||||
view.startTurnEvent.emit();
|
view.startTurnEvent.emit();
|
||||||
assertFalse(view.displayStartTurnPanel);
|
assertFalse(view.displayStartTurnPanel);
|
||||||
IHand hand = testGameState.players.get(0).hand;
|
IHand hand = testRoundState.players.get(0).hand;
|
||||||
Stone stone = hand.iterator().next().getFirst();
|
Stone stone = hand.iterator().next().getFirst();
|
||||||
hand.pickUp(stone);
|
hand.pickUp(stone);
|
||||||
newTable.drop(new StoneSet(stone), new Position(0, 0));
|
testTable.drop(new StoneSet(stone), new Position(0, 0));
|
||||||
testGameState.players.get(0).hand = new Hand();
|
testRoundState.players.get(0).hand = new Hand();
|
||||||
resetTurnStart();
|
resetTurnStart();
|
||||||
view.getPlayerPanel().endTurnEvent.emit();
|
view.getPlayerPanel().endTurnEvent.emit();
|
||||||
|
|
||||||
|
@ -262,12 +400,15 @@ public class RoundControlTest {
|
||||||
Stone blueTwo = new Stone(2, BLUE);
|
Stone blueTwo = new Stone(2, BLUE);
|
||||||
Stone blueThree = new Stone(3, BLUE);
|
Stone blueThree = new Stone(3, BLUE);
|
||||||
Stone blueFour = new Stone(4, 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);
|
StoneSet oldSet2 = new StoneSet(blueTwo);
|
||||||
oldTable.drop(oldSet1, new Position(0, 0));
|
oldTable.drop(oldSet1, new Position(0, 0));
|
||||||
oldTable.drop(oldSet2, new Position(0, 0));
|
oldTable.drop(oldSet2, new Position(0, 0));
|
||||||
StoneSet newSet1 = new StoneSet(Arrays.asList(blueOne, blueTwo, blueFour));
|
StoneSet newSet1 = new StoneSet(Arrays.asList(blueOne, blueTwo,
|
||||||
StoneSet newSet2 = new StoneSet(Arrays.asList(redOne, blackOne, blueThree));
|
blueFour));
|
||||||
|
StoneSet newSet2 = new StoneSet(Arrays.asList(redOne, blackOne,
|
||||||
|
blueThree));
|
||||||
newTable.drop(newSet1, new Position(0, 0));
|
newTable.drop(newSet1, new Position(0, 0));
|
||||||
newTable.drop(newSet2, new Position(0, 0));
|
newTable.drop(newSet2, new Position(0, 0));
|
||||||
|
|
||||||
|
|
Reference in a new issue