Fixed tests

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@537 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-06-21 03:54:43 +02:00
parent b62babba45
commit c708a0b648
3 changed files with 58 additions and 70 deletions

View file

@ -309,4 +309,10 @@ public class MockView implements IView {
public void load() { public void load() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override
public void setMayPause(boolean mayPause) {
// TODO Auto-generated method stub
}
} }

View file

@ -1,8 +1,6 @@
package jrummikub.control.turn; package jrummikub.control.turn;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.*;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.awt.Color; import java.awt.Color;
@ -82,7 +80,7 @@ public class AIControlTest {
@Test(timeout = 10000) @Test(timeout = 10000)
public void testTurnZeroNoRedealing() throws InterruptedException { public void testTurnZeroNoRedealing() throws InterruptedException {
aiControl.setup(new ITurnControl.TurnInfo(roundState, aiControl.setup(new ITurnControl.TurnInfo(roundState,
TurnMode.MAY_REDEAL), gameSettings, view); TurnMode.MAY_REDEAL, false), gameSettings, view);
aiControl.startTurn(); aiControl.startTurn();
assertTrue(turnEnded); assertTrue(turnEnded);
assertFalse(redealt); assertFalse(redealt);
@ -96,7 +94,7 @@ public class AIControlTest {
@Test(timeout = 10000) @Test(timeout = 10000)
public void testTurnZeroNotMelding() throws InterruptedException { public void testTurnZeroNotMelding() throws InterruptedException {
aiControl.setup(new ITurnControl.TurnInfo(roundState, aiControl.setup(new ITurnControl.TurnInfo(roundState,
TurnMode.INSPECT_ONLY), gameSettings, view); TurnMode.INSPECT_ONLY, false), gameSettings, view);
aiControl.startTurn(); aiControl.startTurn();
assertTrue(turnEnded); assertTrue(turnEnded);
assertFalse(redealt); assertFalse(redealt);
@ -110,7 +108,7 @@ public class AIControlTest {
@Test @Test
public void testNormalTurnMelding() throws InterruptedException { public void testNormalTurnMelding() throws InterruptedException {
aiControl.setup(new ITurnControl.TurnInfo(roundState, aiControl.setup(new ITurnControl.TurnInfo(roundState,
TurnMode.NORMAL_TURN), gameSettings, view); TurnMode.NORMAL_TURN, false), gameSettings, view);
aiControl.startTurn(); aiControl.startTurn();
assertTrue(turnEnded); assertTrue(turnEnded);
assertFalse(redealt); assertFalse(redealt);

View file

@ -1,13 +1,7 @@
package jrummikub.control.turn; package jrummikub.control.turn;
import static jrummikub.model.StoneColor.BLACK; import static jrummikub.model.StoneColor.*;
import static jrummikub.model.StoneColor.BLUE; import static org.junit.Assert.*;
import static jrummikub.model.StoneColor.ORANGE;
import static jrummikub.model.StoneColor.RED;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -37,7 +31,6 @@ import jrummikub.model.Table;
import jrummikub.util.Event; import jrummikub.util.Event;
import jrummikub.util.IEvent; import jrummikub.util.IEvent;
import jrummikub.util.IListener2; import jrummikub.util.IListener2;
import jrummikub.util.IListener3;
import jrummikub.util.Pair; import jrummikub.util.Pair;
import jrummikub.view.IView.BottomPanelType; import jrummikub.view.IView.BottomPanelType;
import jrummikub.view.MockView; import jrummikub.view.MockView;
@ -151,7 +144,7 @@ public class TurnControlTest {
mockPlayer.hand = mockHand; mockPlayer.hand = mockHand;
testControl = new HumanTurnControl(mockTimer); testControl = new HumanTurnControl(mockTimer);
testControl.setup(new ITurnControl.TurnInfo(mockRoundState, testControl.setup(new ITurnControl.TurnInfo(mockRoundState,
TurnMode.NORMAL_TURN), new GameSettings(), mockView); TurnMode.NORMAL_TURN, false), new GameSettings(), mockView);
} }
/** */ /** */
@ -178,7 +171,7 @@ public class TurnControlTest {
testControl = new HumanTurnControl(mockTimer); testControl = new HumanTurnControl(mockTimer);
testControl.setup(new ITurnControl.TurnInfo(mockRoundState, testControl.setup(new ITurnControl.TurnInfo(mockRoundState,
TurnMode.INSPECT_ONLY), new GameSettings(), mockView); TurnMode.INSPECT_ONLY, false), new GameSettings(), mockView);
testControl.startTurn(); testControl.startTurn();
mockView.startTurnEvent.emit(); mockView.startTurnEvent.emit();
@ -227,8 +220,7 @@ public class TurnControlTest {
testControl.getEndOfTurnEvent().add( testControl.getEndOfTurnEvent().add(
new IListener2<IRoundState, RoundControl.InvalidTurnInfo>() { new IListener2<IRoundState, RoundControl.InvalidTurnInfo>() {
@Override @Override
public void handle(IRoundState value1, public void handle(IRoundState value1, InvalidTurnInfo value2) {
InvalidTurnInfo value2) {
eventFired = true; eventFired = true;
} }
}); });
@ -312,8 +304,8 @@ public class TurnControlTest {
mockView.handPanel.stoneClickEvent.emit(redJoker, true); mockView.handPanel.stoneClickEvent.emit(redJoker, true);
mockView.handPanel.stoneClickEvent.emit(blackJoker, true); mockView.handPanel.stoneClickEvent.emit(blackJoker, true);
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit( mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(blackJoker,
blackJoker, true); true);
assertCollection(Arrays.asList(redJoker, blackJoker)); assertCollection(Arrays.asList(redJoker, blackJoker));
} }
@ -329,8 +321,7 @@ public class TurnControlTest {
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(redJoker, mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(redJoker,
true); true);
mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(redJoker, mockView.tablePanel.stoneCollectionPanel.setClickEvent.emit(redJoker, true);
true);
assertCollection(new ArrayList<Stone>()); assertCollection(new ArrayList<Stone>());
} }
@ -428,8 +419,8 @@ public class TurnControlTest {
testControl.startTurn(); testControl.startTurn();
Stone stone4 = new Stone(4, StoneColor.RED); Stone stone4 = new Stone(4, StoneColor.RED);
StoneSet set1 = new StoneSet(Arrays.asList(redOne, redTwo, redThree, StoneSet set1 = new StoneSet(
stone4)); Arrays.asList(redOne, redTwo, redThree, stone4));
mockTable.findStoneSet.put(redOne, set1); mockTable.findStoneSet.put(redOne, set1);
mockTable.findStoneSet.put(redThree, set1); mockTable.findStoneSet.put(redThree, set1);
@ -600,15 +591,15 @@ public class TurnControlTest {
mockHand.drop(blueThree, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0));
mockHand.drop(blueFour, new Position(0, 0)); mockHand.drop(blueFour, new Position(0, 0));
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
blackOne, redTwo, redThree, redFour, blackTwo, blackThree)); redTwo, redThree, redFour, blackTwo, blackThree));
StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour, StoneSet oldSet2 = new StoneSet(
blackFive)); Arrays.asList(blueTwo, blackFour, blackFive));
table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet1, new Position(0, 0));
table.drop(oldSet2, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0));
turnControl.setup(new ITurnControl.TurnInfo(mockRoundState, turnControl.setup(new ITurnControl.TurnInfo(mockRoundState,
TurnMode.NORMAL_TURN), new GameSettings(), mockView); TurnMode.NORMAL_TURN, false), new GameSettings(), mockView);
turnControl.startTurn(); turnControl.startTurn();
mockView.handPanel.stoneClickEvent.emit(blueThree, false); mockView.handPanel.stoneClickEvent.emit(blueThree, false);
@ -707,16 +698,17 @@ public class TurnControlTest {
mockTable.clonedTable = table; mockTable.clonedTable = table;
HumanTurnControl turnControl = new HumanTurnControl(mockTimer); HumanTurnControl turnControl = new HumanTurnControl(mockTimer);
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
blackOne, redTwo, redThree, redFour, blackTwo, blackThree)); redTwo, redThree, redFour, blackTwo, blackThree));
StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour, StoneSet oldSet2 = new StoneSet(
blackFive)); Arrays.asList(blueTwo, blackFour, blackFive));
table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet1, new Position(0, 0));
table.drop(oldSet2, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0));
mockHand.drop(blueFour, new Position(0, 0)); mockHand.drop(blueFour, new Position(0, 0));
turnControl.setup(new TurnInfo(mockRoundState, TurnMode.NORMAL_TURN), turnControl.setup(
new TurnInfo(mockRoundState, TurnMode.NORMAL_TURN, false),
new GameSettings(), mockView); new GameSettings(), mockView);
turnControl.startTurn(); turnControl.startTurn();
@ -814,17 +806,18 @@ public class TurnControlTest {
public void testAddNewSet() { public void testAddNewSet() {
AccessibleTable table = new AccessibleTable(); AccessibleTable table = new AccessibleTable();
mockTable.clonedTable = table; mockTable.clonedTable = table;
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
blackOne, redTwo, redThree, redFour, blackTwo, blackThree)); redTwo, redThree, redFour, blackTwo, blackThree));
StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour, StoneSet oldSet2 = new StoneSet(
blackFive)); Arrays.asList(blueTwo, blackFour, blackFive));
table.drop(oldSet1, new Position(0, 0)); table.drop(oldSet1, new Position(0, 0));
table.drop(oldSet2, new Position(0, 0)); table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0)); mockHand.drop(blueThree, new Position(0, 0));
mockHand.drop(blueFour, new Position(0, 0)); mockHand.drop(blueFour, new Position(0, 0));
HumanTurnControl turnControl = new HumanTurnControl(mockTimer); HumanTurnControl turnControl = new HumanTurnControl(mockTimer);
turnControl.setup(new TurnInfo(mockRoundState, TurnMode.NORMAL_TURN), turnControl.setup(
new TurnInfo(mockRoundState, TurnMode.NORMAL_TURN, false),
new GameSettings(), mockView); new GameSettings(), mockView);
turnControl.startTurn(); turnControl.startTurn();
mockView.handPanel.stoneClickEvent.emit(blueThree, false); mockView.handPanel.stoneClickEvent.emit(blueThree, false);
@ -914,8 +907,8 @@ public class TurnControlTest {
List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>( List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(
mockHand.stones); mockHand.stones);
Collections.sort(stones, Collections
new HumanTurnControl.HandStonePositionComparator()); .sort(stones, new HumanTurnControl.HandStonePositionComparator());
assertEquals(stones.size(), 13); assertEquals(stones.size(), 13);
@ -963,8 +956,8 @@ public class TurnControlTest {
List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>( List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(
mockHand.stones); mockHand.stones);
Collections.sort(stones, Collections
new HumanTurnControl.HandStonePositionComparator()); .sort(stones, new HumanTurnControl.HandStonePositionComparator());
assertEquals(stones.size(), 13); assertEquals(stones.size(), 13);
@ -1004,8 +997,8 @@ public class TurnControlTest {
assertCollection(new ArrayList<Stone>()); assertCollection(new ArrayList<Stone>());
Set<Stone> expected = new HashSet<Stone>(Arrays.asList(redJoker, Set<Stone> expected = new HashSet<Stone>(
blackJoker)); Arrays.asList(redJoker, blackJoker));
assertEquals(expected, mockHand.pickups); assertEquals(expected, mockHand.pickups);
Set<Stone> handStones = new HashSet<Stone>(); Set<Stone> handStones = new HashSet<Stone>();
@ -1032,8 +1025,7 @@ public class TurnControlTest {
assertCollection(Arrays.asList(blackJoker)); assertCollection(Arrays.asList(blackJoker));
Set<Stone> expected = new HashSet<Stone>(Arrays.asList(redJoker, Set<Stone> expected = new HashSet<Stone>(Arrays.asList(redJoker, black13));
black13));
assertEquals(expected, mockHand.pickups); assertEquals(expected, mockHand.pickups);
Set<Stone> handStones = new HashSet<Stone>(); Set<Stone> handStones = new HashSet<Stone>();
@ -1049,15 +1041,12 @@ public class TurnControlTest {
public void testTableDifference() { public void testTableDifference() {
MockTable oldTable = new MockTable(); MockTable oldTable = new MockTable();
MockTable newTable = new MockTable(); MockTable newTable = new MockTable();
StoneSet oldSet1 = new StoneSet( StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne));
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, StoneSet newSet1 = new StoneSet(Arrays.asList(blueOne, blueTwo, blueFour));
blueFour)); StoneSet newSet2 = new StoneSet(Arrays.asList(redOne, blackOne, blueThree));
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));
@ -1065,8 +1054,7 @@ public class TurnControlTest {
expectedStones.add(blueThree); expectedStones.add(blueThree);
expectedStones.add(blueFour); expectedStones.add(blueFour);
Set<Stone> stones = AbstractTurnControl.tableDifference(oldTable, Set<Stone> stones = AbstractTurnControl.tableDifference(oldTable, newTable);
newTable);
assertTrue(expectedStones.containsAll(stones)); assertTrue(expectedStones.containsAll(stones));
assertTrue(stones.containsAll(expectedStones)); assertTrue(stones.containsAll(expectedStones));
@ -1083,15 +1071,14 @@ public class TurnControlTest {
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, StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
blackOne, orangeOne)); orangeOne));
StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blueThree, StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blueThree, blueFour));
blueFour));
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));
ITable newTable = (Table) oldTable.clone(); ITable newTable = (Table) oldTable.clone();
List<StoneSet> newSets = AbstractTurnControl.tableSetDifference( List<StoneSet> newSets = AbstractTurnControl.tableSetDifference(oldTable,
oldTable, newTable); newTable);
List<StoneSet> vanishedSets = AbstractTurnControl.tableSetDifference( List<StoneSet> vanishedSets = AbstractTurnControl.tableSetDifference(
newTable, oldTable); newTable, oldTable);
@ -1099,11 +1086,10 @@ public class TurnControlTest {
assertTrue(vanishedSets.isEmpty()); assertTrue(vanishedSets.isEmpty());
newTable.pickUp(oldSet2); newTable.pickUp(oldSet2);
newTable.drop(oldSet2.join(new StoneSet(new Stone(5, BLUE))), newTable.drop(oldSet2.join(new StoneSet(new Stone(5, BLUE))), new Position(
new Position(0, 0)); 0, 0));
newSets = AbstractTurnControl.tableSetDifference(oldTable, newTable); newSets = AbstractTurnControl.tableSetDifference(oldTable, newTable);
vanishedSets = AbstractTurnControl.tableSetDifference(newTable, vanishedSets = AbstractTurnControl.tableSetDifference(newTable, oldTable);
oldTable);
assertFalse(newSets.isEmpty()); assertFalse(newSets.isEmpty());
assertFalse(vanishedSets.isEmpty()); assertFalse(vanishedSets.isEmpty());
@ -1113,13 +1099,11 @@ public class TurnControlTest {
Stone redTwo = new Stone(2, RED); Stone redTwo = new Stone(2, RED);
Stone redThree = new Stone(3, RED); Stone redThree = new Stone(3, RED);
Stone redFour = new Stone(4, RED); Stone redFour = new Stone(4, RED);
StoneSet oldSet3 = new StoneSet( StoneSet oldSet3 = new StoneSet(Arrays.asList(redTwo, redThree, redFour));
Arrays.asList(redTwo, redThree, redFour));
ITable newTable2 = (Table) oldTable.clone(); ITable newTable2 = (Table) oldTable.clone();
newTable2.drop(oldSet3, new Position(0, 0)); newTable2.drop(oldSet3, new Position(0, 0));
newSets = AbstractTurnControl.tableSetDifference(oldTable, newTable2); newSets = AbstractTurnControl.tableSetDifference(oldTable, newTable2);
vanishedSets = AbstractTurnControl.tableSetDifference(newTable2, vanishedSets = AbstractTurnControl.tableSetDifference(newTable2, oldTable);
oldTable);
assertFalse(newSets.isEmpty()); assertFalse(newSets.isEmpty());
assertTrue(vanishedSets.isEmpty()); assertTrue(vanishedSets.isEmpty());