Cleaned up RoundControl tests
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@260 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
102299d0ff
commit
2446671f7a
10 changed files with 45 additions and 105 deletions
|
@ -1,34 +0,0 @@
|
||||||
package jrummikub.model;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.awt.Color;
|
|
||||||
|
|
||||||
public class MockGameSettings implements IGameSettings {
|
|
||||||
List<PlayerSettings> players = new ArrayList<PlayerSettings>();
|
|
||||||
int initialMeldThreshold;
|
|
||||||
|
|
||||||
public MockGameSettings() {
|
|
||||||
players.add(new PlayerSettings("Bennet", Color.BLUE));
|
|
||||||
players.add(new PlayerSettings("Matze", Color.BLACK));
|
|
||||||
players.add(new PlayerSettings("Ida", Color.RED));
|
|
||||||
players.add(new PlayerSettings("Jannis", Color.PINK));
|
|
||||||
initialMeldThreshold=30;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<PlayerSettings> getPlayerList() {
|
|
||||||
return players;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setInitialMeldThreshold(int value) {
|
|
||||||
initialMeldThreshold = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getInitialMeldThreshold() {
|
|
||||||
return initialMeldThreshold;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -19,7 +19,7 @@ public class MockRoundState implements IRoundState {
|
||||||
/** */
|
/** */
|
||||||
public StoneHeap gameHeap;
|
public StoneHeap gameHeap;
|
||||||
/** */
|
/** */
|
||||||
public IGameSettings gameSettings;
|
public GameSettings gameSettings;
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
public MockRoundState() {
|
public MockRoundState() {
|
||||||
|
@ -72,7 +72,7 @@ public class MockRoundState implements IRoundState {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IGameSettings getGameSettings() {
|
public GameSettings getGameSettings() {
|
||||||
return gameSettings;
|
return gameSettings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import javax.swing.UIManager;
|
||||||
|
|
||||||
import jrummikub.control.GameControl;
|
import jrummikub.control.GameControl;
|
||||||
import jrummikub.model.GameSettings;
|
import jrummikub.model.GameSettings;
|
||||||
import jrummikub.model.IGameSettings;
|
|
||||||
import jrummikub.model.PlayerSettings;
|
import jrummikub.model.PlayerSettings;
|
||||||
import jrummikub.view.impl.View;
|
import jrummikub.view.impl.View;
|
||||||
|
|
||||||
|
@ -29,7 +28,7 @@ public class JRummikub {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
IGameSettings gameSettings = new GameSettings();
|
GameSettings gameSettings = new GameSettings();
|
||||||
gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED));
|
gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED));
|
||||||
gameSettings.getPlayerList().add(
|
gameSettings.getPlayerList().add(
|
||||||
new PlayerSettings("Matthias", Color.YELLOW));
|
new PlayerSettings("Matthias", Color.YELLOW));
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package jrummikub.control;
|
package jrummikub.control;
|
||||||
|
|
||||||
import jrummikub.model.IGameSettings;
|
import jrummikub.model.GameSettings;
|
||||||
import jrummikub.model.RoundState;
|
import jrummikub.model.RoundState;
|
||||||
import jrummikub.util.IListener;
|
import jrummikub.util.IListener;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
|
@ -9,7 +9,7 @@ import jrummikub.view.IView;
|
||||||
* Controls a Game, at some point including all Rounds, starts new Rounds
|
* Controls a Game, at some point including all Rounds, starts new Rounds
|
||||||
*/
|
*/
|
||||||
public class GameControl {
|
public class GameControl {
|
||||||
private IGameSettings gameSettings;
|
private GameSettings gameSettings;
|
||||||
private IView view;
|
private IView view;
|
||||||
private RoundControl roundControl;
|
private RoundControl roundControl;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ public class GameControl {
|
||||||
* @param view
|
* @param view
|
||||||
* the view
|
* the view
|
||||||
*/
|
*/
|
||||||
public GameControl(IGameSettings gameSettings, IView view) {
|
public GameControl(GameSettings gameSettings, IView view) {
|
||||||
this.gameSettings = gameSettings;
|
this.gameSettings = gameSettings;
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
* The overall game settings
|
* The overall game settings
|
||||||
*/
|
*/
|
||||||
public class GameSettings implements IGameSettings {
|
public class GameSettings {
|
||||||
private List<PlayerSettings> players = new ArrayList<PlayerSettings>();
|
private List<PlayerSettings> players = new ArrayList<PlayerSettings>();
|
||||||
|
|
||||||
private int initialMeldThreshold;
|
private int initialMeldThreshold;
|
||||||
|
@ -18,26 +18,30 @@ public class GameSettings implements IGameSettings {
|
||||||
initialMeldThreshold = 30;
|
initialMeldThreshold = 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/**
|
||||||
* @see jrummikub.model.IGameSettings#getPlayerList()
|
* Returns the list containing the settings of all players
|
||||||
|
*
|
||||||
|
* @return the player settings list
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public List<PlayerSettings> getPlayerList() {
|
public List<PlayerSettings> getPlayerList() {
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/**
|
||||||
* @see jrummikub.model.IGameSettings#setInitialMeldThreshold(int)
|
* Sets the initial meld threshold
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
* the value to set
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void setInitialMeldThreshold(int value) {
|
public void setInitialMeldThreshold(int value) {
|
||||||
initialMeldThreshold = value;
|
initialMeldThreshold = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/**
|
||||||
* @see jrummikub.model.IGameSettings#getInitialMeldThreshold()
|
* Returns the initial meld threshold
|
||||||
|
*
|
||||||
|
* @return the threshold
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public int getInitialMeldThreshold() {
|
public int getInitialMeldThreshold() {
|
||||||
return initialMeldThreshold;
|
return initialMeldThreshold;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
package jrummikub.model;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface IGameSettings {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the list containing the settings of all players
|
|
||||||
*
|
|
||||||
* @return the player settings list
|
|
||||||
*/
|
|
||||||
public List<PlayerSettings> getPlayerList();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the initial meld threshold
|
|
||||||
*
|
|
||||||
* @param value
|
|
||||||
* the value to set
|
|
||||||
*/
|
|
||||||
public void setInitialMeldThreshold(int value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the initial meld threshold
|
|
||||||
*
|
|
||||||
* @return the threshold
|
|
||||||
*/
|
|
||||||
public int getInitialMeldThreshold();
|
|
||||||
|
|
||||||
}
|
|
|
@ -10,7 +10,7 @@ public interface IRoundState {
|
||||||
*
|
*
|
||||||
* @return The game settings
|
* @return The game settings
|
||||||
*/
|
*/
|
||||||
public IGameSettings getGameSettings();
|
public GameSettings getGameSettings();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current {@link Table}
|
* Get the current {@link Table}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import java.util.List;
|
||||||
|
|
||||||
/** Class managing the overall and momentary RoundState */
|
/** Class managing the overall and momentary RoundState */
|
||||||
public class RoundState implements IRoundState {
|
public class RoundState implements IRoundState {
|
||||||
private IGameSettings gameSettings;
|
private GameSettings gameSettings;
|
||||||
|
|
||||||
private ITable table;
|
private ITable table;
|
||||||
private List<Player> players;
|
private List<Player> players;
|
||||||
|
@ -18,7 +18,7 @@ public class RoundState implements IRoundState {
|
||||||
* @param gameSettings
|
* @param gameSettings
|
||||||
* the game settings
|
* the game settings
|
||||||
*/
|
*/
|
||||||
public RoundState(IGameSettings gameSettings) {
|
public RoundState(GameSettings gameSettings) {
|
||||||
this.gameSettings = gameSettings;
|
this.gameSettings = gameSettings;
|
||||||
|
|
||||||
table = new Table();
|
table = new Table();
|
||||||
|
@ -68,7 +68,7 @@ public class RoundState implements IRoundState {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IGameSettings getGameSettings() {
|
public GameSettings getGameSettings() {
|
||||||
return gameSettings;
|
return gameSettings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,18 +11,20 @@ import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import jrummikub.model.GameSettings;
|
||||||
import jrummikub.model.Hand;
|
import jrummikub.model.Hand;
|
||||||
import jrummikub.model.IHand;
|
import jrummikub.model.IHand;
|
||||||
import jrummikub.model.ITable;
|
import jrummikub.model.ITable;
|
||||||
import jrummikub.model.MockGameSettings;
|
|
||||||
import jrummikub.model.MockRoundState;
|
import jrummikub.model.MockRoundState;
|
||||||
import jrummikub.model.MockTable;
|
import jrummikub.model.MockTable;
|
||||||
|
import jrummikub.model.PlayerSettings;
|
||||||
import jrummikub.model.Position;
|
import jrummikub.model.Position;
|
||||||
import jrummikub.model.RoundState;
|
import jrummikub.model.RoundState;
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
|
@ -43,6 +45,10 @@ public class RoundControlTest {
|
||||||
private RoundControl testRound;
|
private RoundControl testRound;
|
||||||
private MockTable testTable;
|
private MockTable testTable;
|
||||||
|
|
||||||
|
private GameSettings gameSettings;
|
||||||
|
private RoundState roundState;
|
||||||
|
private RoundControl roundControl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For each test create a round control initialized by a mock model and view
|
* For each test create a round control initialized by a mock model and view
|
||||||
*/
|
*/
|
||||||
|
@ -56,6 +62,18 @@ public class RoundControlTest {
|
||||||
testTable = new MockTable();
|
testTable = new MockTable();
|
||||||
testTable.sets.add(testRoundState.table.sets.get(0));
|
testTable.sets.add(testRoundState.table.sets.get(0));
|
||||||
testRoundState.table.clonedTable = testTable;
|
testRoundState.table.clonedTable = testTable;
|
||||||
|
|
||||||
|
gameSettings = new GameSettings();
|
||||||
|
|
||||||
|
gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED));
|
||||||
|
gameSettings.getPlayerList().add(
|
||||||
|
new PlayerSettings("Matthias", Color.YELLOW));
|
||||||
|
gameSettings.getPlayerList().add(
|
||||||
|
new PlayerSettings("Jannis", Color.GREEN));
|
||||||
|
gameSettings.getPlayerList().add(
|
||||||
|
new PlayerSettings("Bennet", Color.BLACK));
|
||||||
|
roundState = new RoundState(gameSettings);
|
||||||
|
roundControl = new RoundControl(roundState, view);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkCorrectlyDealed() {
|
private void checkCorrectlyDealed() {
|
||||||
|
@ -104,9 +122,6 @@ public class RoundControlTest {
|
||||||
/** Threshold=30 */
|
/** Threshold=30 */
|
||||||
@Test
|
@Test
|
||||||
public void laidOutValidTooFew() {
|
public void laidOutValidTooFew() {
|
||||||
MockGameSettings gameSettings = new MockGameSettings();
|
|
||||||
RoundState roundState = new RoundState(gameSettings);
|
|
||||||
RoundControl roundControl = new RoundControl(roundState, view);
|
|
||||||
roundControl.startRound();
|
roundControl.startRound();
|
||||||
view.startTurnEvent.emit();
|
view.startTurnEvent.emit();
|
||||||
|
|
||||||
|
@ -137,9 +152,6 @@ public class RoundControlTest {
|
||||||
/** Threshold=30 */
|
/** Threshold=30 */
|
||||||
@Test
|
@Test
|
||||||
public void laidOutInvalidEnough() {
|
public void laidOutInvalidEnough() {
|
||||||
MockGameSettings gameSettings = new MockGameSettings();
|
|
||||||
RoundState roundState = new RoundState(gameSettings);
|
|
||||||
RoundControl roundControl = new RoundControl(roundState, view);
|
|
||||||
roundControl.startRound();
|
roundControl.startRound();
|
||||||
view.startTurnEvent.emit();
|
view.startTurnEvent.emit();
|
||||||
|
|
||||||
|
@ -184,9 +196,6 @@ public class RoundControlTest {
|
||||||
/** Threshold=30 */
|
/** Threshold=30 */
|
||||||
@Test
|
@Test
|
||||||
public void laidOutTooFewChangedTable() {
|
public void laidOutTooFewChangedTable() {
|
||||||
MockGameSettings gameSettings = new MockGameSettings();
|
|
||||||
RoundState roundState = new RoundState(gameSettings);
|
|
||||||
RoundControl roundControl = new RoundControl(roundState, view);
|
|
||||||
roundControl.startRound();
|
roundControl.startRound();
|
||||||
view.startTurnEvent.emit();
|
view.startTurnEvent.emit();
|
||||||
// Fake Turn to put stones on the table
|
// Fake Turn to put stones on the table
|
||||||
|
@ -254,9 +263,6 @@ public class RoundControlTest {
|
||||||
/** Threshold=30 */
|
/** Threshold=30 */
|
||||||
@Test
|
@Test
|
||||||
public void laidOutEnoughChangedTable() {
|
public void laidOutEnoughChangedTable() {
|
||||||
MockGameSettings gameSettings = new MockGameSettings();
|
|
||||||
RoundState roundState = new RoundState(gameSettings);
|
|
||||||
RoundControl roundControl = new RoundControl(roundState, view);
|
|
||||||
roundControl.startRound();
|
roundControl.startRound();
|
||||||
view.startTurnEvent.emit();
|
view.startTurnEvent.emit();
|
||||||
// Fake Turn to put stones on the table
|
// Fake Turn to put stones on the table
|
||||||
|
@ -326,9 +332,6 @@ public class RoundControlTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void laidOutJustChangedTable() {
|
public void laidOutJustChangedTable() {
|
||||||
MockGameSettings gameSettings = new MockGameSettings();
|
|
||||||
RoundState roundState = new RoundState(gameSettings);
|
|
||||||
RoundControl roundControl = new RoundControl(roundState, view);
|
|
||||||
roundControl.startRound();
|
roundControl.startRound();
|
||||||
view.startTurnEvent.emit();
|
view.startTurnEvent.emit();
|
||||||
// Fake Turn to put stones on the table
|
// Fake Turn to put stones on the table
|
||||||
|
@ -389,9 +392,6 @@ public class RoundControlTest {
|
||||||
/** Threshold=30 */
|
/** Threshold=30 */
|
||||||
@Test
|
@Test
|
||||||
public void laidOutValid() {
|
public void laidOutValid() {
|
||||||
MockGameSettings gameSettings = new MockGameSettings();
|
|
||||||
RoundState roundState = new RoundState(gameSettings);
|
|
||||||
RoundControl roundControl = new RoundControl(roundState, view);
|
|
||||||
roundControl.startRound();
|
roundControl.startRound();
|
||||||
view.startTurnEvent.emit();
|
view.startTurnEvent.emit();
|
||||||
// Fake Turn to put stones on the table
|
// Fake Turn to put stones on the table
|
||||||
|
|
|
@ -11,7 +11,7 @@ import org.junit.Test;
|
||||||
* Test class for {@link RoundState}
|
* Test class for {@link RoundState}
|
||||||
*/
|
*/
|
||||||
public class RoundStateTest {
|
public class RoundStateTest {
|
||||||
private IGameSettings settings = new GameSettings();
|
private GameSettings settings = new GameSettings();
|
||||||
private IRoundState testRound;
|
private IRoundState testRound;
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
|
|
Reference in a new issue