Some missing control tests
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@591 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
e1df2b8e88
commit
f5aa073827
4 changed files with 107 additions and 2 deletions
|
@ -9,6 +9,7 @@ import jrummikub.util.Event1;
|
||||||
import jrummikub.util.Event2;
|
import jrummikub.util.Event2;
|
||||||
import jrummikub.util.IEvent1;
|
import jrummikub.util.IEvent1;
|
||||||
import jrummikub.util.IEvent2;
|
import jrummikub.util.IEvent2;
|
||||||
|
import jrummikub.util.MockEvent2;
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,7 +17,7 @@ import jrummikub.util.Pair;
|
||||||
*/
|
*/
|
||||||
public class MockHandPanel implements IHandPanel {
|
public class MockHandPanel implements IHandPanel {
|
||||||
/** */
|
/** */
|
||||||
public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>();
|
public MockEvent2<Stone, Boolean> stoneClickEvent = new MockEvent2<Stone, Boolean>();
|
||||||
/** */
|
/** */
|
||||||
public List<Pair<Stone, Position>> stones;
|
public List<Pair<Stone, Position>> stones;
|
||||||
/** */
|
/** */
|
||||||
|
|
|
@ -18,6 +18,8 @@ import jrummikub.util.Pair;
|
||||||
/**
|
/**
|
||||||
* Base class for AI players
|
* Base class for AI players
|
||||||
*
|
*
|
||||||
|
* Code not covered by tests uses timers and background threads.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class AIControl extends AbstractTurnControl {
|
public class AIControl extends AbstractTurnControl {
|
||||||
private TurnLogic logic;
|
private TurnLogic logic;
|
||||||
|
|
|
@ -10,6 +10,7 @@ import jrummikub.model.IHand;
|
||||||
import jrummikub.model.PlayerSettings;
|
import jrummikub.model.PlayerSettings;
|
||||||
import jrummikub.model.Position;
|
import jrummikub.model.Position;
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
|
import jrummikub.util.IListener;
|
||||||
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;
|
||||||
|
@ -24,6 +25,7 @@ public class GameControlTest {
|
||||||
private GameControl gameControl;
|
private GameControl gameControl;
|
||||||
private GameSettings gameSettings;
|
private GameSettings gameSettings;
|
||||||
private MockView view;
|
private MockView view;
|
||||||
|
protected boolean gameEnded;
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
@Before
|
@Before
|
||||||
|
@ -81,6 +83,84 @@ public class GameControlTest {
|
||||||
view.newRoundEvent.emit();
|
view.newRoundEvent.emit();
|
||||||
assertSame(BottomPanelType.START_TURN_PANEL, view.bottomPanelType);
|
assertSame(BottomPanelType.START_TURN_PANEL, view.bottomPanelType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNewGame() {
|
||||||
|
gameControl.getEndOfGameEvent().add(new IListener() {
|
||||||
|
@Override
|
||||||
|
public void handle() {
|
||||||
|
gameEnded = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
gameEnded = false;
|
||||||
|
|
||||||
|
gameControl.startGame();
|
||||||
|
// Manipulate first player's hand, to allow player1 to win
|
||||||
|
IHand playerHand = gameControl.roundControl.roundState.getActivePlayer().getHand();
|
||||||
|
for (Pair<Stone, Position> entry : playerHand.clone()) {
|
||||||
|
playerHand.pickUp(entry.getFirst());
|
||||||
|
}
|
||||||
|
Stone stone1 = new Stone(9, RED);
|
||||||
|
Stone stone2 = new Stone(10, RED);
|
||||||
|
Stone stone3 = new Stone(11, RED);
|
||||||
|
playerHand.drop(stone1, new Position(0, 0));
|
||||||
|
playerHand.drop(stone2, new Position(0, 0));
|
||||||
|
playerHand.drop(stone3, new Position(0, 0));
|
||||||
|
// Done setting up first players hand
|
||||||
|
|
||||||
|
view.startTurnEvent.emit();
|
||||||
|
|
||||||
|
view.playerPanel.endTurnEvent.emit();
|
||||||
|
view.startTurnEvent.emit();
|
||||||
|
view.playerPanel.endTurnEvent.emit();
|
||||||
|
view.startTurnEvent.emit();
|
||||||
|
|
||||||
|
view.handPanel.stoneClickEvent.emit(stone1, false);
|
||||||
|
view.handPanel.stoneClickEvent.emit(stone2, true);
|
||||||
|
view.handPanel.stoneClickEvent.emit(stone3, true);
|
||||||
|
|
||||||
|
view.tablePanel.clickEvent.emit(new Position(0, 0));
|
||||||
|
view.playerPanel.endTurnEvent.emit();
|
||||||
|
|
||||||
|
assertSame(BottomPanelType.WIN_PANEL, view.bottomPanelType);
|
||||||
|
|
||||||
|
|
||||||
|
assertFalse(gameEnded);
|
||||||
|
view.newGameEvent.emit();
|
||||||
|
assertTrue(gameEnded);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAborting() {
|
||||||
|
gameControl.startGame();
|
||||||
|
|
||||||
|
// Manipulate first player's hand, to allow player1 to win
|
||||||
|
IHand playerHand = gameControl.roundControl.roundState.getActivePlayer().getHand();
|
||||||
|
for (Pair<Stone, Position> entry : playerHand.clone()) {
|
||||||
|
playerHand.pickUp(entry.getFirst());
|
||||||
|
}
|
||||||
|
Stone stone1 = new Stone(9, RED);
|
||||||
|
Stone stone2 = new Stone(10, RED);
|
||||||
|
Stone stone3 = new Stone(11, RED);
|
||||||
|
playerHand.drop(stone1, new Position(0, 0));
|
||||||
|
playerHand.drop(stone2, new Position(0, 0));
|
||||||
|
playerHand.drop(stone3, new Position(0, 0));
|
||||||
|
// Done setting up first players hand
|
||||||
|
|
||||||
|
view.startTurnEvent.emit();
|
||||||
|
|
||||||
|
view.playerPanel.endTurnEvent.emit();
|
||||||
|
view.startTurnEvent.emit();
|
||||||
|
view.playerPanel.endTurnEvent.emit();
|
||||||
|
view.startTurnEvent.emit();
|
||||||
|
|
||||||
|
view.handPanel.stoneClickEvent.emit(stone1, false);
|
||||||
|
view.handPanel.stoneClickEvent.emit(stone2, true);
|
||||||
|
gameControl.abortGame();
|
||||||
|
assertTrue(view.handPanel.stoneClickEvent.listeners.isEmpty());
|
||||||
|
assertTrue(view.playerPanel.endTurnEvent.listeners.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
package jrummikub.control.turn;
|
package jrummikub.control.turn;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static jrummikub.model.StoneColor.RED;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import jrummikub.control.RoundControl;
|
import jrummikub.control.RoundControl;
|
||||||
import jrummikub.model.GameSettings;
|
import jrummikub.model.GameSettings;
|
||||||
|
@ -15,6 +19,7 @@ import jrummikub.model.Position;
|
||||||
import jrummikub.model.RoundState;
|
import jrummikub.model.RoundState;
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
import jrummikub.model.StoneColor;
|
import jrummikub.model.StoneColor;
|
||||||
|
import jrummikub.model.StoneSet;
|
||||||
import jrummikub.util.IListener;
|
import jrummikub.util.IListener;
|
||||||
import jrummikub.util.IListener2;
|
import jrummikub.util.IListener2;
|
||||||
import jrummikub.view.MockView;
|
import jrummikub.view.MockView;
|
||||||
|
@ -115,4 +120,21 @@ public class AIControlTest {
|
||||||
assertEquals(1, roundState.getTable().getSize());
|
assertEquals(1, roundState.getTable().getSize());
|
||||||
assertEquals(0, roundState.getActivePlayer().getHand().getSize());
|
assertEquals(0, roundState.getActivePlayer().getHand().getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWithStonesOnTable() {
|
||||||
|
roundState.getActivePlayer().setLaidOut(true);
|
||||||
|
roundState.getTable().drop(new StoneSet(Arrays.asList(new Stone(1, RED), new Stone(2, RED), new Stone(3, RED))), new Position(0,0));
|
||||||
|
IHand hand = roundState.getActivePlayer().getHand();
|
||||||
|
hand.drop(new Stone(4, RED), new Position(0,0));
|
||||||
|
hand.drop(new Stone(7, RED), new Position(0,0));
|
||||||
|
aiControl.setup(new ITurnControl.TurnInfo(roundState,
|
||||||
|
TurnMode.NORMAL_TURN, false), gameSettings, view);
|
||||||
|
aiControl.startTurn();
|
||||||
|
assertTrue(turnEnded);
|
||||||
|
assertFalse(redealt);
|
||||||
|
assertEquals(2, roundState.getTable().getSize());
|
||||||
|
assertEquals(1, roundState.getActivePlayer().getHand().getSize());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue