Added all missing comments
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@213 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
4a860e53cf
commit
3b49b2053e
38 changed files with 696 additions and 263 deletions
|
@ -4,13 +4,22 @@ import java.awt.Color;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock class for {@link GameState}
|
||||||
|
*/
|
||||||
public class MockGameState implements IGameState {
|
public class MockGameState implements IGameState {
|
||||||
|
/** */
|
||||||
public MockTable table;
|
public MockTable table;
|
||||||
|
/** */
|
||||||
public ITable setTable;
|
public ITable setTable;
|
||||||
|
/** */
|
||||||
public List<MockPlayer> players;
|
public List<MockPlayer> players;
|
||||||
|
/** */
|
||||||
public int activePlayer;
|
public int activePlayer;
|
||||||
|
/** */
|
||||||
public StoneHeap gameHeap;
|
public StoneHeap gameHeap;
|
||||||
|
|
||||||
|
/** */
|
||||||
public MockGameState() {
|
public MockGameState() {
|
||||||
table = new MockTable();
|
table = new MockTable();
|
||||||
players = new ArrayList<MockPlayer>();
|
players = new ArrayList<MockPlayer>();
|
||||||
|
|
|
@ -7,13 +7,15 @@ import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
|
/**
|
||||||
|
* Mock class for {@link Hand}
|
||||||
|
*/
|
||||||
public class MockHand implements IHand {
|
public class MockHand implements IHand {
|
||||||
|
/** */
|
||||||
public List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>();
|
public List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>();
|
||||||
|
/** */
|
||||||
public Set<Stone> pickups = new HashSet<Stone>();
|
public Set<Stone> pickups = new HashSet<Stone>();
|
||||||
|
/** */
|
||||||
public Iterable<Pair<Stone, Position>> iterable;
|
public Iterable<Pair<Stone, Position>> iterable;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,14 +2,21 @@ package jrummikub.model;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock class for {@link Player}
|
||||||
|
*/
|
||||||
public class MockPlayer implements IPlayer {
|
public class MockPlayer implements IPlayer {
|
||||||
|
/** */
|
||||||
public MockHand hand;
|
public MockHand hand;
|
||||||
|
/** */
|
||||||
public String name;
|
public String name;
|
||||||
|
/** */
|
||||||
public Color color;
|
public Color color;
|
||||||
|
|
||||||
// private String name;
|
/**
|
||||||
|
* @param name
|
||||||
|
* @param color
|
||||||
|
*/
|
||||||
public MockPlayer(String name, Color color) {
|
public MockPlayer(String name, Color color) {
|
||||||
hand = new MockHand();
|
hand = new MockHand();
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
|
@ -7,11 +7,17 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
|
/**
|
||||||
|
* Mock class for {@link Table}
|
||||||
|
*/
|
||||||
public class MockTable implements ITable {
|
public class MockTable implements ITable {
|
||||||
|
/** */
|
||||||
public Map<Stone, StoneSet> findStoneSet = new HashMap<Stone, StoneSet>();
|
public Map<Stone, StoneSet> findStoneSet = new HashMap<Stone, StoneSet>();
|
||||||
|
/** */
|
||||||
public boolean valid = false;
|
public boolean valid = false;
|
||||||
|
/** */
|
||||||
public MockTable clonedTable;
|
public MockTable clonedTable;
|
||||||
|
/** */
|
||||||
public List<Pair<StoneSet, Position>> sets = new ArrayList<Pair<StoneSet, Position>>();
|
public List<Pair<StoneSet, Position>> sets = new ArrayList<Pair<StoneSet, Position>>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package jrummikub.util;
|
package jrummikub.util;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
/**
|
||||||
|
* Mock class for Events
|
||||||
|
*/
|
||||||
public class MockEvent implements IEvent {
|
public class MockEvent implements IEvent {
|
||||||
|
/** */
|
||||||
public HashSet<IListener> listeners = new HashSet<IListener>();
|
public HashSet<IListener> listeners = new HashSet<IListener>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -21,7 +24,8 @@ public class MockEvent implements IEvent {
|
||||||
public void remove(IListener listener) {
|
public void remove(IListener listener) {
|
||||||
listeners.remove(listener);
|
listeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
public void emit() {
|
public void emit() {
|
||||||
for (IListener listener : listeners) {
|
for (IListener listener : listeners) {
|
||||||
listener.handle();
|
listener.handle();
|
||||||
|
|
|
@ -2,14 +2,21 @@ package jrummikub.util;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock class for Event1s
|
||||||
|
*
|
||||||
|
* @param <T>
|
||||||
|
* event type
|
||||||
|
*/
|
||||||
public class MockEvent1<T> implements IEvent1<T> {
|
public class MockEvent1<T> implements IEvent1<T> {
|
||||||
|
/** */
|
||||||
public HashSet<IListener1<T>> listeners = new HashSet<IListener1<T>>();
|
public HashSet<IListener1<T>> listeners = new HashSet<IListener1<T>>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection add(final IListener1<T> listener) {
|
public Connection add(final IListener1<T> listener) {
|
||||||
listeners.add(listener);
|
listeners.add(listener);
|
||||||
return new Connection() {
|
return new Connection() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
MockEvent1.this.remove(listener);
|
MockEvent1.this.remove(listener);
|
||||||
|
@ -22,6 +29,9 @@ public class MockEvent1<T> implements IEvent1<T> {
|
||||||
listeners.remove(listener);
|
listeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
public void emit(T value) {
|
public void emit(T value) {
|
||||||
for (IListener1<T> listener : listeners) {
|
for (IListener1<T> listener : listeners) {
|
||||||
listener.handle(value);
|
listener.handle(value);
|
||||||
|
|
|
@ -2,14 +2,23 @@ package jrummikub.util;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock class for Event2s
|
||||||
|
*
|
||||||
|
* @param <T1>
|
||||||
|
* first event type
|
||||||
|
* @param <T2>
|
||||||
|
* second event type
|
||||||
|
*/
|
||||||
public class MockEvent2<T1, T2> implements IEvent2<T1, T2> {
|
public class MockEvent2<T1, T2> implements IEvent2<T1, T2> {
|
||||||
|
/** */
|
||||||
public HashSet<IListener2<T1, T2>> listeners = new HashSet<IListener2<T1, T2>>();
|
public HashSet<IListener2<T1, T2>> listeners = new HashSet<IListener2<T1, T2>>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection add(final IListener2<T1, T2> listener) {
|
public Connection add(final IListener2<T1, T2> listener) {
|
||||||
listeners.add(listener);
|
listeners.add(listener);
|
||||||
return new Connection() {
|
return new Connection() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove() {
|
public void remove() {
|
||||||
MockEvent2.this.remove(listener);
|
MockEvent2.this.remove(listener);
|
||||||
|
@ -22,6 +31,10 @@ public class MockEvent2<T1, T2> implements IEvent2<T1, T2> {
|
||||||
listeners.remove(listener);
|
listeners.remove(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param value1
|
||||||
|
* @param value2
|
||||||
|
*/
|
||||||
public void emit(T1 value1, T2 value2) {
|
public void emit(T1 value1, T2 value2) {
|
||||||
for (IListener2<T1, T2> listener : listeners) {
|
for (IListener2<T1, T2> listener : listeners) {
|
||||||
listener.handle(value1, value2);
|
listener.handle(value1, value2);
|
||||||
|
|
|
@ -10,11 +10,17 @@ import jrummikub.util.Event2;
|
||||||
import jrummikub.util.IEvent1;
|
import jrummikub.util.IEvent1;
|
||||||
import jrummikub.util.IEvent2;
|
import jrummikub.util.IEvent2;
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
|
/**
|
||||||
|
* Mock class for HandPanel
|
||||||
|
*/
|
||||||
public class MockHandPanel implements IHandPanel {
|
public class MockHandPanel implements IHandPanel {
|
||||||
|
/** */
|
||||||
public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>();
|
public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>();
|
||||||
|
/** */
|
||||||
public List<Pair<Stone, Position>> stones;
|
public List<Pair<Stone, Position>> stones;
|
||||||
|
/** */
|
||||||
public Event2<Stone, Boolean> rangeClickEvent = new Event2<Stone, Boolean>();
|
public Event2<Stone, Boolean> rangeClickEvent = new Event2<Stone, Boolean>();
|
||||||
|
/** */
|
||||||
public Event1<Position> clickEvent = new Event1<Position>();
|
public Event1<Position> clickEvent = new Event1<Position>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,10 +3,17 @@ package jrummikub.view;
|
||||||
import jrummikub.util.IEvent;
|
import jrummikub.util.IEvent;
|
||||||
import jrummikub.util.MockEvent;
|
import jrummikub.util.MockEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock class for PlayerPanel
|
||||||
|
*/
|
||||||
public class MockPlayerPanel implements IPlayerPanel {
|
public class MockPlayerPanel implements IPlayerPanel {
|
||||||
|
/** */
|
||||||
public MockEvent endTurnEvent = new MockEvent();
|
public MockEvent endTurnEvent = new MockEvent();
|
||||||
|
/** */
|
||||||
public MockHandPanel handPanel = new MockHandPanel();
|
public MockHandPanel handPanel = new MockHandPanel();
|
||||||
|
/** */
|
||||||
public MockEvent sortByGroupsEvent = new MockEvent();
|
public MockEvent sortByGroupsEvent = new MockEvent();
|
||||||
|
/** */
|
||||||
public MockEvent sortByRunsEvent = new MockEvent();
|
public MockEvent sortByRunsEvent = new MockEvent();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -4,10 +4,14 @@ import jrummikub.model.Stone;
|
||||||
import jrummikub.util.Event2;
|
import jrummikub.util.Event2;
|
||||||
import jrummikub.util.IEvent2;
|
import jrummikub.util.IEvent2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock class for StoneCollectionPanel
|
||||||
|
*/
|
||||||
public class MockStoneCollectionPanel implements IStoneCollectionPanel {
|
public class MockStoneCollectionPanel implements IStoneCollectionPanel {
|
||||||
|
/** */
|
||||||
public Event2<Stone,Boolean> stoneClickEvent = new Event2<Stone, Boolean>();
|
public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>();
|
||||||
public Event2<Stone,Boolean> setClickEvent = new Event2<Stone, Boolean>();
|
/** */
|
||||||
|
public Event2<Stone, Boolean> setClickEvent = new Event2<Stone, Boolean>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEvent2<Stone, Boolean> getStoneClickEvent() {
|
public IEvent2<Stone, Boolean> getStoneClickEvent() {
|
||||||
|
|
|
@ -9,20 +9,34 @@ import jrummikub.util.IEvent1;
|
||||||
import jrummikub.util.IEvent2;
|
import jrummikub.util.IEvent2;
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mock class for TablePanel
|
||||||
|
*/
|
||||||
public class MockTablePanel implements ITablePanel {
|
public class MockTablePanel implements ITablePanel {
|
||||||
|
|
||||||
|
/** */
|
||||||
public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>();
|
public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>();
|
||||||
|
/** */
|
||||||
public Event2<Stone, Boolean> setClickEvent = new Event2<Stone, Boolean>();
|
public Event2<Stone, Boolean> setClickEvent = new Event2<Stone, Boolean>();
|
||||||
|
/** */
|
||||||
public Event2<Stone, Boolean> rangeClickEvent = new Event2<Stone, Boolean>();
|
public Event2<Stone, Boolean> rangeClickEvent = new Event2<Stone, Boolean>();
|
||||||
|
/** */
|
||||||
public Event1<Position> clickEvent = new Event1<Position>();
|
public Event1<Position> clickEvent = new Event1<Position>();
|
||||||
|
/** */
|
||||||
public Event1<StoneSet> leftConnectorClickEvent = new Event1<StoneSet>();
|
public Event1<StoneSet> leftConnectorClickEvent = new Event1<StoneSet>();
|
||||||
|
/** */
|
||||||
public Event1<StoneSet> rightConnectorClickEvent = new Event1<StoneSet>();
|
public Event1<StoneSet> rightConnectorClickEvent = new Event1<StoneSet>();
|
||||||
|
|
||||||
|
/** */
|
||||||
public MockStoneCollectionPanel stoneCollectionPanel = new MockStoneCollectionPanel();
|
public MockStoneCollectionPanel stoneCollectionPanel = new MockStoneCollectionPanel();
|
||||||
|
/** */
|
||||||
public String leftPlayerName;
|
public String leftPlayerName;
|
||||||
|
/** */
|
||||||
public String topPlayerName;
|
public String topPlayerName;
|
||||||
|
/** */
|
||||||
public String rightPlayerName;
|
public String rightPlayerName;
|
||||||
|
|
||||||
|
/** */
|
||||||
public Iterable<Pair<StoneSet, Position>> stoneSets;
|
public Iterable<Pair<StoneSet, Position>> stoneSets;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -5,19 +5,30 @@ import java.util.Collection;
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
import jrummikub.util.IEvent;
|
import jrummikub.util.IEvent;
|
||||||
import jrummikub.util.MockEvent;
|
import jrummikub.util.MockEvent;
|
||||||
|
/**
|
||||||
|
* Mock class for View
|
||||||
|
*/
|
||||||
public class MockView implements IView {
|
public class MockView implements IView {
|
||||||
|
/** */
|
||||||
public MockPlayerPanel playerPanel = new MockPlayerPanel();
|
public MockPlayerPanel playerPanel = new MockPlayerPanel();
|
||||||
|
/** */
|
||||||
public MockTablePanel tablePanel = new MockTablePanel();
|
public MockTablePanel tablePanel = new MockTablePanel();
|
||||||
|
|
||||||
|
/** */
|
||||||
public Collection<Stone> selectedStones;
|
public Collection<Stone> selectedStones;
|
||||||
|
|
||||||
|
/** */
|
||||||
public String currentPlayerName;
|
public String currentPlayerName;
|
||||||
|
/** */
|
||||||
public boolean displayStartTurnPanel = false;
|
public boolean displayStartTurnPanel = false;
|
||||||
|
/** */
|
||||||
public boolean displayWinPanel = false;
|
public boolean displayWinPanel = false;
|
||||||
|
|
||||||
|
/** */
|
||||||
public MockEvent startTurnEvent = new MockEvent();
|
public MockEvent startTurnEvent = new MockEvent();
|
||||||
|
/** */
|
||||||
public MockEvent quitEvent = new MockEvent();
|
public MockEvent quitEvent = new MockEvent();
|
||||||
|
/** */
|
||||||
public MockEvent newGameEvent = new MockEvent();
|
public MockEvent newGameEvent = new MockEvent();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,12 +2,26 @@ package jrummikub.control;
|
||||||
|
|
||||||
import jrummikub.util.IEvent;
|
import jrummikub.util.IEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for the {@link TurnTimer}
|
||||||
|
*/
|
||||||
public interface ITurnTimer {
|
public interface ITurnTimer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the timer
|
||||||
|
*/
|
||||||
public abstract void startTimer();
|
public abstract void startTimer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops the timer. Stopping an already stopped timer is a no-op.
|
||||||
|
*/
|
||||||
public abstract void stopTimer();
|
public abstract void stopTimer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the event that is emitted if the timer timed out.
|
||||||
|
*
|
||||||
|
* @return time out event
|
||||||
|
*/
|
||||||
public abstract IEvent getTimeRunOutEvent();
|
public abstract IEvent getTimeRunOutEvent();
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,6 +18,9 @@ import jrummikub.util.IListener;
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller that manages a single round of rummikub
|
||||||
|
*/
|
||||||
public class RoundControl {
|
public class RoundControl {
|
||||||
private IGameState gameState;
|
private IGameState gameState;
|
||||||
private IView view;
|
private IView view;
|
||||||
|
@ -25,6 +28,14 @@ public class RoundControl {
|
||||||
private Event endRoundEvent = new Event();
|
private Event endRoundEvent = new Event();
|
||||||
private List<Connection> connections = new ArrayList<Connection>();
|
private List<Connection> connections = new ArrayList<Connection>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new RoundControl using the given gameState and view
|
||||||
|
*
|
||||||
|
* @param gameState
|
||||||
|
* initial game state
|
||||||
|
* @param view
|
||||||
|
* view used for user interaction
|
||||||
|
*/
|
||||||
public RoundControl(IGameState gameState, IView view) {
|
public RoundControl(IGameState gameState, IView view) {
|
||||||
this.gameState = gameState;
|
this.gameState = gameState;
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
@ -34,6 +45,9 @@ public class RoundControl {
|
||||||
return endRoundEvent;
|
return endRoundEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Begin the round
|
||||||
|
*/
|
||||||
public void startRound() {
|
public void startRound() {
|
||||||
deal();
|
deal();
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,9 @@ import jrummikub.util.IListener2;
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller for a single turn made by a human player
|
||||||
|
*/
|
||||||
public class TurnControl {
|
public class TurnControl {
|
||||||
private IHand hand;
|
private IHand hand;
|
||||||
private ITable table;
|
private ITable table;
|
||||||
|
@ -32,6 +35,17 @@ public class TurnControl {
|
||||||
private Event endOfTurnEvent = new Event();
|
private Event endOfTurnEvent = new Event();
|
||||||
private List<Connection> connections = new ArrayList<Connection>();
|
private List<Connection> connections = new ArrayList<Connection>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new TurnControl using a given hand (of the active player), a
|
||||||
|
* given table and a given view for user interaction.
|
||||||
|
*
|
||||||
|
* @param hand
|
||||||
|
* active player's hand
|
||||||
|
* @param table
|
||||||
|
* current table
|
||||||
|
* @param view
|
||||||
|
* view for user interaction.
|
||||||
|
*/
|
||||||
public TurnControl(IHand hand, ITable table, IView view) {
|
public TurnControl(IHand hand, ITable table, IView view) {
|
||||||
this.hand = hand;
|
this.hand = hand;
|
||||||
this.table = table;
|
this.table = table;
|
||||||
|
@ -47,6 +61,9 @@ public class TurnControl {
|
||||||
this.timer = testTimer;
|
this.timer = testTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the turn
|
||||||
|
*/
|
||||||
public void startTurn() {
|
public void startTurn() {
|
||||||
|
|
||||||
IListener endOfTurnListener = new IListener() {
|
IListener endOfTurnListener = new IListener() {
|
||||||
|
@ -408,6 +425,11 @@ public class TurnControl {
|
||||||
view.setSelectedStones(new ArrayList<Stone>());
|
view.setSelectedStones(new ArrayList<Stone>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the event that is emitted when the turn is over
|
||||||
|
*
|
||||||
|
* @return end of turn event
|
||||||
|
*/
|
||||||
public IEvent getEndOfTurnEvent() {
|
public IEvent getEndOfTurnEvent() {
|
||||||
return endOfTurnEvent;
|
return endOfTurnEvent;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,21 @@ import jrummikub.util.Event;
|
||||||
import jrummikub.util.IEvent;
|
import jrummikub.util.IEvent;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Count-down timer used to limit the turn time
|
||||||
|
*/
|
||||||
public class TurnTimer implements ActionListener, ITurnTimer {
|
public class TurnTimer implements ActionListener, ITurnTimer {
|
||||||
private IView view;
|
private IView view;
|
||||||
private int timeLeft = 60;
|
private int timeLeft = 60;
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
private Event timeRunOutEvent = new Event();
|
private Event timeRunOutEvent = new Event();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new timer using a given view to display the current time left
|
||||||
|
*
|
||||||
|
* @param view
|
||||||
|
* view to display
|
||||||
|
*/
|
||||||
public TurnTimer(IView view) {
|
public TurnTimer(IView view) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
timer = new Timer(1000, this);
|
timer = new Timer(1000, this);
|
||||||
|
@ -23,19 +32,16 @@ public class TurnTimer implements ActionListener, ITurnTimer {
|
||||||
view.getPlayerPanel().setTimeLeft(timeLeft);
|
view.getPlayerPanel().setTimeLeft(timeLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startTimer() {
|
public void startTimer() {
|
||||||
timer.start();
|
timer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stopTimer() {
|
public void stopTimer() {
|
||||||
timer.stop();
|
timer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
timeLeft--;
|
timeLeft--;
|
||||||
|
|
|
@ -11,6 +11,9 @@ public class GameState implements IGameState {
|
||||||
private int activePlayer;
|
private int activePlayer;
|
||||||
private StoneHeap gameHeap;
|
private StoneHeap gameHeap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new GameState with an empty table and (currntly) 4 new players.
|
||||||
|
*/
|
||||||
public GameState() {
|
public GameState() {
|
||||||
table = new Table();
|
table = new Table();
|
||||||
players = new ArrayList<Player>();
|
players = new ArrayList<Player>();
|
||||||
|
@ -37,7 +40,6 @@ public class GameState implements IGameState {
|
||||||
return players.size();
|
return players.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Changes the activePlayer to the next {@link Player} in the list */
|
|
||||||
@Override
|
@Override
|
||||||
public void nextPlayer() {
|
public void nextPlayer() {
|
||||||
activePlayer = (activePlayer + 1) % players.size();
|
activePlayer = (activePlayer + 1) % players.size();
|
||||||
|
|
|
@ -1,20 +1,56 @@
|
||||||
package jrummikub.model;
|
package jrummikub.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for {@link GameState} model
|
||||||
|
*/
|
||||||
public interface IGameState {
|
public interface IGameState {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current {@link Table}
|
||||||
|
*
|
||||||
|
* @return The current Table
|
||||||
|
*/
|
||||||
public ITable getTable();
|
public ITable getTable();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current {@link Table}
|
||||||
|
*
|
||||||
|
* @param table
|
||||||
|
* The new Table
|
||||||
|
*/
|
||||||
public void setTable(ITable table);
|
public void setTable(ITable table);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of players
|
||||||
|
*
|
||||||
|
* @return number of players
|
||||||
|
*/
|
||||||
public int getPlayerCount();
|
public int getPlayerCount();
|
||||||
|
|
||||||
/** Changes the activePlayer to the next {@link Player} in the list */
|
/** Changes the activePlayer to the next {@link Player} in the list */
|
||||||
public void nextPlayer();
|
public void nextPlayer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the currently active player
|
||||||
|
*
|
||||||
|
* @return currently active player
|
||||||
|
*/
|
||||||
public IPlayer getActivePlayer();
|
public IPlayer getActivePlayer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the heap of stones to draw from
|
||||||
|
*
|
||||||
|
* @return heap of stones
|
||||||
|
*/
|
||||||
public StoneHeap getGameHeap();
|
public StoneHeap getGameHeap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the player that would be the active player after i turns
|
||||||
|
*
|
||||||
|
* @param i
|
||||||
|
* number of turns
|
||||||
|
* @return player active after i turns
|
||||||
|
*/
|
||||||
public IPlayer getNthNextPlayer(int i);
|
public IPlayer getNthNextPlayer(int i);
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,5 +1,8 @@
|
||||||
package jrummikub.model;
|
package jrummikub.model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for the {@link Hand} model
|
||||||
|
*/
|
||||||
public interface IHand extends IStoneTray<Stone> {
|
public interface IHand extends IStoneTray<Stone> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,30 @@ package jrummikub.model;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for {@link Player} model
|
||||||
|
*/
|
||||||
public interface IPlayer {
|
public interface IPlayer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current hand of the player
|
||||||
|
*
|
||||||
|
* @return the player's hand
|
||||||
|
*/
|
||||||
public IHand getHand();
|
public IHand getHand();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the player's color
|
||||||
|
*
|
||||||
|
* @return the player's color
|
||||||
|
*/
|
||||||
public Color getColor();
|
public Color getColor();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the name of the player
|
||||||
|
*
|
||||||
|
* @return the player's name
|
||||||
|
*/
|
||||||
public String getName();
|
public String getName();
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,6 +2,12 @@ package jrummikub.model;
|
||||||
|
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for the {@link StoneTray} model
|
||||||
|
*
|
||||||
|
* @param <E>
|
||||||
|
* Objects held by the IStoneTray
|
||||||
|
*/
|
||||||
public interface IStoneTray<E extends Sizeable> extends
|
public interface IStoneTray<E extends Sizeable> extends
|
||||||
Iterable<Pair<E, Position>>, Cloneable {
|
Iterable<Pair<E, Position>>, Cloneable {
|
||||||
|
|
||||||
|
@ -9,7 +15,7 @@ public interface IStoneTray<E extends Sizeable> extends
|
||||||
* Removes object from tray and returns it
|
* Removes object from tray and returns it
|
||||||
*
|
*
|
||||||
* @param position
|
* @param position
|
||||||
* position of the object that will be removed
|
* position of the object that will be removed
|
||||||
* @return the picked up stone
|
* @return the picked up stone
|
||||||
*/
|
*/
|
||||||
public E pickUp(Position position);
|
public E pickUp(Position position);
|
||||||
|
@ -18,9 +24,9 @@ public interface IStoneTray<E extends Sizeable> extends
|
||||||
* Adds object to the tray
|
* Adds object to the tray
|
||||||
*
|
*
|
||||||
* @param object
|
* @param object
|
||||||
* object to add to Hand
|
* object to add to Hand
|
||||||
* @param position
|
* @param position
|
||||||
* {@link Position} to put the object
|
* {@link Position} to put the object
|
||||||
*/
|
*/
|
||||||
public void drop(E object, Position position);
|
public void drop(E object, Position position);
|
||||||
|
|
||||||
|
@ -28,15 +34,32 @@ public interface IStoneTray<E extends Sizeable> extends
|
||||||
* Returns the position of an object that is already on the tray
|
* Returns the position of an object that is already on the tray
|
||||||
*
|
*
|
||||||
* @param object
|
* @param object
|
||||||
* object whose position is requested
|
* object whose position is requested
|
||||||
* @return position of the object or null when the object is not on the tray
|
* @return position of the object or null when the object is not on the tray
|
||||||
*/
|
*/
|
||||||
public Position getPosition(E object);
|
public Position getPosition(E object);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tries to pick up (remove) a given object
|
||||||
|
*
|
||||||
|
* @param object
|
||||||
|
* object to pick up
|
||||||
|
* @return true when the object was successfully removed
|
||||||
|
*/
|
||||||
public boolean pickUp(E object);
|
public boolean pickUp(E object);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a clone of the StoneTray
|
||||||
|
*
|
||||||
|
* @return cloned StoneTray
|
||||||
|
*/
|
||||||
public IStoneTray<E> clone();
|
public IStoneTray<E> clone();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the number of objects on the tray
|
||||||
|
*
|
||||||
|
* @return number of objects
|
||||||
|
*/
|
||||||
public int getSize();
|
public int getSize();
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,20 +2,32 @@ package jrummikub.model;
|
||||||
|
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for the {@link Table} model
|
||||||
|
*/
|
||||||
public interface ITable extends IStoneTray<StoneSet> {
|
public interface ITable extends IStoneTray<StoneSet> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes {@link Stone} from the Table
|
* Removes {@link Stone} from the Table
|
||||||
*
|
*
|
||||||
* @param stone
|
* @param stone
|
||||||
* stone to pick up
|
* stone to pick up
|
||||||
* @return the stone sets that are created by taking pickung the the stone
|
* @return the stone sets that are created by taking pickung the the stone
|
||||||
*/
|
*/
|
||||||
public Pair<StoneSet, StoneSet> pickUpStone(Stone stone);
|
public Pair<StoneSet, StoneSet> pickUpStone(Stone stone);
|
||||||
|
|
||||||
/** Tests the Table for rule conflicts by checking all the {@link StoneSet} */
|
/**
|
||||||
|
* Tests the Table for rule conflicts by checking all the {@link StoneSet}
|
||||||
|
*
|
||||||
|
* @return whether all sets on the table are valid
|
||||||
|
*/
|
||||||
public boolean isValid();
|
public boolean isValid();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the {@link StoneSet} containing the given {@link Stone}
|
||||||
|
* @param stone stone whose set we're searching
|
||||||
|
* @return the set containing the stone or null if no set was found
|
||||||
|
*/
|
||||||
StoneSet findStoneSet(Stone stone);
|
StoneSet findStoneSet(Stone stone);
|
||||||
|
|
||||||
}
|
}
|
|
@ -9,8 +9,14 @@ public class Player implements IPlayer {
|
||||||
private String name;
|
private String name;
|
||||||
private Color color;
|
private Color color;
|
||||||
|
|
||||||
// private String name;
|
/**
|
||||||
|
* Create a new player with a given name and color
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* player name
|
||||||
|
* @param color
|
||||||
|
* player's color
|
||||||
|
*/
|
||||||
public Player(String name, Color color) {
|
public Player(String name, Color color) {
|
||||||
hand = new Hand();
|
hand = new Hand();
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
|
@ -2,5 +2,12 @@ package jrummikub.model;
|
||||||
|
|
||||||
/** Class specifying possible StoneColors */
|
/** Class specifying possible StoneColors */
|
||||||
public enum StoneColor {
|
public enum StoneColor {
|
||||||
BLACK, ORANGE, BLUE, RED
|
/** */
|
||||||
|
BLACK,
|
||||||
|
/** */
|
||||||
|
ORANGE,
|
||||||
|
/** */
|
||||||
|
BLUE,
|
||||||
|
/** */
|
||||||
|
RED
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class StoneHeap {
|
||||||
* Removes several {@link Stone}s from the heap and returns them
|
* Removes several {@link Stone}s from the heap and returns them
|
||||||
*
|
*
|
||||||
* @param number
|
* @param number
|
||||||
* number of requested Stones
|
* number of requested Stones
|
||||||
* @return list of drawn stones
|
* @return list of drawn stones
|
||||||
*/
|
*/
|
||||||
public List<Stone> drawStones(int number) {
|
public List<Stone> drawStones(int number) {
|
||||||
|
@ -54,10 +54,21 @@ public class StoneHeap {
|
||||||
return drawnStones;
|
return drawnStones;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of stones left
|
||||||
|
*
|
||||||
|
* @return number of stones on the heap
|
||||||
|
*/
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
return heap.size();
|
return heap.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put stones back on the heap
|
||||||
|
*
|
||||||
|
* @param stones
|
||||||
|
* collection of stones to put back
|
||||||
|
*/
|
||||||
public void putBack(Collection<Stone> stones) {
|
public void putBack(Collection<Stone> stones) {
|
||||||
heap.addAll(stones);
|
heap.addAll(stones);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,16 +18,34 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
|
||||||
static final float HORIZONTAL_BORDER = 0.125f;
|
static final float HORIZONTAL_BORDER = 0.125f;
|
||||||
private List<Stone> stones;
|
private List<Stone> stones;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new single stone stone set
|
||||||
|
*
|
||||||
|
* @param stone
|
||||||
|
* single stone of the set
|
||||||
|
*/
|
||||||
public StoneSet(Stone stone) {
|
public StoneSet(Stone stone) {
|
||||||
stones = Collections.singletonList(stone);
|
stones = Collections.singletonList(stone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a stone set from a list of stones
|
||||||
|
*
|
||||||
|
* @param stones
|
||||||
|
* list of stones to build a set of
|
||||||
|
*/
|
||||||
public StoneSet(List<Stone> stones) {
|
public StoneSet(List<Stone> stones) {
|
||||||
this.stones = new ArrayList<Stone>(stones);
|
this.stones = new ArrayList<Stone>(stones);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Validity type of the set */
|
||||||
public enum Type {
|
public enum Type {
|
||||||
GROUP, RUN, INVALID
|
/** Set is a valid group */
|
||||||
|
GROUP,
|
||||||
|
/** Set is a valid run */
|
||||||
|
RUN,
|
||||||
|
/** Set is invalid */
|
||||||
|
INVALID
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,8 +58,8 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for rule conflict within the StoneSet and determine whether the set is
|
* Test for rule conflict within the StoneSet and determine whether the set
|
||||||
* a group or a run
|
* is a group or a run
|
||||||
*
|
*
|
||||||
* @return GROUP or RUN for valid sets, INVALID otherwise
|
* @return GROUP or RUN for valid sets, INVALID otherwise
|
||||||
*/
|
*/
|
||||||
|
@ -62,13 +80,15 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
|
||||||
return GROUP;
|
return GROUP;
|
||||||
}
|
}
|
||||||
// is run
|
// is run
|
||||||
if (stones.get(nonJoker1).getColor() == stones.get(nonJoker2).getColor()) {
|
if (stones.get(nonJoker1).getColor() == stones.get(nonJoker2)
|
||||||
|
.getColor()) {
|
||||||
return isValidRun(nonJoker1) ? RUN : INVALID;
|
return isValidRun(nonJoker1) ? RUN : INVALID;
|
||||||
|
|
||||||
}
|
}
|
||||||
// is group
|
// is group
|
||||||
else {
|
else {
|
||||||
return isValidGroup(stones.get(nonJoker1).getValue()) ? GROUP : INVALID;
|
return isValidGroup(stones.get(nonJoker1).getValue()) ? GROUP
|
||||||
|
: INVALID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +96,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
|
||||||
* Test for rule conflict within the StoneSet, assuming we have a run
|
* Test for rule conflict within the StoneSet, assuming we have a run
|
||||||
*
|
*
|
||||||
* @param referencePosition
|
* @param referencePosition
|
||||||
* position of stone used as reference (any non-joker stone)
|
* position of stone used as reference (any non-joker stone)
|
||||||
*/
|
*/
|
||||||
private boolean isValidRun(int referencePosition) {
|
private boolean isValidRun(int referencePosition) {
|
||||||
StoneColor runColor = stones.get(referencePosition).getColor();
|
StoneColor runColor = stones.get(referencePosition).getColor();
|
||||||
|
@ -130,7 +150,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
|
||||||
* Stone Sets
|
* Stone Sets
|
||||||
*
|
*
|
||||||
* @param position
|
* @param position
|
||||||
* Splitting {@link Position}
|
* Splitting {@link Position}
|
||||||
* @return A pair of StoneSets, one for each split part
|
* @return A pair of StoneSets, one for each split part
|
||||||
*/
|
*/
|
||||||
public Pair<StoneSet, StoneSet> splitAt(int position) {
|
public Pair<StoneSet, StoneSet> splitAt(int position) {
|
||||||
|
@ -140,7 +160,8 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
|
||||||
return new Pair<StoneSet, StoneSet>(this, null);
|
return new Pair<StoneSet, StoneSet>(this, null);
|
||||||
}
|
}
|
||||||
StoneSet firstSet = new StoneSet(stones.subList(0, position));
|
StoneSet firstSet = new StoneSet(stones.subList(0, position));
|
||||||
StoneSet secondSet = new StoneSet(stones.subList(position, stones.size()));
|
StoneSet secondSet = new StoneSet(stones.subList(position,
|
||||||
|
stones.size()));
|
||||||
return new Pair<StoneSet, StoneSet>(firstSet, secondSet);
|
return new Pair<StoneSet, StoneSet>(firstSet, secondSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +169,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
|
||||||
* Joins StoneSet to another StoneSet and returns the resulting new StoneSet
|
* Joins StoneSet to another StoneSet and returns the resulting new StoneSet
|
||||||
*
|
*
|
||||||
* @param other
|
* @param other
|
||||||
* StoneSet to be joined to active StoneSet
|
* StoneSet to be joined to active StoneSet
|
||||||
* @return the combined StoneSet
|
* @return the combined StoneSet
|
||||||
*/
|
*/
|
||||||
public StoneSet join(StoneSet other) {
|
public StoneSet join(StoneSet other) {
|
||||||
|
@ -171,7 +192,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
|
||||||
* Returns the i-th stone of the set (starting with 0)
|
* Returns the i-th stone of the set (starting with 0)
|
||||||
*
|
*
|
||||||
* @param i
|
* @param i
|
||||||
* number of the stone to return
|
* number of the stone to return
|
||||||
* @return the i-th stone
|
* @return the i-th stone
|
||||||
*/
|
*/
|
||||||
public Stone get(int i) {
|
public Stone get(int i) {
|
||||||
|
|
|
@ -16,7 +16,19 @@ public interface IHandPanel extends IStonePanel, IClickable {
|
||||||
*/
|
*/
|
||||||
public void setStones(Iterable<Pair<Stone, Position>> stones);
|
public void setStones(Iterable<Pair<Stone, Position>> stones);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the number of stones that fit on the hand horizontally
|
||||||
|
*
|
||||||
|
* @param width
|
||||||
|
* number of stones
|
||||||
|
*/
|
||||||
public void setHandWidth(int width);
|
public void setHandWidth(int width);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the number of stones that fit on the hand vertically
|
||||||
|
*
|
||||||
|
* @param height
|
||||||
|
* number of stones
|
||||||
|
*/
|
||||||
public void setHandHeight(int height);
|
public void setHandHeight(int height);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,12 +26,18 @@ import jrummikub.view.MockView;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link RoundControl}
|
||||||
|
*/
|
||||||
public class RoundControlTest {
|
public class RoundControlTest {
|
||||||
private MockView view;
|
private MockView view;
|
||||||
private MockGameState testGameState;
|
private MockGameState testGameState;
|
||||||
private RoundControl testRound;
|
private RoundControl testRound;
|
||||||
private MockTable newTable;
|
private MockTable newTable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For each test create a round control initialized by a mock model and view
|
||||||
|
*/
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
view = new MockView();
|
view = new MockView();
|
||||||
|
@ -86,7 +92,7 @@ public class RoundControlTest {
|
||||||
view.displayStartTurnPanel = false;
|
view.displayStartTurnPanel = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO hier weitermachen
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testDealStone() {
|
public void testDealStone() {
|
||||||
testRound.deal();
|
testRound.deal();
|
||||||
|
@ -97,12 +103,14 @@ public class RoundControlTest {
|
||||||
assertEquals(28, testGameState.getActivePlayer().getHand().getSize());
|
assertEquals(28, testGameState.getActivePlayer().getHand().getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testDeal() {
|
public void testDeal() {
|
||||||
testRound.deal();
|
testRound.deal();
|
||||||
checkCorrectlyDealed();
|
checkCorrectlyDealed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testStartRound() {
|
public void testStartRound() {
|
||||||
testRound.startRound();
|
testRound.startRound();
|
||||||
|
@ -111,6 +119,7 @@ public class RoundControlTest {
|
||||||
checkTurnStartSetUp();
|
checkTurnStartSetUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testTableDisplay() {
|
public void testTableDisplay() {
|
||||||
testRound.startRound();
|
testRound.startRound();
|
||||||
|
@ -120,6 +129,7 @@ public class RoundControlTest {
|
||||||
view.getPlayerPanel().endTurnEvent.emit();
|
view.getPlayerPanel().endTurnEvent.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testTableValidHandChanged() {
|
public void testTableValidHandChanged() {
|
||||||
testRound.startRound();
|
testRound.startRound();
|
||||||
|
@ -139,6 +149,7 @@ public class RoundControlTest {
|
||||||
checkTurnStartSetUp();
|
checkTurnStartSetUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testTableInvalidHandChanged() {
|
public void testTableInvalidHandChanged() {
|
||||||
testRound.startRound();
|
testRound.startRound();
|
||||||
|
@ -160,6 +171,7 @@ public class RoundControlTest {
|
||||||
checkTurnStartSetUp();
|
checkTurnStartSetUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testTableValidHandUnchanged() {
|
public void testTableValidHandUnchanged() {
|
||||||
testRound.startRound();
|
testRound.startRound();
|
||||||
|
@ -179,6 +191,7 @@ public class RoundControlTest {
|
||||||
checkTurnStartSetUp();
|
checkTurnStartSetUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testTableInvalidHandUnchanged() {
|
public void testTableInvalidHandUnchanged() {
|
||||||
testRound.startRound();
|
testRound.startRound();
|
||||||
|
@ -198,6 +211,7 @@ public class RoundControlTest {
|
||||||
checkTurnStartSetUp();
|
checkTurnStartSetUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testWinning() {
|
public void testWinning() {
|
||||||
testRound.startRound();
|
testRound.startRound();
|
||||||
|
@ -217,6 +231,7 @@ public class RoundControlTest {
|
||||||
assertTrue(view.displayWinPanel);
|
assertTrue(view.displayWinPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testTableDifference() {
|
public void testTableDifference() {
|
||||||
MockTable oldTable = new MockTable();
|
MockTable oldTable = new MockTable();
|
||||||
|
|
|
@ -34,6 +34,9 @@ import jrummikub.view.MockView;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link TurnControl}
|
||||||
|
*/
|
||||||
public class TurnControlTest {
|
public class TurnControlTest {
|
||||||
static class AccessibleTable extends Table {
|
static class AccessibleTable extends Table {
|
||||||
StoneSet[] getSetArray() {
|
StoneSet[] getSetArray() {
|
||||||
|
@ -93,6 +96,7 @@ public class TurnControlTest {
|
||||||
assertFalse(stoneSetsModel.hasNext());
|
assertFalse(stoneSetsModel.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mockView = new MockView();
|
mockView = new MockView();
|
||||||
|
@ -102,6 +106,7 @@ public class TurnControlTest {
|
||||||
testControl = new TurnControl(mockHand, mockTable, mockView, mockTimer);
|
testControl = new TurnControl(mockHand, mockTable, mockView, mockTimer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void startTimer() {
|
public void startTimer() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -109,6 +114,7 @@ public class TurnControlTest {
|
||||||
assertTrue(mockTimer.timerRunning);
|
assertTrue(mockTimer.timerRunning);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void showInitialHand() {
|
public void showInitialHand() {
|
||||||
|
@ -134,6 +140,7 @@ public class TurnControlTest {
|
||||||
assertFalse(mockView.displayStartTurnPanel);
|
assertFalse(mockView.displayStartTurnPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void viewEndOfTurn() {
|
public void viewEndOfTurn() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -156,6 +163,7 @@ public class TurnControlTest {
|
||||||
assertTrue(mockView.playerPanel.endTurnEvent.listeners.isEmpty());
|
assertTrue(mockView.playerPanel.endTurnEvent.listeners.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void timerEndOfTurn() {
|
public void timerEndOfTurn() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -177,6 +185,7 @@ public class TurnControlTest {
|
||||||
assertFalse(mockTimer.timerRunning);
|
assertFalse(mockTimer.timerRunning);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void deselctOnEndOfTurn() {
|
public void deselctOnEndOfTurn() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -190,6 +199,7 @@ public class TurnControlTest {
|
||||||
assertCollection(new ArrayList<Stone>());
|
assertCollection(new ArrayList<Stone>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void selectStoneInHand() {
|
public void selectStoneInHand() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -209,6 +219,7 @@ public class TurnControlTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void collectStoneInHand() {
|
public void collectStoneInHand() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -232,6 +243,7 @@ public class TurnControlTest {
|
||||||
assertCollection(Arrays.asList(secondStone));
|
assertCollection(Arrays.asList(secondStone));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void deselectStoneInCollection() {
|
public void deselectStoneInCollection() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -248,6 +260,7 @@ public class TurnControlTest {
|
||||||
assertCollection(Arrays.asList(secondStone));
|
assertCollection(Arrays.asList(secondStone));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void reorderCollection() {
|
public void reorderCollection() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -264,6 +277,7 @@ public class TurnControlTest {
|
||||||
assertCollection(Arrays.asList(secondStone, firstStone));
|
assertCollection(Arrays.asList(secondStone, firstStone));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void deselectWholeCollection() {
|
public void deselectWholeCollection() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -283,6 +297,7 @@ public class TurnControlTest {
|
||||||
assertCollection(new ArrayList<Stone>());
|
assertCollection(new ArrayList<Stone>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void selectStoneOnTable() {
|
public void selectStoneOnTable() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -302,6 +317,7 @@ public class TurnControlTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void collectStoneOnTable() {
|
public void collectStoneOnTable() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -325,6 +341,7 @@ public class TurnControlTest {
|
||||||
assertCollection(Arrays.asList(secondStone));
|
assertCollection(Arrays.asList(secondStone));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void selectSetOnTable() {
|
public void selectSetOnTable() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -347,6 +364,7 @@ public class TurnControlTest {
|
||||||
assertCollection(Arrays.asList(stone3, stone4));
|
assertCollection(Arrays.asList(stone3, stone4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void collectSetOnTable() {
|
public void collectSetOnTable() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -369,6 +387,7 @@ public class TurnControlTest {
|
||||||
assertCollection(Arrays.asList(stone1, stone2, stone3, stone4));
|
assertCollection(Arrays.asList(stone1, stone2, stone3, stone4));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void rangeSelectOnTableReverse() {
|
public void rangeSelectOnTableReverse() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -389,6 +408,7 @@ public class TurnControlTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void rangeSelectOnTable() {
|
public void rangeSelectOnTable() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -409,6 +429,7 @@ public class TurnControlTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void rangeCollectOnTable() {
|
public void rangeCollectOnTable() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -432,6 +453,7 @@ public class TurnControlTest {
|
||||||
assertCollection(Arrays.asList(extraStone, stone1, stone2, stone3));
|
assertCollection(Arrays.asList(extraStone, stone1, stone2, stone3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void rangeFailSelect() {
|
public void rangeFailSelect() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -456,6 +478,7 @@ public class TurnControlTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void rangeFailCollect() {
|
public void rangeFailCollect() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -479,6 +502,7 @@ public class TurnControlTest {
|
||||||
assertCollection(Arrays.asList(stone1, stone2));
|
assertCollection(Arrays.asList(stone1, stone2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void rangeSelectOnHandReverse() {
|
public void rangeSelectOnHandReverse() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -498,6 +522,7 @@ public class TurnControlTest {
|
||||||
assertCollection(Arrays.asList(stone1, stone2, stone3));
|
assertCollection(Arrays.asList(stone1, stone2, stone3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void rangeSelectOnHand() {
|
public void rangeSelectOnHand() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -517,6 +542,7 @@ public class TurnControlTest {
|
||||||
assertCollection(Arrays.asList(stone1, stone2, stone3));
|
assertCollection(Arrays.asList(stone1, stone2, stone3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void rangeCollectOnHand() {
|
public void rangeCollectOnHand() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -539,6 +565,7 @@ public class TurnControlTest {
|
||||||
assertCollection(Arrays.asList(extraStone, stone1, stone2, stone3));
|
assertCollection(Arrays.asList(extraStone, stone1, stone2, stone3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void rangeFailSelectHand() {
|
public void rangeFailSelectHand() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -560,6 +587,7 @@ public class TurnControlTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void rangeFailCollectHand() {
|
public void rangeFailCollectHand() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -587,6 +615,7 @@ public class TurnControlTest {
|
||||||
assertEquals(expectedStones, selectedStones);
|
assertEquals(expectedStones, selectedStones);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testAddLeft() {
|
public void testAddLeft() {
|
||||||
AccessibleTable table = new AccessibleTable();
|
AccessibleTable table = new AccessibleTable();
|
||||||
|
@ -703,6 +732,7 @@ public class TurnControlTest {
|
||||||
assertSame(newSet2.get(5), blackFive);
|
assertSame(newSet2.get(5), blackFive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testAddRight() {
|
public void testAddRight() {
|
||||||
AccessibleTable table = new AccessibleTable();
|
AccessibleTable table = new AccessibleTable();
|
||||||
|
@ -819,6 +849,7 @@ public class TurnControlTest {
|
||||||
assertSame(newSet2.get(5), redThree);
|
assertSame(newSet2.get(5), redThree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testAddNewSet() {
|
public void testAddNewSet() {
|
||||||
AccessibleTable table = new AccessibleTable();
|
AccessibleTable table = new AccessibleTable();
|
||||||
|
@ -908,7 +939,7 @@ public class TurnControlTest {
|
||||||
checkTableDisplay(table);
|
checkTableDisplay(table);
|
||||||
checkHandDisplay(mockHand);
|
checkHandDisplay(mockHand);
|
||||||
}
|
}
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testSortByGroups() {
|
public void testSortByGroups() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -969,6 +1000,7 @@ public class TurnControlTest {
|
||||||
checkHandDisplay(mockHand);
|
checkHandDisplay(mockHand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testSortByRuns() {
|
public void testSortByRuns() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -1029,6 +1061,7 @@ public class TurnControlTest {
|
||||||
checkHandDisplay(mockHand);
|
checkHandDisplay(mockHand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testDropHandValid() {
|
public void testDropHandValid() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
@ -1056,7 +1089,7 @@ public class TurnControlTest {
|
||||||
}
|
}
|
||||||
assertEquals(expected, handStones);
|
assertEquals(expected, handStones);
|
||||||
}
|
}
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testDropHandInvalid() {
|
public void testDropHandInvalid() {
|
||||||
testControl.startTurn();
|
testControl.startTurn();
|
||||||
|
|
|
@ -6,15 +6,19 @@ import java.awt.Color;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
/**
|
||||||
|
* Test class for {@link GameState}
|
||||||
|
*/
|
||||||
public class GameStateTest {
|
public class GameStateTest {
|
||||||
private IGameState testGame;
|
private IGameState testGame;
|
||||||
|
|
||||||
|
/** */
|
||||||
@Before
|
@Before
|
||||||
public void createGame() {
|
public void createGame() {
|
||||||
testGame = new GameState();
|
testGame = new GameState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void nextActiveTest() {
|
public void nextActiveTest() {
|
||||||
// All there?
|
// All there?
|
||||||
|
|
|
@ -5,16 +5,20 @@ import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
/**
|
||||||
|
* Test class for {@link Hand}
|
||||||
|
*/
|
||||||
public class HandTest {
|
public class HandTest {
|
||||||
|
|
||||||
Hand hand;
|
Hand hand;
|
||||||
|
|
||||||
|
/** */
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
hand = new Hand();
|
hand = new Hand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleDrop() {
|
public void testSimpleDrop() {
|
||||||
Stone stone1 = new Stone(1, RED);
|
Stone stone1 = new Stone(1, RED);
|
||||||
|
@ -30,6 +34,7 @@ public class HandTest {
|
||||||
assertEquals(new Position(2.5f, 0), hand.getPosition(stone3));
|
assertEquals(new Position(2.5f, 0), hand.getPosition(stone3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testSingleEdgeDrop() {
|
public void testSingleEdgeDrop() {
|
||||||
Stone stone1 = new Stone(2, RED);
|
Stone stone1 = new Stone(2, RED);
|
||||||
|
@ -42,6 +47,7 @@ public class HandTest {
|
||||||
assertEquals(new Position(1, 0), hand.getPosition(stone2));
|
assertEquals(new Position(1, 0), hand.getPosition(stone2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testNearEdgeDrop() {
|
public void testNearEdgeDrop() {
|
||||||
Stone stone1 = new Stone(2, RED);
|
Stone stone1 = new Stone(2, RED);
|
||||||
|
@ -54,6 +60,7 @@ public class HandTest {
|
||||||
assertEquals(new Position(1, 0), hand.getPosition(stone2));
|
assertEquals(new Position(1, 0), hand.getPosition(stone2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testNearEdgeMiddleDrop() {
|
public void testNearEdgeMiddleDrop() {
|
||||||
Stone stone1 = new Stone(1, RED);
|
Stone stone1 = new Stone(1, RED);
|
||||||
|
@ -69,6 +76,7 @@ public class HandTest {
|
||||||
assertEquals(new Position(1, 0), hand.getPosition(stone3));
|
assertEquals(new Position(1, 0), hand.getPosition(stone3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testNearRightEdgeDrop() {
|
public void testNearRightEdgeDrop() {
|
||||||
Stone stone1 = new Stone(2, BLUE);
|
Stone stone1 = new Stone(2, BLUE);
|
||||||
|
@ -81,6 +89,7 @@ public class HandTest {
|
||||||
assertEquals(new Position(12, 1), hand.getPosition(stone2));
|
assertEquals(new Position(12, 1), hand.getPosition(stone2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testRightWrapDrop() {
|
public void testRightWrapDrop() {
|
||||||
Stone stone1 = new Stone(12, ORANGE);
|
Stone stone1 = new Stone(12, ORANGE);
|
||||||
|
@ -93,6 +102,7 @@ public class HandTest {
|
||||||
assertEquals(new Position(12.5f, 0), hand.getPosition(stone2));
|
assertEquals(new Position(12.5f, 0), hand.getPosition(stone2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testLeftWrapDrop() {
|
public void testLeftWrapDrop() {
|
||||||
Stone stone1 = new Stone(1, ORANGE);
|
Stone stone1 = new Stone(1, ORANGE);
|
||||||
|
|
|
@ -8,21 +8,29 @@ import java.util.Map;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link StoneHeap}
|
||||||
|
*/
|
||||||
public class StoneHeapTest {
|
public class StoneHeapTest {
|
||||||
private StoneHeap testHeap;
|
private StoneHeap testHeap;
|
||||||
|
|
||||||
|
/** */
|
||||||
@Before
|
@Before
|
||||||
public void createHeap() {
|
public void createHeap() {
|
||||||
testHeap = new StoneHeap();
|
testHeap = new StoneHeap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is the right number of Stones in heap?
|
/**
|
||||||
|
* Is the right number of Stones in heap?
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void fullStoneHeap() {
|
public void fullStoneHeap() {
|
||||||
assertEquals(106, testHeap.heap.size());
|
assertEquals(106, testHeap.heap.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enough stones of each color in heap?
|
/**
|
||||||
|
* Enough stones of each color in heap?
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void fullColor() {
|
public void fullColor() {
|
||||||
Map<StoneColor, Integer> counters = new HashMap<StoneColor, Integer>();
|
Map<StoneColor, Integer> counters = new HashMap<StoneColor, Integer>();
|
||||||
|
@ -40,7 +48,9 @@ public class StoneHeapTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enough Jokers?
|
/**
|
||||||
|
* Enough Jokers?
|
||||||
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void fullJoker() {
|
public void fullJoker() {
|
||||||
int countJoker = 0;
|
int countJoker = 0;
|
||||||
|
@ -51,14 +61,14 @@ public class StoneHeapTest {
|
||||||
assertEquals(2, countJoker);
|
assertEquals(2, countJoker);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw Stone Test
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void drawStoneTest() {
|
public void drawStoneTest() {
|
||||||
assertNotNull(testHeap.drawStone());
|
assertNotNull(testHeap.drawStone());
|
||||||
assertEquals(105, testHeap.heap.size());
|
assertEquals(105, testHeap.heap.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw Stones Test
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void drawStonesTest() {
|
public void drawStonesTest() {
|
||||||
List<Stone> testStones = testHeap.drawStones(5);
|
List<Stone> testStones = testHeap.drawStones(5);
|
||||||
|
|
|
@ -11,21 +11,25 @@ import static jrummikub.model.StoneSet.Type.*;
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link StoneSet}
|
||||||
|
*/
|
||||||
public class StoneSetTest {
|
public class StoneSetTest {
|
||||||
|
|
||||||
// Is Valid-Test
|
private void assertSet(StoneSet.Type expectedType, List<Stone> stones) {
|
||||||
// valid
|
|
||||||
public void assertSet(StoneSet.Type expectedType, List<Stone> stones) {
|
|
||||||
StoneSet set = new StoneSet(stones);
|
StoneSet set = new StoneSet(stones);
|
||||||
assertSame(expectedType, set.classify());
|
assertSame(expectedType, set.classify());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// valid
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void doubleJoker() {
|
public void doubleJoker() {
|
||||||
assertSet(GROUP,
|
assertSet(GROUP,
|
||||||
Arrays.asList(new Stone(RED), new Stone(BLACK), new Stone(1, BLACK)));
|
Arrays.asList(new Stone(RED), new Stone(BLACK), new Stone(1, BLACK)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void groups() {
|
public void groups() {
|
||||||
assertSet(GROUP, Arrays.asList(new Stone(1, RED), new Stone(1, BLACK),
|
assertSet(GROUP, Arrays.asList(new Stone(1, RED), new Stone(1, BLACK),
|
||||||
|
@ -34,6 +38,7 @@ public class StoneSetTest {
|
||||||
new Stone(1, BLUE), new Stone(1, ORANGE)));
|
new Stone(1, BLUE), new Stone(1, ORANGE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void runs() {
|
public void runs() {
|
||||||
assertSet(RUN,
|
assertSet(RUN,
|
||||||
|
@ -42,6 +47,7 @@ public class StoneSetTest {
|
||||||
new Stone(6, BLUE)));
|
new Stone(6, BLUE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void singleJoker() {
|
public void singleJoker() {
|
||||||
assertSet(GROUP,
|
assertSet(GROUP,
|
||||||
|
@ -51,17 +57,18 @@ public class StoneSetTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// invalid
|
// invalid
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void outOfBounds() {
|
public void outOfBounds() {
|
||||||
assertSet(INVALID,
|
assertSet(INVALID, Arrays.asList(new Stone(RED), new Stone(1, RED),
|
||||||
Arrays.asList(new Stone(RED), new Stone(1, RED), new Stone(2, RED)));
|
new Stone(2, RED)));
|
||||||
assertSet(INVALID,
|
assertSet(INVALID, Arrays.asList(new Stone(12, RED),
|
||||||
Arrays.asList(new Stone(12, RED), new Stone(13, RED), new Stone(RED)));
|
new Stone(13, RED), new Stone(RED)));
|
||||||
assertSet(INVALID, Arrays.asList(new Stone(RED), new Stone(BLACK),
|
assertSet(INVALID, Arrays.asList(new Stone(RED), new Stone(BLACK),
|
||||||
new Stone(1, RED), new Stone(2, RED)));
|
new Stone(1, RED), new Stone(2, RED)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void sameColor() {
|
public void sameColor() {
|
||||||
assertSet(INVALID,
|
assertSet(INVALID,
|
||||||
|
@ -70,6 +77,7 @@ public class StoneSetTest {
|
||||||
new Stone(1, BLACK), new Stone(1, ORANGE), new Stone(RED)));
|
new Stone(1, BLACK), new Stone(1, ORANGE), new Stone(RED)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void incorrectOrder() {
|
public void incorrectOrder() {
|
||||||
assertSet(INVALID,
|
assertSet(INVALID,
|
||||||
|
@ -80,6 +88,7 @@ public class StoneSetTest {
|
||||||
Arrays.asList(new Stone(4, RED), new Stone(RED), new Stone(5, RED)));
|
Arrays.asList(new Stone(4, RED), new Stone(RED), new Stone(5, RED)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void otherInvalid() {
|
public void otherInvalid() {
|
||||||
|
|
||||||
|
@ -91,11 +100,12 @@ public class StoneSetTest {
|
||||||
assertSet(INVALID,
|
assertSet(INVALID,
|
||||||
Arrays.asList(new Stone(4, BLUE), new Stone(5, RED), new Stone(6, RED)));
|
Arrays.asList(new Stone(4, BLUE), new Stone(5, RED), new Stone(6, RED)));
|
||||||
// Regression test:
|
// Regression test:
|
||||||
assertSet(INVALID, Arrays.asList(new Stone(12, ORANGE),
|
assertSet(INVALID, Arrays.asList(new Stone(12, ORANGE), new Stone(12,
|
||||||
new Stone(12, BLACK), new Stone(7, BLUE)));
|
BLACK), new Stone(7, BLUE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// invalid Split
|
// invalid Split
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testSplitInvalidLow() {
|
public void testSplitInvalidLow() {
|
||||||
StoneSet testSet = createTestSet();
|
StoneSet testSet = createTestSet();
|
||||||
|
@ -103,6 +113,7 @@ public class StoneSetTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testSplitInvalidHigh() {
|
public void testSplitInvalidHigh() {
|
||||||
StoneSet testSet = createTestSet();
|
StoneSet testSet = createTestSet();
|
||||||
|
@ -110,6 +121,7 @@ public class StoneSetTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// valid Split
|
// valid Split
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testSplitValid() {
|
public void testSplitValid() {
|
||||||
StoneSet testSet = createTestSet();
|
StoneSet testSet = createTestSet();
|
||||||
|
@ -133,6 +145,7 @@ public class StoneSetTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// join
|
// join
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testJoin() {
|
public void testJoin() {
|
||||||
StoneSet testSet = createTestSet();
|
StoneSet testSet = createTestSet();
|
||||||
|
@ -148,6 +161,7 @@ public class StoneSetTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterator
|
// iterator
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testIterator() {
|
public void testIterator() {
|
||||||
StoneSet testSet = createTestSet();
|
StoneSet testSet = createTestSet();
|
||||||
|
|
|
@ -7,7 +7,9 @@ import jrummikub.util.Pair;
|
||||||
|
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
/**
|
||||||
|
* Tests for {@link StoneTray}
|
||||||
|
*/
|
||||||
public class StoneTrayTest {
|
public class StoneTrayTest {
|
||||||
class Thing implements Sizeable {
|
class Thing implements Sizeable {
|
||||||
private float width;
|
private float width;
|
||||||
|
@ -30,12 +32,13 @@ public class StoneTrayTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private StoneTray<Thing> testTray;
|
private StoneTray<Thing> testTray;
|
||||||
|
/** */
|
||||||
@Before
|
@Before
|
||||||
public void createTray() {
|
public void createTray() {
|
||||||
testTray = new StoneTray<Thing>();
|
testTray = new StoneTray<Thing>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testDrop() {
|
public void testDrop() {
|
||||||
Thing firstThing = new Thing(3, 4);
|
Thing firstThing = new Thing(3, 4);
|
||||||
|
@ -50,6 +53,7 @@ public class StoneTrayTest {
|
||||||
assertEquals(8.5, secondPosition.getY(), 0.00001);
|
assertEquals(8.5, secondPosition.getY(), 0.00001);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testDropNull() {
|
public void testDropNull() {
|
||||||
testTray.drop(null, new Position(0, 0));
|
testTray.drop(null, new Position(0, 0));
|
||||||
|
@ -57,6 +61,7 @@ public class StoneTrayTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leftshift
|
// Leftshift
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testLeftDrop() {
|
public void testLeftDrop() {
|
||||||
Thing firstThing = new Thing(5, 5);
|
Thing firstThing = new Thing(5, 5);
|
||||||
|
@ -72,6 +77,7 @@ public class StoneTrayTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rightshift
|
// Rightshift
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testRightDrop() {
|
public void testRightDrop() {
|
||||||
Thing firstThing = new Thing(5, 5);
|
Thing firstThing = new Thing(5, 5);
|
||||||
|
@ -87,6 +93,7 @@ public class StoneTrayTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upshift
|
// Upshift
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testUpDrop() {
|
public void testUpDrop() {
|
||||||
Thing firstThing = new Thing(5, 5);
|
Thing firstThing = new Thing(5, 5);
|
||||||
|
@ -102,6 +109,7 @@ public class StoneTrayTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Downshift
|
// Downshift
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testDownDrop() {
|
public void testDownDrop() {
|
||||||
Thing firstThing = new Thing(5, 5);
|
Thing firstThing = new Thing(5, 5);
|
||||||
|
@ -116,6 +124,7 @@ public class StoneTrayTest {
|
||||||
assertEquals(-2, secondPosition.getY(), 0.00001);
|
assertEquals(-2, secondPosition.getY(), 0.00001);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testDoubleShift() {
|
public void testDoubleShift() {
|
||||||
Thing firstThing = new Thing(5, 5);
|
Thing firstThing = new Thing(5, 5);
|
||||||
|
@ -137,6 +146,7 @@ public class StoneTrayTest {
|
||||||
assertEquals(1, thirdPosition.getY(), 0.00001);
|
assertEquals(1, thirdPosition.getY(), 0.00001);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testWrongPickUp() {
|
public void testWrongPickUp() {
|
||||||
Thing firstThing = new Thing(5, 5);
|
Thing firstThing = new Thing(5, 5);
|
||||||
|
@ -145,6 +155,7 @@ public class StoneTrayTest {
|
||||||
assertNull(testTray.pickUp(testPosition));
|
assertNull(testTray.pickUp(testPosition));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testPickUpByObject() {
|
public void testPickUpByObject() {
|
||||||
Thing firstThing = new Thing(5, 5);
|
Thing firstThing = new Thing(5, 5);
|
||||||
|
@ -158,6 +169,7 @@ public class StoneTrayTest {
|
||||||
assertTrue(testTray.iterator().hasNext());
|
assertTrue(testTray.iterator().hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testRightPickUp() {
|
public void testRightPickUp() {
|
||||||
Thing firstThing = new Thing(5, 5);
|
Thing firstThing = new Thing(5, 5);
|
||||||
|
@ -169,6 +181,7 @@ public class StoneTrayTest {
|
||||||
assertNull(testTray.pickUp(testPosition));
|
assertNull(testTray.pickUp(testPosition));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testIterate() {
|
public void testIterate() {
|
||||||
List<Thing> testThings = new ArrayList<Thing>();
|
List<Thing> testThings = new ArrayList<Thing>();
|
||||||
|
@ -191,6 +204,7 @@ public class StoneTrayTest {
|
||||||
assertTrue(testPositions.isEmpty());
|
assertTrue(testPositions.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testClone() {
|
public void testClone() {
|
||||||
Thing firstThing = new Thing(5, 5);
|
Thing firstThing = new Thing(5, 5);
|
||||||
|
|
|
@ -12,22 +12,28 @@ import java.util.Arrays;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for {@link Table}
|
||||||
|
*/
|
||||||
public class TableTest {
|
public class TableTest {
|
||||||
Table testTable;
|
Table testTable;
|
||||||
|
|
||||||
|
/** */
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
testTable = new Table();
|
testTable = new Table();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testIsValid() {
|
public void testIsValid() {
|
||||||
testTable.drop(
|
testTable.drop(
|
||||||
new StoneSet(Arrays.asList(new Stone(RED), new Stone(BLACK), new Stone(
|
new StoneSet(Arrays.asList(new Stone(RED), new Stone(BLACK),
|
||||||
1, BLACK))), new Position(0, 0));
|
new Stone(1, BLACK))), new Position(0, 0));
|
||||||
testTable.drop(
|
testTable.drop(
|
||||||
new StoneSet(Arrays.asList(new Stone(1, RED), new Stone(2, RED),
|
new StoneSet(Arrays.asList(new Stone(1, RED),
|
||||||
new Stone(3, RED))), new Position(0, 0));
|
new Stone(2, RED), new Stone(3, RED))), new Position(0,
|
||||||
|
0));
|
||||||
assertTrue(testTable.isValid());
|
assertTrue(testTable.isValid());
|
||||||
|
|
||||||
testTable.drop(new StoneSet(Arrays.asList(new Stone(5, RED))),
|
testTable.drop(new StoneSet(Arrays.asList(new Stone(5, RED))),
|
||||||
|
@ -35,18 +41,20 @@ public class TableTest {
|
||||||
assertFalse(testTable.isValid());
|
assertFalse(testTable.isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testEmptyIsValid() {
|
public void testEmptyIsValid() {
|
||||||
assertTrue(testTable.isValid());
|
assertTrue(testTable.isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public void testPickUpStoneGroup() {
|
public void testPickUpStoneGroup() {
|
||||||
Stone targetStone = new Stone(BLACK);
|
Stone targetStone = new Stone(BLACK);
|
||||||
testTable.drop(
|
testTable.drop(
|
||||||
new StoneSet(Arrays.asList(new Stone(RED), targetStone, new Stone(1,
|
new StoneSet(Arrays.asList(new Stone(RED), targetStone,
|
||||||
BLACK))), new Position(0, 0));
|
new Stone(1, BLACK))), new Position(0, 0));
|
||||||
assertTrue(testTable.isValid());
|
assertTrue(testTable.isValid());
|
||||||
testTable.pickUpStone(targetStone);
|
testTable.pickUpStone(targetStone);
|
||||||
assertFalse(testTable.isValid());
|
assertFalse(testTable.isValid());
|
||||||
|
@ -58,6 +66,7 @@ public class TableTest {
|
||||||
assertEquals(1, counter);
|
assertEquals(1, counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testPickLonelyStone() {
|
public void testPickLonelyStone() {
|
||||||
Stone targetStone = new Stone(BLACK);
|
Stone targetStone = new Stone(BLACK);
|
||||||
|
@ -66,6 +75,7 @@ public class TableTest {
|
||||||
assertEquals(0, testTable.getSize());
|
assertEquals(0, testTable.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testPickStoneFromEmptyTable() {
|
public void testPickStoneFromEmptyTable() {
|
||||||
Stone targetStone = new Stone(BLACK);
|
Stone targetStone = new Stone(BLACK);
|
||||||
|
@ -73,6 +83,7 @@ public class TableTest {
|
||||||
assertEquals(0, testTable.getSize());
|
assertEquals(0, testTable.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testPickNonexistentStone() {
|
public void testPickNonexistentStone() {
|
||||||
Stone targetStone = new Stone(BLACK);
|
Stone targetStone = new Stone(BLACK);
|
||||||
|
@ -84,13 +95,14 @@ public class TableTest {
|
||||||
assertSame(testTable.findStoneSet(droppedStone), set);
|
assertSame(testTable.findStoneSet(droppedStone), set);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public void testPickUpStoneRun() {
|
public void testPickUpStoneRun() {
|
||||||
Stone targetStone = new Stone(BLACK);
|
Stone targetStone = new Stone(BLACK);
|
||||||
testTable.drop(
|
testTable.drop(
|
||||||
new StoneSet(Arrays.asList(new Stone(1, RED), targetStone, new Stone(3,
|
new StoneSet(Arrays.asList(new Stone(1, RED), targetStone,
|
||||||
RED))), new Position(0, 0));
|
new Stone(3, RED))), new Position(0, 0));
|
||||||
assertTrue(testTable.isValid());
|
assertTrue(testTable.isValid());
|
||||||
testTable.pickUpStone(targetStone);
|
testTable.pickUpStone(targetStone);
|
||||||
assertFalse(testTable.isValid());
|
assertFalse(testTable.isValid());
|
||||||
|
@ -102,6 +114,7 @@ public class TableTest {
|
||||||
assertEquals(2, counter);
|
assertEquals(2, counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testFindSet() {
|
public void testFindSet() {
|
||||||
Stone targetStone = new Stone(BLACK);
|
Stone targetStone = new Stone(BLACK);
|
||||||
|
|
|
@ -4,105 +4,112 @@ import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for {@link Event1}
|
||||||
|
*/
|
||||||
public class Event1Test {
|
public class Event1Test {
|
||||||
|
|
||||||
int fired, fired2;
|
int fired, fired2;
|
||||||
|
|
||||||
@Test
|
/** */
|
||||||
public void singleListener() {
|
@Test
|
||||||
fired = 0;
|
public void singleListener() {
|
||||||
Event1<Integer> testEvent = new Event1<Integer>();
|
fired = 0;
|
||||||
testEvent.add(new IListener1<Integer>() {
|
Event1<Integer> testEvent = new Event1<Integer>();
|
||||||
|
testEvent.add(new IListener1<Integer>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Integer n) {
|
public void handle(Integer n) {
|
||||||
fired += n;
|
fired += n;
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals(fired, 0);
|
assertEquals(fired, 0);
|
||||||
testEvent.emit(10);
|
testEvent.emit(10);
|
||||||
assertEquals(fired, 10);
|
assertEquals(fired, 10);
|
||||||
testEvent.emit(20);
|
testEvent.emit(20);
|
||||||
assertEquals(fired, 30);
|
assertEquals(fired, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
/** */
|
||||||
public void twoListeners() {
|
@Test
|
||||||
fired = 0;
|
public void twoListeners() {
|
||||||
fired2 = 0;
|
fired = 0;
|
||||||
Event1<Integer> testEvent = new Event1<Integer>();
|
fired2 = 0;
|
||||||
testEvent.add(new IListener1<Integer>() {
|
Event1<Integer> testEvent = new Event1<Integer>();
|
||||||
|
testEvent.add(new IListener1<Integer>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Integer n) {
|
public void handle(Integer n) {
|
||||||
fired += n;
|
fired += n;
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
testEvent.add(new IListener1<Integer>() {
|
testEvent.add(new IListener1<Integer>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Integer n) {
|
public void handle(Integer n) {
|
||||||
fired2 -= n;
|
fired2 -= n;
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals(fired, 0);
|
assertEquals(fired, 0);
|
||||||
assertEquals(fired2, 0);
|
assertEquals(fired2, 0);
|
||||||
testEvent.emit(5);
|
testEvent.emit(5);
|
||||||
assertEquals(fired, 5);
|
assertEquals(fired, 5);
|
||||||
assertEquals(fired2, -5);
|
assertEquals(fired2, -5);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
/** */
|
||||||
public void removeListener() {
|
@Test
|
||||||
fired = 0;
|
public void removeListener() {
|
||||||
Event1<Integer> testEvent = new Event1<Integer>();
|
fired = 0;
|
||||||
testEvent.add(new IListener1<Integer>() {
|
Event1<Integer> testEvent = new Event1<Integer>();
|
||||||
|
testEvent.add(new IListener1<Integer>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Integer n) {
|
public void handle(Integer n) {
|
||||||
fired += n;
|
fired += n;
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
IListener1<Integer> rem = new IListener1<Integer>() {
|
IListener1<Integer> rem = new IListener1<Integer>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Integer n) {
|
public void handle(Integer n) {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
testEvent.add(rem);
|
testEvent.add(rem);
|
||||||
testEvent.remove(rem);
|
testEvent.remove(rem);
|
||||||
testEvent.emit(10);
|
testEvent.emit(10);
|
||||||
assertEquals(fired, 10);
|
assertEquals(fired, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void removeListenerByConnection() {
|
|
||||||
fired = 0;
|
|
||||||
Event1<Integer> testEvent = new Event1<Integer>();
|
|
||||||
testEvent.add(new IListener1<Integer>() {
|
|
||||||
|
|
||||||
@Override
|
/** */
|
||||||
public void handle(Integer n) {
|
@Test
|
||||||
fired += n;
|
public void removeListenerByConnection() {
|
||||||
|
fired = 0;
|
||||||
|
Event1<Integer> testEvent = new Event1<Integer>();
|
||||||
|
testEvent.add(new IListener1<Integer>() {
|
||||||
|
|
||||||
}
|
@Override
|
||||||
});
|
public void handle(Integer n) {
|
||||||
IListener1<Integer> rem = new IListener1<Integer>() {
|
fired += n;
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public void handle(Integer n) {
|
});
|
||||||
fail();
|
IListener1<Integer> rem = new IListener1<Integer>() {
|
||||||
}
|
|
||||||
};
|
@Override
|
||||||
Connection connection = testEvent.add(rem);
|
public void handle(Integer n) {
|
||||||
connection.remove();
|
fail();
|
||||||
testEvent.emit(10);
|
}
|
||||||
assertEquals(fired, 10);
|
};
|
||||||
}
|
Connection connection = testEvent.add(rem);
|
||||||
|
connection.remove();
|
||||||
|
testEvent.emit(10);
|
||||||
|
assertEquals(fired, 10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,122 +4,129 @@ import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for {@link Event2}
|
||||||
|
*/
|
||||||
public class Event2Test {
|
public class Event2Test {
|
||||||
|
|
||||||
int fired, fired2, fired3, fired4;
|
int fired, fired2, fired3, fired4;
|
||||||
|
|
||||||
@Test
|
/** */
|
||||||
public void singleListener() {
|
@Test
|
||||||
fired = 0;
|
public void singleListener() {
|
||||||
fired2 = 0;
|
fired = 0;
|
||||||
Event2<Integer, Integer> testEvent = new Event2<Integer, Integer>();
|
fired2 = 0;
|
||||||
testEvent.add(new IListener2<Integer, Integer>() {
|
Event2<Integer, Integer> testEvent = new Event2<Integer, Integer>();
|
||||||
|
testEvent.add(new IListener2<Integer, Integer>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Integer n, Integer m) {
|
public void handle(Integer n, Integer m) {
|
||||||
fired += n;
|
fired += n;
|
||||||
fired2 += m;
|
fired2 += m;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals(fired, 0);
|
assertEquals(fired, 0);
|
||||||
assertEquals(fired2, 0);
|
assertEquals(fired2, 0);
|
||||||
testEvent.emit(10, 5);
|
testEvent.emit(10, 5);
|
||||||
assertEquals(fired, 10);
|
assertEquals(fired, 10);
|
||||||
assertEquals(fired2, 5);
|
assertEquals(fired2, 5);
|
||||||
testEvent.emit(20, 45);
|
testEvent.emit(20, 45);
|
||||||
assertEquals(fired, 30);
|
assertEquals(fired, 30);
|
||||||
assertEquals(fired2, 50);
|
assertEquals(fired2, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
/** */
|
||||||
public void twoListeners() {
|
@Test
|
||||||
fired = 0;
|
public void twoListeners() {
|
||||||
fired2 = 0;
|
fired = 0;
|
||||||
fired3 = 0;
|
fired2 = 0;
|
||||||
fired4 = 0;
|
fired3 = 0;
|
||||||
Event2<Integer, Integer> testEvent = new Event2<Integer, Integer>();
|
fired4 = 0;
|
||||||
testEvent.add(new IListener2<Integer, Integer>() {
|
Event2<Integer, Integer> testEvent = new Event2<Integer, Integer>();
|
||||||
|
testEvent.add(new IListener2<Integer, Integer>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Integer n, Integer m) {
|
public void handle(Integer n, Integer m) {
|
||||||
fired += n;
|
fired += n;
|
||||||
fired2 += m;
|
fired2 += m;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
testEvent.add(new IListener2<Integer, Integer>() {
|
testEvent.add(new IListener2<Integer, Integer>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Integer n, Integer m) {
|
public void handle(Integer n, Integer m) {
|
||||||
fired3 -= n;
|
fired3 -= n;
|
||||||
fired4 -= m;
|
fired4 -= m;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertEquals(fired, 0);
|
assertEquals(fired, 0);
|
||||||
assertEquals(fired2, 0);
|
assertEquals(fired2, 0);
|
||||||
assertEquals(fired3, 0);
|
assertEquals(fired3, 0);
|
||||||
assertEquals(fired4, 0);
|
assertEquals(fired4, 0);
|
||||||
testEvent.emit(5, 10);
|
testEvent.emit(5, 10);
|
||||||
assertEquals(fired, 5);
|
assertEquals(fired, 5);
|
||||||
assertEquals(fired2, 10);
|
assertEquals(fired2, 10);
|
||||||
assertEquals(fired3, -5);
|
assertEquals(fired3, -5);
|
||||||
assertEquals(fired4, -10);
|
assertEquals(fired4, -10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
/** */
|
||||||
public void removeListener() {
|
@Test
|
||||||
fired = 0;
|
public void removeListener() {
|
||||||
fired2 = 0;
|
fired = 0;
|
||||||
Event2<Integer, Integer> testEvent = new Event2<Integer, Integer>();
|
fired2 = 0;
|
||||||
testEvent.add(new IListener2<Integer, Integer>() {
|
Event2<Integer, Integer> testEvent = new Event2<Integer, Integer>();
|
||||||
|
testEvent.add(new IListener2<Integer, Integer>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Integer n, Integer m) {
|
public void handle(Integer n, Integer m) {
|
||||||
fired += n;
|
fired += n;
|
||||||
fired2 += m;
|
fired2 += m;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
IListener2<Integer, Integer> rem = new IListener2<Integer, Integer>() {
|
IListener2<Integer, Integer> rem = new IListener2<Integer, Integer>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Integer n, Integer m) {
|
public void handle(Integer n, Integer m) {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
assertEquals(fired, 0);
|
assertEquals(fired, 0);
|
||||||
assertEquals(fired2, 0);
|
assertEquals(fired2, 0);
|
||||||
testEvent.add(rem);
|
testEvent.add(rem);
|
||||||
testEvent.remove(rem);
|
testEvent.remove(rem);
|
||||||
testEvent.emit(10, 20);
|
testEvent.emit(10, 20);
|
||||||
assertEquals(fired, 10);
|
assertEquals(fired, 10);
|
||||||
assertEquals(fired2, 20);
|
assertEquals(fired2, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void removeListenerByConnection() {
|
|
||||||
fired = 0;
|
|
||||||
fired2 = 0;
|
|
||||||
Event2<Integer, Integer> testEvent = new Event2<Integer, Integer>();
|
|
||||||
testEvent.add(new IListener2<Integer, Integer>() {
|
|
||||||
|
|
||||||
@Override
|
/** */
|
||||||
public void handle(Integer n, Integer m) {
|
@Test
|
||||||
fired += n;
|
public void removeListenerByConnection() {
|
||||||
fired2 += m;
|
fired = 0;
|
||||||
}
|
fired2 = 0;
|
||||||
});
|
Event2<Integer, Integer> testEvent = new Event2<Integer, Integer>();
|
||||||
IListener2<Integer, Integer> rem = new IListener2<Integer, Integer>() {
|
testEvent.add(new IListener2<Integer, Integer>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Integer n, Integer m) {
|
public void handle(Integer n, Integer m) {
|
||||||
fail();
|
fired += n;
|
||||||
}
|
fired2 += m;
|
||||||
};
|
}
|
||||||
assertEquals(fired, 0);
|
});
|
||||||
assertEquals(fired2, 0);
|
IListener2<Integer, Integer> rem = new IListener2<Integer, Integer>() {
|
||||||
Connection connection = testEvent.add(rem);
|
|
||||||
connection.remove();
|
@Override
|
||||||
testEvent.emit(10, 20);
|
public void handle(Integer n, Integer m) {
|
||||||
assertEquals(fired, 10);
|
fail();
|
||||||
assertEquals(fired2, 20);
|
}
|
||||||
}
|
};
|
||||||
|
assertEquals(fired, 0);
|
||||||
|
assertEquals(fired2, 0);
|
||||||
|
Connection connection = testEvent.add(rem);
|
||||||
|
connection.remove();
|
||||||
|
testEvent.emit(10, 20);
|
||||||
|
assertEquals(fired, 10);
|
||||||
|
assertEquals(fired2, 20);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,13 @@ package jrummikub.util;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
/**
|
||||||
|
* Test class for {@link Event}
|
||||||
|
*/
|
||||||
public class EventTest {
|
public class EventTest {
|
||||||
boolean fired, fired2;
|
boolean fired, fired2;
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void singleListener() {
|
public void singleListener() {
|
||||||
fired = false;
|
fired = false;
|
||||||
|
@ -26,6 +29,7 @@ public class EventTest {
|
||||||
assertTrue(fired);
|
assertTrue(fired);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void twoListeners() {
|
public void twoListeners() {
|
||||||
fired = false;
|
fired = false;
|
||||||
|
@ -55,6 +59,7 @@ public class EventTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void removeListener() {
|
public void removeListener() {
|
||||||
fired = false;
|
fired = false;
|
||||||
|
@ -80,6 +85,7 @@ public class EventTest {
|
||||||
assertTrue(fired);
|
assertTrue(fired);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void removeListenerByConnection() {
|
public void removeListenerByConnection() {
|
||||||
fired = false;
|
fired = false;
|
||||||
|
|
Reference in a new issue