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