Tests für Sets mit mehr Farben, mehr Values, ...

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@332 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Ida Massow 2011-05-31 00:58:46 +02:00
parent d66d73ea8f
commit f22ff5f0f1
12 changed files with 308 additions and 186 deletions

View file

@ -78,22 +78,23 @@ public class RoundControl {
} }
private void prepareTurn() { private void prepareTurn() {
boolean isHuman = roundState.getActivePlayer().getPlayerSettings().getTurnControlType() == HUMAN; boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
.getTurnControlType() == HUMAN;
clonedTable = (ITable) roundState.getTable().clone(); clonedTable = (ITable) roundState.getTable().clone();
if (isHuman) { if (isHuman) {
view.enableStartTurnPanel(true); view.enableStartTurnPanel(true);
} else { } else {
view.enableThinkPanel(true); view.enableThinkPanel(true);
} }
view.getTablePanel().setStoneSets(clonedTable); view.getTablePanel().setStoneSets(clonedTable);
view.setCurrentPlayerName(roundState.getActivePlayer() view.setCurrentPlayerName(roundState.getActivePlayer()
.getPlayerSettings().getName()); .getPlayerSettings().getName());
view.setCurrentPlayerColor(roundState.getActivePlayer() view.setCurrentPlayerColor(roundState.getActivePlayer()
.getPlayerSettings().getColor()); .getPlayerSettings().getColor());
view.setHasLaidOut(roundState.getActivePlayer().getLaidOut()); view.setHasLaidOut(roundState.getActivePlayer().getLaidOut());
if (!isHuman) if (!isHuman)
startTurn(); startTurn();
} }
@ -101,7 +102,8 @@ public class RoundControl {
private void startTurn() { private void startTurn() {
if (turnControl != null) if (turnControl != null)
return; return;
boolean isHuman = roundState.getActivePlayer().getPlayerSettings().getTurnControlType() == HUMAN; boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
.getTurnControlType() == HUMAN;
boolean inspectOnly = roundState.getTurnNumber() < 1; boolean inspectOnly = roundState.getTurnNumber() < 1;
boolean mayRedeal = inspectOnly boolean mayRedeal = inspectOnly
&& roundState.getActivePlayer().getHand() && roundState.getActivePlayer().getHand()
@ -110,10 +112,11 @@ public class RoundControl {
if (isHuman) { if (isHuman) {
view.getPlayerPanel().setEndTurnMode(inspectOnly, mayRedeal); view.getPlayerPanel().setEndTurnMode(inspectOnly, mayRedeal);
} }
turnControl = TurnControlFactory.getFactory(roundState.getActivePlayer() turnControl = TurnControlFactory.getFactory(
.getPlayerSettings().getTurnControlType()).create(); roundState.getActivePlayer().getPlayerSettings()
turnControl.setup(roundState.getActivePlayer(), clonedTable, .getTurnControlType()).create();
view, inspectOnly, mayRedeal); turnControl.setup(roundState.getActivePlayer(), clonedTable, view,
inspectOnly, mayRedeal);
turnControl.getEndOfTurnEvent().add(new IListener() { turnControl.getEndOfTurnEvent().add(new IListener() {
@Override @Override
public void handle() { public void handle() {
@ -148,7 +151,8 @@ public class RoundControl {
int totalValue = 0; int totalValue = 0;
for (StoneSet set : newSets) { for (StoneSet set : newSets) {
totalValue += set.classify().getSecond(); totalValue += set.classify(roundState.getGameSettings())
.getSecond();
} }
return totalValue == 0 return totalValue == 0

View file

@ -23,7 +23,7 @@ public class RoundState implements IRoundState {
public RoundState(GameSettings gameSettings) { public RoundState(GameSettings gameSettings) {
this.gameSettings = gameSettings; this.gameSettings = gameSettings;
table = new Table(); table = new Table(gameSettings);
players = new ArrayList<Player>(); players = new ArrayList<Player>();
for (PlayerSettings playerSettings : gameSettings.getPlayerList()) { for (PlayerSettings playerSettings : gameSettings.getPlayerList()) {

View file

@ -9,5 +9,13 @@ public enum StoneColor {
/** */ /** */
BLUE, BLUE,
/** */ /** */
RED RED,
/** */
GREEN,
/** */
VIOLET,
/** */
BROWN,
/** */
WHITE
} }

View file

@ -3,7 +3,6 @@ package jrummikub.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@ -24,21 +23,25 @@ public class StoneHeap {
* */ * */
public StoneHeap(GameSettings gameSettings) { public StoneHeap(GameSettings gameSettings) {
heap = new ArrayList<Stone>(); heap = new ArrayList<Stone>();
for (int i = 1; i <= 13; i++) { for (int i = 1; i <= gameSettings.getHighestCard(); i++) {
for (int j = 0; j < gameSettings.getStoneSetNumber(); j++) { for (int j = 0; j < gameSettings.getStoneSetNumber(); j++) {
for (StoneColor c : EnumSet.allOf(StoneColor.class)) { for (StoneColor c : gameSettings.getStoneColors()) {
heap.add(new Stone(i, c)); heap.add(new Stone(i, c));
} }
} }
} }
// Joker // Joker
ArrayList<StoneColor> jokerColors = new ArrayList<StoneColor>(Arrays.asList(StoneColor.values())); ArrayList<StoneColor> jokerColors = new ArrayList<StoneColor>(
Arrays.asList(StoneColor.values()));
StoneColor temp = jokerColors.get(1); jokerColors.retainAll(gameSettings.getStoneColors());
jokerColors.set(1, jokerColors.get(3));
jokerColors.set(3, temp); if (jokerColors.size() >= 4) {
StoneColor temp = jokerColors.get(1);
jokerColors.set(1, jokerColors.get(3));
jokerColors.set(3, temp);
}
int jokersLeft = gameSettings.getJokerNumber(); int jokersLeft = gameSettings.getJokerNumber();
done: while (true) { done: while (true) {
for (StoneColor c : jokerColors) { for (StoneColor c : jokerColors) {

View file

@ -51,8 +51,8 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
* *
* @return true when the set is valid according to the rules * @return true when the set is valid according to the rules
*/ */
public boolean isValid() { public boolean isValid(GameSettings settings) {
return classify().getFirst() != INVALID; return classify(settings).getFirst() != INVALID;
} }
/** /**
@ -62,7 +62,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
* @return GROUP or RUN for valid sets, INVALID otherwise * @return GROUP or RUN for valid sets, INVALID otherwise
*/ */
public Pair<Type, Integer> classify() { public Pair<Type, Integer> classify(GameSettings settings) {
if (stones.size() < 3) { if (stones.size() < 3) {
return new Pair<Type, Integer>(INVALID, 0); return new Pair<Type, Integer>(INVALID, 0);
} }

View file

@ -5,6 +5,7 @@ import jrummikub.util.Pair;
/** Class administering the {@link Stone}s on the game-Table */ /** Class administering the {@link Stone}s on the game-Table */
public class Table extends StoneTray<StoneSet> implements ITable { public class Table extends StoneTray<StoneSet> implements ITable {
private GameSettings gameSettings;
private static class StoneInfo { private static class StoneInfo {
StoneSet set; StoneSet set;
@ -18,11 +19,15 @@ public class Table extends StoneTray<StoneSet> implements ITable {
} }
} }
public Table(GameSettings settings) {
gameSettings = settings;
}
/** /**
* Removes {@link Stone} from the Table * Removes {@link Stone} from the Table
* *
* @param stone * @param stone
* stone to pick up * stone to pick up
*/ */
@Override @Override
public void pickUpStone(Stone stone) { public void pickUpStone(Stone stone) {
@ -69,21 +74,21 @@ public class Table extends StoneTray<StoneSet> implements ITable {
return info.set; return info.set;
} }
private void splitSet(StoneSet set, Position setPosition, private void splitSet(StoneSet set, Position setPosition, int stonePosition) {
int stonePosition) {
pickUp(set); pickUp(set);
Pair<StoneSet, StoneSet> firstSplit = set.splitAt(stonePosition); Pair<StoneSet, StoneSet> firstSplit = set.splitAt(stonePosition);
Pair<StoneSet, StoneSet> secondSplit = firstSplit.getSecond().splitAt(1); Pair<StoneSet, StoneSet> secondSplit = firstSplit.getSecond()
.splitAt(1);
StoneSet leftSet = firstSplit.getFirst(); StoneSet leftSet = firstSplit.getFirst();
StoneSet rightSet = secondSplit.getSecond(); StoneSet rightSet = secondSplit.getSecond();
if (set.classify().getFirst() == StoneSet.Type.RUN) { if (set.classify(gameSettings).getFirst() == StoneSet.Type.RUN) {
Position leftPosition, rightPosition; Position leftPosition, rightPosition;
leftPosition = setPosition; leftPosition = setPosition;
rightPosition = new Position(setPosition.getX() + stonePosition + 1, rightPosition = new Position(
setPosition.getY()); setPosition.getX() + stonePosition + 1, setPosition.getY());
drop(leftSet, leftPosition); drop(leftSet, leftPosition);
drop(rightSet, rightPosition); drop(rightSet, rightPosition);
@ -105,7 +110,7 @@ public class Table extends StoneTray<StoneSet> implements ITable {
@Override @Override
public boolean isValid() { public boolean isValid() {
for (Pair<StoneSet, Position> i : this) { for (Pair<StoneSet, Position> i : this) {
if (!i.getFirst().isValid()) { if (!i.getFirst().isValid(gameSettings)) {
return false; return false;
} }
} }

View file

@ -60,7 +60,8 @@ class StonePainter {
int g = (int) (color.getGreen() * BRIGHTER_SCALE); int g = (int) (color.getGreen() * BRIGHTER_SCALE);
int b = (int) (color.getBlue() * BRIGHTER_SCALE); int b = (int) (color.getBlue() * BRIGHTER_SCALE);
return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b); return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255
: b);
} }
private static Color hover(Color color) { private static Color hover(Color color) {
@ -68,19 +69,28 @@ class StonePainter {
int g = (int) (color.getGreen() * HOVER_RATIO + 255 * (1 - HOVER_RATIO)); int g = (int) (color.getGreen() * HOVER_RATIO + 255 * (1 - HOVER_RATIO));
int b = (int) (color.getBlue() * HOVER_RATIO + 255 * (1 - HOVER_RATIO)); int b = (int) (color.getBlue() * HOVER_RATIO + 255 * (1 - HOVER_RATIO));
return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b); return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255
: b);
} }
private static Color getColor(StoneColor color) { private static Color getColor(StoneColor color) {
switch (color) { switch (color) {
case BLACK: case BLACK:
return new Color(0.15f, 0.15f, 0.15f); return new Color(0.15f, 0.15f, 0.15f);
case BLUE: case BLUE:
return new Color(0.0f, 0.0f, 1.0f); return new Color(0.0f, 0.0f, 1.0f);
case ORANGE: case ORANGE:
return new Color(1.0f, 0.4f, 0.0f); return new Color(1.0f, 0.4f, 0.0f);
case RED: case RED:
return new Color(0.9f, 0.0f, 0.25f); return new Color(0.9f, 0.0f, 0.25f);
case BROWN:
return new Color(0.5f, 0.25f, 0.0f);
case GREEN:
return new Color(0.0f, 0.75f, 0.0f);
case VIOLET:
return new Color(0.75f, 0.325f, 0.75f);
case WHITE:
return new Color(1.0f, 1.0f, 1.0f);
} }
return null; return null;
@ -90,7 +100,7 @@ class StonePainter {
* Sets the new grid scale * Sets the new grid scale
* *
* @param scale * @param scale
* the new scale * the new scale
*/ */
public void setScale(float scale) { public void setScale(float scale) {
this.scale = scale; this.scale = scale;
@ -104,9 +114,9 @@ class StonePainter {
/** /**
* @param x * @param x
* x position in screen coordinates * x position in screen coordinates
* @param y * @param y
* y position in screen coordinates * y position in screen coordinates
* @return position in grid coordinates * @return position in grid coordinates
*/ */
public Position calculatePosition(int x, int y) { public Position calculatePosition(int x, int y) {
@ -178,23 +188,29 @@ class StonePainter {
Color hoveredFg = hover(defaultFg); Color hoveredFg = hover(defaultFg);
Color hoveredSelectedFg = hover(selectedFg); Color hoveredSelectedFg = hover(selectedFg);
defaultStones.put(color, prepaintColor(defaultFg, defaultBackground)); defaultStones.put(color,
selectedStones.put(color, prepaintColor(selectedFg, selectedBackground)); prepaintColor(defaultFg, defaultBackground));
hoveredStones.put(color, prepaintColor(hoveredFg, hoveredBackground)); selectedStones.put(color,
hoveredSelectedStones.put(color, prepaintColor(selectedFg, selectedBackground));
prepaintColor(hoveredSelectedFg, hoveredSelectedBackground)); hoveredStones.put(color,
prepaintColor(hoveredFg, hoveredBackground));
hoveredSelectedStones
.put(color,
prepaintColor(hoveredSelectedFg,
hoveredSelectedBackground));
} }
} }
/** /**
* @param scale * @param scale
* the scaling factor for the grid coordinates * the scaling factor for the grid coordinates
*/ */
StonePainter(float scale) { StonePainter(float scale) {
setScale(scale); setScale(scale);
} }
private void paintStoneBackground(Graphics2D g, Rectangle r, Color background) { private void paintStoneBackground(Graphics2D g, Rectangle r,
Color background) {
// Paint background // Paint background
g.setColor(background); g.setColor(background);
g.fillRect(r.x, r.y, r.width, r.height); g.fillRect(r.x, r.y, r.width, r.height);
@ -294,8 +310,9 @@ class StonePainter {
pos + (fm.getAscent() - fm.getDescent()) / 2 + 1); pos + (fm.getAscent() - fm.getDescent()) / 2 + 1);
} }
g.setColor(color); g.setColor(color);
g.drawString(value, (int) (r.x + r.width / 2 - stringRect.getWidth() / 2), g.drawString(value,
pos + (fm.getAscent() - fm.getDescent()) / 2); (int) (r.x + r.width / 2 - stringRect.getWidth() / 2), pos
+ (fm.getAscent() - fm.getDescent()) / 2);
} }
private void paintCircle(Graphics2D g, Rectangle r, Color background) { private void paintCircle(Graphics2D g, Rectangle r, Color background) {
@ -304,26 +321,27 @@ class StonePainter {
// Paint circle // Paint circle
g.setColor(background.darker()); g.setColor(background.darker());
g.drawArc(r.x + r.width / 2 - size / 2, pos - size / 2, size, size, 50, 170); g.drawArc(r.x + r.width / 2 - size / 2, pos - size / 2, size, size, 50,
170);
g.setColor(brighter(background)); g.setColor(brighter(background));
g.drawArc((int) (r.x + r.width / 2 - size / 2), pos - size / 2, size, size, g.drawArc((int) (r.x + r.width / 2 - size / 2), pos - size / 2, size,
-130, 170); size, -130, 170);
} }
/** /**
* Paints a stone * Paints a stone
* *
* @param g * @param g
* the graphics context to paint the stone on * the graphics context to paint the stone on
* @param stone * @param stone
* the stone to paint * the stone to paint
* @param p * @param p
* the position of the stone * the position of the stone
* @param selected * @param selected
* if selected is true the stone will be painted darker * if selected is true the stone will be painted darker
* @param hovered * @param hovered
* if hovered is true the stone will be painted brighter * if hovered is true the stone will be painted brighter
*/ */
public void paintStone(Graphics2D g, Stone stone, Position p, public void paintStone(Graphics2D g, Stone stone, Position p,
boolean selected, boolean hovered) { boolean selected, boolean hovered) {
@ -350,8 +368,8 @@ class StonePainter {
if (stone.isJoker()) { if (stone.isJoker()) {
g.drawImage(stoneMap.get(stone.getColor()).get(0), x, y, null); g.drawImage(stoneMap.get(stone.getColor()).get(0), x, y, null);
} else { } else {
g.drawImage(stoneMap.get(stone.getColor()).get(stone.getValue()), x, y, g.drawImage(stoneMap.get(stone.getColor()).get(stone.getValue()),
null); x, y, null);
} }
} }
} }

View file

@ -70,8 +70,10 @@ public class RoundControlTest {
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));
gameSettings.getPlayerList().add(new PlayerSettings("Jannis", Color.GREEN)); gameSettings.getPlayerList().add(
gameSettings.getPlayerList().add(new PlayerSettings("Bennet", Color.BLACK)); new PlayerSettings("Jannis", Color.GREEN));
gameSettings.getPlayerList().add(
new PlayerSettings("Bennet", Color.BLACK));
roundState = new RoundState(gameSettings); roundState = new RoundState(gameSettings);
roundControl = new RoundControl(roundState, view); roundControl = new RoundControl(roundState, view);
} }
@ -81,7 +83,8 @@ public class RoundControlTest {
- testRoundState.table.getSize(), testRoundState.getGameHeap() - testRoundState.table.getSize(), testRoundState.getGameHeap()
.getSize()); .getSize());
for (int i = 0; i < testRoundState.getPlayerCount(); i++) { for (int i = 0; i < testRoundState.getPlayerCount(); i++) {
assertEquals(14, testRoundState.getNthNextPlayer(i).getHand().getSize()); assertEquals(14, testRoundState.getNthNextPlayer(i).getHand()
.getSize());
} }
} }
@ -142,8 +145,8 @@ public class RoundControlTest {
view.tablePanel.clickEvent.emit(new Position(0, 0)); view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) assertFalse(roundState
.getLaidOut()); .getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
assertEquals(0, roundState.getTable().getSize()); assertEquals(0, roundState.getTable().getSize());
assertEquals(14 + 6, hand.getSize()); assertEquals(14 + 6, hand.getSize());
} }
@ -163,8 +166,8 @@ public class RoundControlTest {
assertFalse(roundState.getActivePlayer().getLaidOut()); assertFalse(roundState.getActivePlayer().getLaidOut());
view.playerPanel.endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) assertFalse(roundState
.getLaidOut()); .getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
assertEquals(0, roundState.getTable().getSize()); assertEquals(0, roundState.getTable().getSize());
assertEquals(14 + 1, hand.getSize()); assertEquals(14 + 1, hand.getSize());
} }
@ -211,8 +214,8 @@ public class RoundControlTest {
view.tablePanel.clickEvent.emit(new Position(0, 0)); view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) assertFalse(roundState
.getLaidOut()); .getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
assertEquals(0, roundState.getTable().getSize()); assertEquals(0, roundState.getTable().getSize());
assertEquals(14 + 9, hand.getSize()); assertEquals(14 + 9, hand.getSize());
} }
@ -282,8 +285,8 @@ public class RoundControlTest {
view.tablePanel.clickEvent.emit(new Position(0, 0)); view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) assertFalse(roundState
.getLaidOut()); .getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
assertEquals(2, roundState.getTable().getSize()); assertEquals(2, roundState.getTable().getSize());
assertEquals(14 + 6, hand.getSize()); assertEquals(14 + 6, hand.getSize());
} }
@ -356,8 +359,8 @@ public class RoundControlTest {
view.tablePanel.clickEvent.emit(new Position(0, 0)); view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) assertFalse(roundState
.getLaidOut()); .getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
assertEquals(2, roundState.getTable().getSize()); assertEquals(2, roundState.getTable().getSize());
assertEquals(14 + 7, hand.getSize()); assertEquals(14 + 7, hand.getSize());
} }
@ -420,8 +423,8 @@ public class RoundControlTest {
view.tablePanel.clickEvent.emit(new Position(0, 0)); view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1) assertFalse(roundState
.getLaidOut()); .getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
assertEquals(2, roundState.getTable().getSize()); assertEquals(2, roundState.getTable().getSize());
assertEquals(14 + 3, hand.getSize()); assertEquals(14 + 3, hand.getSize());
} }
@ -679,12 +682,15 @@ public class RoundControlTest {
Stone blueTwo = new Stone(2, BLUE); Stone blueTwo = new Stone(2, BLUE);
Stone blueThree = new Stone(3, BLUE); Stone blueThree = new Stone(3, BLUE);
Stone blueFour = new Stone(4, BLUE); Stone blueFour = new Stone(4, BLUE);
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne)); StoneSet oldSet1 = new StoneSet(
Arrays.asList(blueOne, redOne, blackOne));
StoneSet oldSet2 = new StoneSet(blueTwo); StoneSet oldSet2 = new StoneSet(blueTwo);
oldTable.drop(oldSet1, new Position(0, 0)); oldTable.drop(oldSet1, new Position(0, 0));
oldTable.drop(oldSet2, new Position(0, 0)); oldTable.drop(oldSet2, new Position(0, 0));
StoneSet newSet1 = new StoneSet(Arrays.asList(blueOne, blueTwo, blueFour)); StoneSet newSet1 = new StoneSet(Arrays.asList(blueOne, blueTwo,
StoneSet newSet2 = new StoneSet(Arrays.asList(redOne, blackOne, blueThree)); blueFour));
StoneSet newSet2 = new StoneSet(Arrays.asList(redOne, blackOne,
blueThree));
newTable.drop(newSet1, new Position(0, 0)); newTable.drop(newSet1, new Position(0, 0));
newTable.drop(newSet2, new Position(0, 0)); newTable.drop(newSet2, new Position(0, 0));
@ -701,7 +707,7 @@ public class RoundControlTest {
/** */ /** */
@Test @Test
public void testTableSetDifference() { public void testTableSetDifference() {
ITable oldTable = new Table(); ITable oldTable = new Table(gameSettings);
Stone blueOne = new Stone(1, BLUE); Stone blueOne = new Stone(1, BLUE);
Stone redOne = new Stone(1, RED); Stone redOne = new Stone(1, RED);
Stone blackOne = new Stone(1, BLACK); Stone blackOne = new Stone(1, BLACK);
@ -709,14 +715,15 @@ public class RoundControlTest {
Stone blueTwo = new Stone(2, BLUE); Stone blueTwo = new Stone(2, BLUE);
Stone blueThree = new Stone(3, BLUE); Stone blueThree = new Stone(3, BLUE);
Stone blueFour = new Stone(4, BLUE); Stone blueFour = new Stone(4, BLUE);
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne, StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
orangeOne)); blackOne, orangeOne));
StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blueThree, blueFour)); StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blueThree,
blueFour));
oldTable.drop(oldSet1, new Position(0, 0)); oldTable.drop(oldSet1, new Position(0, 0));
oldTable.drop(oldSet2, new Position(0, 0)); oldTable.drop(oldSet2, new Position(0, 0));
ITable newTable = (Table) oldTable.clone(); ITable newTable = (Table) oldTable.clone();
List<StoneSet> newSets = RoundControl List<StoneSet> newSets = RoundControl.tableSetDifference(oldTable,
.tableSetDifference(oldTable, newTable); newTable);
List<StoneSet> vanishedSets = RoundControl.tableSetDifference(newTable, List<StoneSet> vanishedSets = RoundControl.tableSetDifference(newTable,
oldTable); oldTable);
@ -724,8 +731,8 @@ public class RoundControlTest {
assertTrue(vanishedSets.isEmpty()); assertTrue(vanishedSets.isEmpty());
newTable.pickUp(oldSet2); newTable.pickUp(oldSet2);
newTable.drop(oldSet2.join(new StoneSet(new Stone(5, BLUE))), new Position( newTable.drop(oldSet2.join(new StoneSet(new Stone(5, BLUE))),
0, 0)); new Position(0, 0));
newSets = RoundControl.tableSetDifference(oldTable, newTable); newSets = RoundControl.tableSetDifference(oldTable, newTable);
vanishedSets = RoundControl.tableSetDifference(newTable, oldTable); vanishedSets = RoundControl.tableSetDifference(newTable, oldTable);
@ -737,7 +744,8 @@ public class RoundControlTest {
Stone redTwo = new Stone(2, RED); Stone redTwo = new Stone(2, RED);
Stone redThree = new Stone(3, RED); Stone redThree = new Stone(3, RED);
Stone redFour = new Stone(4, RED); Stone redFour = new Stone(4, RED);
StoneSet oldSet3 = new StoneSet(Arrays.asList(redTwo, redThree, redFour)); StoneSet oldSet3 = new StoneSet(
Arrays.asList(redTwo, redThree, redFour));
ITable newTable2 = (Table) oldTable.clone(); ITable newTable2 = (Table) oldTable.clone();
newTable2.drop(oldSet3, new Position(0, 0)); newTable2.drop(oldSet3, new Position(0, 0));
newSets = RoundControl.tableSetDifference(oldTable, newTable2); newSets = RoundControl.tableSetDifference(oldTable, newTable2);
@ -799,19 +807,20 @@ public class RoundControlTest {
} }
testRoundState.players.get(0).laidOut = true; testRoundState.players.get(0).laidOut = true;
testRoundState.players.get(0).hand.drop(new Stone(1, RED), new Position(0, testRoundState.players.get(0).hand.drop(new Stone(1, RED),
0)); new Position(0, 0));
testRoundState.players.get(0).hand.drop(new Stone(2, RED), new Position(0, testRoundState.players.get(0).hand.drop(new Stone(2, RED),
0)); new Position(0, 0));
testRoundState.players.get(1).laidOut = true; testRoundState.players.get(1).laidOut = true;
testRoundState.players.get(1).hand.drop(new Stone(RED), new Position(0, 0)); testRoundState.players.get(1).hand.drop(new Stone(RED), new Position(0,
0));
testRoundState.players.get(2).laidOut = false; testRoundState.players.get(2).laidOut = false;
testRoundState.players.get(2).hand.drop(new Stone(9, RED), new Position(0, testRoundState.players.get(2).hand.drop(new Stone(9, RED),
0)); new Position(0, 0));
testRoundState.players.get(2).hand.drop(new Stone(10, RED), new Position(0, testRoundState.players.get(2).hand.drop(new Stone(10, RED),
0)); new Position(0, 0));
testRoundState.players.get(2).hand.drop(new Stone(11, RED), new Position(0, testRoundState.players.get(2).hand.drop(new Stone(11, RED),
0)); new Position(0, 0));
testRoundState.players.get(3).laidOut = true; testRoundState.players.get(3).laidOut = true;
testRound.endOfRound(); testRound.endOfRound();
@ -845,19 +854,19 @@ public class RoundControlTest {
} }
testRoundState.players.get(0).laidOut = true; testRoundState.players.get(0).laidOut = true;
testRoundState.players.get(0).hand.drop(new Stone(1, RED), new Position(0, testRoundState.players.get(0).hand.drop(new Stone(1, RED),
0)); new Position(0, 0));
testRoundState.players.get(0).hand.drop(new Stone(2, RED), new Position(0, testRoundState.players.get(0).hand.drop(new Stone(2, RED),
0)); new Position(0, 0));
testRoundState.players.get(1).laidOut = true; testRoundState.players.get(1).laidOut = true;
testRoundState.players.get(1).hand.drop(new Stone(3, RED), new Position(0, testRoundState.players.get(1).hand.drop(new Stone(3, RED),
0)); new Position(0, 0));
testRoundState.players.get(2).laidOut = true; testRoundState.players.get(2).laidOut = true;
testRoundState.players.get(2).hand.drop(new Stone(3, BLUE), new Position(0, testRoundState.players.get(2).hand.drop(new Stone(3, BLUE),
0)); new Position(0, 0));
testRoundState.players.get(3).laidOut = false; testRoundState.players.get(3).laidOut = false;
testRoundState.players.get(3).hand.drop(new Stone(13, RED), new Position(0, testRoundState.players.get(3).hand.drop(new Stone(13, RED),
0)); new Position(0, 0));
testRound.endOfRound(); testRound.endOfRound();
assertTrue(roundEnded); assertTrue(roundEnded);
@ -905,7 +914,7 @@ public class RoundControlTest {
view.playerPanel.redealEvent.emit(); view.playerPanel.redealEvent.emit();
assertTrue(roundRestarted); assertTrue(roundRestarted);
} }
/** */ /** */
@Test @Test
public void testRedealDisallowed() { public void testRedealDisallowed() {
@ -924,7 +933,7 @@ public class RoundControlTest {
} }
assertFalse(view.playerPanel.inspectOnly); assertFalse(view.playerPanel.inspectOnly);
} }
/** */ /** */
@Test @Test
public void testRedealAllowed() { public void testRedealAllowed() {

View file

@ -17,7 +17,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import jrummikub.control.ITurnTimer; import jrummikub.control.ITurnTimer;
import jrummikub.control.turn.HumanTurnControl; import jrummikub.model.GameSettings;
import jrummikub.model.IHand; import jrummikub.model.IHand;
import jrummikub.model.ITable; import jrummikub.model.ITable;
import jrummikub.model.MockHand; import jrummikub.model.MockHand;
@ -45,6 +45,10 @@ public class TurnControlTest {
StoneSet[] getSetArray() { StoneSet[] getSetArray() {
return objects.keySet().toArray(new StoneSet[0]); return objects.keySet().toArray(new StoneSet[0]);
} }
AccessibleTable (){
super (new GameSettings());
}
} }
class MockTimer implements ITurnTimer { class MockTimer implements ITurnTimer {

View file

@ -1,8 +1,8 @@
package jrummikub.model; package jrummikub.model;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -20,8 +20,10 @@ import org.junit.runner.RunWith;
@RunWith(Theories.class) @RunWith(Theories.class)
public class StoneHeapTest { public class StoneHeapTest {
private static Pair<GameSettings, StoneHeap> createHeap(GameSettings settings) { private static Pair<GameSettings, StoneHeap> createHeap(
return new Pair<GameSettings, StoneHeap>(settings, new StoneHeap(settings)); GameSettings settings) {
return new Pair<GameSettings, StoneHeap>(settings, new StoneHeap(
settings));
} }
/** /**
@ -54,7 +56,8 @@ public class StoneHeapTest {
private int calculateTotalNumberOfStones(GameSettings testSettings) { private int calculateTotalNumberOfStones(GameSettings testSettings) {
int totalStones = testSettings.getHighestCard() int totalStones = testSettings.getHighestCard()
* testSettings.getStoneSetNumber() * testSettings.getStoneSetNumber()
* testSettings.getStoneColors().size() + testSettings.getJokerNumber(); * testSettings.getStoneColors().size()
+ testSettings.getJokerNumber();
return totalStones; return totalStones;
} }
@ -62,7 +65,7 @@ public class StoneHeapTest {
* Is the right number of Stones in heap? * Is the right number of Stones in heap?
* *
* @param data * @param data
* data * data
*/ */
@Theory @Theory
public void fullStoneHeap(Pair<GameSettings, StoneHeap> data) { public void fullStoneHeap(Pair<GameSettings, StoneHeap> data) {
@ -74,14 +77,14 @@ public class StoneHeapTest {
* Enough stones of each color in heap? * Enough stones of each color in heap?
* *
* @param data * @param data
* data * data
*/ */
@Theory @Theory
public void fullColor(Pair<GameSettings, StoneHeap> data) { public void fullColor(Pair<GameSettings, StoneHeap> data) {
int stonesOfAColor = data.getFirst().getHighestCard() int stonesOfAColor = data.getFirst().getHighestCard()
* data.getFirst().getStoneSetNumber(); * data.getFirst().getStoneSetNumber();
Map<StoneColor, Integer> counters = new HashMap<StoneColor, Integer>(); Map<StoneColor, Integer> counters = new HashMap<StoneColor, Integer>();
for (StoneColor c : EnumSet.allOf(StoneColor.class)) { for (StoneColor c : data.getFirst().getStoneColors()) {
counters.put(c, 0); counters.put(c, 0);
} }
for (Stone i : data.getSecond().heap) { for (Stone i : data.getSecond().heap) {
@ -90,7 +93,7 @@ public class StoneHeapTest {
int count = counters.get(i.getColor()); int count = counters.get(i.getColor());
counters.put(i.getColor(), count + 1); counters.put(i.getColor(), count + 1);
} }
for (StoneColor c : EnumSet.allOf(StoneColor.class)) { for (StoneColor c : data.getFirst().getStoneColors()) {
assertEquals(stonesOfAColor, (long) counters.get(c)); assertEquals(stonesOfAColor, (long) counters.get(c));
} }
} }
@ -99,7 +102,7 @@ public class StoneHeapTest {
* Enough Jokers? * Enough Jokers?
* *
* @param data * @param data
* data * data
*/ */
@Theory @Theory
public void fullJoker(Pair<GameSettings, StoneHeap> data) { public void fullJoker(Pair<GameSettings, StoneHeap> data) {
@ -113,7 +116,7 @@ public class StoneHeapTest {
/** /**
* @param data * @param data
* data * data
*/ */
@Theory @Theory
public void drawStoneTest(Pair<GameSettings, StoneHeap> data) { public void drawStoneTest(Pair<GameSettings, StoneHeap> data) {
@ -124,7 +127,7 @@ public class StoneHeapTest {
/** /**
* @param data * @param data
* data * data
*/ */
@Theory @Theory
public void drawStonesTest(Pair<GameSettings, StoneHeap> data) { public void drawStonesTest(Pair<GameSettings, StoneHeap> data) {

View file

@ -1,91 +1,136 @@
package jrummikub.model; package jrummikub.model;
import static jrummikub.model.StoneColor.*;
import static jrummikub.model.StoneSet.Type.*;
import static org.junit.Assert.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List; import java.util.List;
import jrummikub.util.Pair; import jrummikub.util.Pair;
import static jrummikub.model.StoneColor.*;
import static jrummikub.model.StoneSet.Type.*;
import org.junit.*; import org.junit.Before;
import static org.junit.Assert.*; import org.junit.Test;
/** /**
* Tests for {@link StoneSet} * Tests for {@link StoneSet}
*/ */
public class StoneSetTest { public class StoneSetTest {
private GameSettings defaultSettings = new GameSettings();
private GameSettings moreColorSettings = new GameSettings();
private GameSettings lessColorSettings = new GameSettings();
private GameSettings higherValueSettings = new GameSettings();
private GameSettings lowerValueSettings = new GameSettings();
/** */
@Before
public void setUpSettings() {
moreColorSettings.setStoneColors(EnumSet.allOf(StoneColor.class));
lessColorSettings.setStoneColors(new HashSet<StoneColor>(Arrays.asList(
StoneColor.BLUE, StoneColor.RED, StoneColor.BLACK)));
higherValueSettings.setHighestCard(17);
lowerValueSettings.setHighestCard(10);
}
private void assertSet(StoneSet.Type expectedType, Integer expectedValue, private void assertSet(StoneSet.Type expectedType, Integer expectedValue,
List<Stone> stones) { List<Stone> stones, GameSettings settings) {
StoneSet set = new StoneSet(stones); StoneSet set = new StoneSet(stones);
assertSame(expectedType, set.classify().getFirst()); assertSame(expectedType, set.classify(settings).getFirst());
assertEquals(expectedValue, set.classify().getSecond()); assertEquals(expectedValue, set.classify(settings).getSecond());
} }
// valid+point count // valid+point count
/** */ /** */
@Test @Test
public void doubleJoker() { public void doubleJokerValid() {
// 3 Stones // 3 Stones
// JJZ // JJZ
assertSet(GROUP, 3, Arrays.asList(new Stone(RED), new Stone(BLACK), assertSet(GROUP, 3, Arrays.asList(new Stone(RED), new Stone(BLACK),
new Stone(1, BLACK))); new Stone(1, BLACK)), defaultSettings);
// JZJ // JZJ
assertSet(GROUP, 3, Arrays.asList(new Stone(RED), new Stone(1, BLACK), assertSet(GROUP, 3, Arrays.asList(new Stone(RED), new Stone(1, BLACK),
new Stone(BLACK))); new Stone(BLACK)), defaultSettings);
// ZJJ // ZJJ
assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(RED), assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(RED),
new Stone(BLACK))); new Stone(BLACK)), defaultSettings);
assertSet(RUN, 33, Arrays.asList(new Stone(10, RED), new Stone(RED),
new Stone(BLACK)), defaultSettings);
assertSet(GROUP, 30, Arrays.asList(new Stone(10, RED), new Stone(RED),
new Stone(BLACK)), lowerValueSettings);
assertSet(GROUP, 39, Arrays.asList(new Stone(13, RED), new Stone(RED),
new Stone(BLACK)), defaultSettings);
assertSet(RUN, 42, Arrays.asList(new Stone(13, RED), new Stone(RED),
new Stone(BLACK)), higherValueSettings);
// 4 Stones // 4 Stones
// JJZZ // JJZZ
assertSet(GROUP, 4, Arrays.asList(new Stone(RED), new Stone(BLACK), assertSet(GROUP, 4, Arrays.asList(new Stone(RED), new Stone(BLACK),
new Stone(1, BLACK), new Stone(1, RED))); new Stone(1, BLACK), new Stone(1, RED)), defaultSettings);
assertSet(RUN, 10, Arrays.asList(new Stone(RED), new Stone(BLACK), assertSet(RUN, 10, Arrays.asList(new Stone(RED), new Stone(BLACK),
new Stone(3, RED), new Stone(4, RED))); new Stone(3, RED), new Stone(4, RED)), defaultSettings);
// ZZJJ // ZZJJ
assertSet(RUN, 10, Arrays.asList(new Stone(1, RED), new Stone(2, RED), assertSet(RUN, 10, Arrays.asList(new Stone(1, RED), new Stone(2, RED),
new Stone(BLACK), new Stone(RED))); new Stone(BLACK), new Stone(RED)), defaultSettings);
assertSet(GROUP, 4, Arrays.asList(new Stone(1, RED), assertSet(GROUP, 4, Arrays.asList(new Stone(1, RED),
new Stone(1, BLACK), new Stone(BLACK), new Stone(RED))); new Stone(1, BLACK), new Stone(BLACK), new Stone(RED)),
defaultSettings);
// ZJZJ // ZJZJ
assertSet(GROUP, 4, Arrays.asList(new Stone(1, RED), new Stone(BLACK), assertSet(GROUP, 4, Arrays.asList(new Stone(1, RED), new Stone(BLACK),
new Stone(1, BLACK), new Stone(RED))); new Stone(1, BLACK), new Stone(RED)), defaultSettings);
assertSet(RUN, 10, Arrays.asList(new Stone(1, RED), new Stone(RED), assertSet(RUN, 10, Arrays.asList(new Stone(1, RED), new Stone(RED),
new Stone(3, RED), new Stone(BLACK))); new Stone(3, RED), new Stone(BLACK)), defaultSettings);
// JZJZ // JZJZ
assertSet(GROUP, 4, Arrays.asList(new Stone(RED), new Stone(1, BLACK), assertSet(GROUP, 4, Arrays.asList(new Stone(RED), new Stone(1, BLACK),
new Stone(BLACK), new Stone(1, RED))); new Stone(BLACK), new Stone(1, RED)), defaultSettings);
assertSet(RUN, 10, Arrays.asList(new Stone(RED), new Stone(2, RED), assertSet(RUN, 10, Arrays.asList(new Stone(RED), new Stone(2, RED),
new Stone(BLACK), new Stone(4, RED))); new Stone(BLACK), new Stone(4, RED)), defaultSettings);
// JZZJ // JZZJ
assertSet(GROUP, 4, Arrays.asList(new Stone(RED), new Stone(1, BLACK), assertSet(GROUP, 4, Arrays.asList(new Stone(RED), new Stone(1, BLACK),
new Stone(1, RED), new Stone(BLACK))); new Stone(1, RED), new Stone(BLACK)), defaultSettings);
assertSet(RUN, 10, Arrays.asList(new Stone(RED), new Stone(2, RED), assertSet(RUN, 10, Arrays.asList(new Stone(RED), new Stone(2, RED),
new Stone(3, RED), new Stone(BLACK))); new Stone(3, RED), new Stone(BLACK)), defaultSettings);
// ZJJZ // ZJJZ
assertSet(GROUP, 4, Arrays.asList(new Stone(1, RED), new Stone(BLACK), assertSet(GROUP, 4, Arrays.asList(new Stone(1, RED), new Stone(BLACK),
new Stone(RED), new Stone(1, BLACK))); new Stone(RED), new Stone(1, BLACK)), defaultSettings);
assertSet(RUN, 10, Arrays.asList(new Stone(1, RED), new Stone(RED), assertSet(RUN, 10, Arrays.asList(new Stone(1, RED), new Stone(RED),
new Stone(BLACK), new Stone(4, RED))); new Stone(BLACK), new Stone(4, RED)), defaultSettings);
// More than 4 stones
assertSet(GROUP, 6, Arrays.asList(new Stone(1, RED),
new Stone(1, BLUE), new Stone(1, GREEN), new Stone(1, BLACK),
new Stone(BLACK), new Stone(RED)), moreColorSettings);
} }
/** */ /** */
@Test @Test
public void groups() { public void groups() {
assertSet(GROUP, 3, Arrays.asList(new Stone(1, RED), assertSet(GROUP, 3, Arrays.asList(new Stone(1, RED),
new Stone(1, BLACK), new Stone(1, BLUE))); new Stone(1, BLACK), new Stone(1, BLUE)), defaultSettings);
assertSet(GROUP, 3, Arrays.asList(new Stone(1, RED),
new Stone(1, BLACK), new Stone(1, BLUE)), lessColorSettings);
assertSet(GROUP, 4, Arrays.asList(new Stone(1, RED), assertSet(GROUP, 4, Arrays.asList(new Stone(1, RED),
new Stone(1, BLACK), new Stone(1, BLUE), new Stone(1, ORANGE))); new Stone(1, BLACK), new Stone(1, BLUE), new Stone(1, ORANGE)),
defaultSettings);
assertSet(GROUP, 6, Arrays.asList(new Stone(1, RED),
new Stone(1, GREEN), new Stone(1, WHITE), new Stone(1, BLACK),
new Stone(1, BLUE), new Stone(1, ORANGE)), moreColorSettings);
} }
/** */ /** */
@Test @Test
public void runs() { public void runs() {
assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(2, RED), assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(2, RED),
new Stone(3, RED))); new Stone(3, RED)), defaultSettings);
assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(2, RED),
new Stone(3, RED)), lowerValueSettings);
assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(2, RED),
new Stone(3, RED)), higherValueSettings);
assertSet(RUN, 22, Arrays.asList(new Stone(4, BLUE), assertSet(RUN, 22, Arrays.asList(new Stone(4, BLUE),
new Stone(5, BLUE), new Stone(6, BLUE), new Stone(7, BLUE))); new Stone(5, BLUE), new Stone(6, BLUE), new Stone(7, BLUE)),
defaultSettings);
assertSet(RUN, 42, Arrays.asList(new Stone(13, RED),
new Stone(14, RED), new Stone(15, RED)), higherValueSettings);
} }
/** */ /** */
@ -93,84 +138,107 @@ public class StoneSetTest {
public void singleJoker() { public void singleJoker() {
// ZJZ // ZJZ
assertSet(GROUP, 3, Arrays.asList(new Stone(1, RED), new Stone(BLACK), assertSet(GROUP, 3, Arrays.asList(new Stone(1, RED), new Stone(BLACK),
new Stone(1, BLACK))); new Stone(1, BLACK)), defaultSettings);
assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(RED), assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(RED),
new Stone(3, RED))); new Stone(3, RED)), defaultSettings);
// JZZ // JZZ
assertSet(GROUP, 3, Arrays.asList(new Stone(RED), new Stone(1, RED), assertSet(GROUP, 3, Arrays.asList(new Stone(RED), new Stone(1, RED),
new Stone(1, BLACK))); new Stone(1, BLACK)), defaultSettings);
assertSet(RUN, 6, Arrays.asList(new Stone(RED), new Stone(2, RED), assertSet(RUN, 6, Arrays.asList(new Stone(RED), new Stone(2, RED),
new Stone(3, RED))); new Stone(3, RED)), defaultSettings);
// ZZJ // ZZJ
assertSet(GROUP, 3, Arrays.asList(new Stone(1, RED), assertSet(GROUP, 3, Arrays.asList(new Stone(1, RED),
new Stone(1, BLACK), new Stone(BLACK))); new Stone(1, BLACK), new Stone(BLACK)), defaultSettings);
assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(2, RED), assertSet(RUN, 6, Arrays.asList(new Stone(1, RED), new Stone(2, RED),
new Stone(RED))); new Stone(RED)), defaultSettings);
assertSet(RUN, 39, Arrays.asList(new Stone(12, RED),
new Stone(13, RED), new Stone(RED)), higherValueSettings);
} }
// invalid // invalid
/** */
@Test
public void doubleJokerInvalid() {
assertSet(INVALID, 0, Arrays.asList(new Stone(RED), new Stone(BLACK),
new Stone(1, BLACK), new Stone(1, RED)), lessColorSettings);
// More than 4 stones
assertSet(INVALID, 0, Arrays.asList(new Stone(1, RED), new Stone(1,
BLUE), new Stone(1, GREEN), new Stone(1, BLACK), new Stone(1,
VIOLET), new Stone(1, ORANGE), new Stone(1, BROWN), new Stone(
BLACK), new Stone(RED)), moreColorSettings);
}
/** */ /** */
@Test @Test
public void outOfBounds() { public void outOfBounds() {
assertSet(INVALID, 0, Arrays.asList(new Stone(RED), new Stone(1, RED), assertSet(INVALID, 0, Arrays.asList(new Stone(RED), new Stone(1, RED),
new Stone(2, RED))); new Stone(2, RED)), defaultSettings);
assertSet(INVALID, 0, Arrays.asList(new Stone(12, RED), new Stone(13, assertSet(INVALID, 0, Arrays.asList(new Stone(12, RED), new Stone(13,
RED), new Stone(RED))); RED), new Stone(RED)), defaultSettings);
assertSet(INVALID, 0, Arrays.asList(new Stone(9, RED), new Stone(10,
RED), new Stone(RED)), lowerValueSettings);
assertSet(INVALID, 0, Arrays.asList(new Stone(RED), new Stone(BLACK), assertSet(INVALID, 0, Arrays.asList(new Stone(RED), new Stone(BLACK),
new Stone(1, RED), new Stone(2, RED))); new Stone(1, RED), new Stone(2, RED)), defaultSettings);
} }
/** */ /** */
@Test @Test
public void sameColor() { public void sameColor() {
assertSet(INVALID, 0, Arrays.asList(new Stone(1, RED), assertSet(INVALID, 0, Arrays.asList(new Stone(1, RED),
new Stone(1, RED), new Stone(1, BLUE))); new Stone(1, RED), new Stone(1, BLUE)), defaultSettings);
assertSet(INVALID, 0, Arrays.asList(new Stone(1, RED), new Stone(1, assertSet(INVALID, 0, Arrays.asList(new Stone(1, RED), new Stone(1,
BLUE), new Stone(1, BLACK), new Stone(1, ORANGE), BLUE), new Stone(1, BLACK), new Stone(1, ORANGE),
new Stone(RED))); new Stone(RED)), defaultSettings);
assertSet(INVALID, 0, Arrays.asList(new Stone(1, RED), new Stone(1,
BLUE), new Stone(1, GREEN), new Stone(1, BLACK), new Stone(1,
VIOLET), new Stone(1, WHITE), new Stone(1, ORANGE), new Stone(
1, BROWN), new Stone(RED)), moreColorSettings);
} }
/** */ /** */
@Test @Test
public void incorrectOrder() { public void incorrectOrder() {
assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED), assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED),
new Stone(6, RED), new Stone(5, RED))); new Stone(6, RED), new Stone(5, RED)), defaultSettings);
assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED), assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED),
new Stone(6, RED), new Stone(RED))); new Stone(6, RED), new Stone(RED)), defaultSettings);
assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED), new Stone(RED), assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED), new Stone(RED),
new Stone(5, RED))); new Stone(5, RED)), defaultSettings);
} }
/** */ /** */
@Test @Test
public void otherInvalid() { public void otherInvalid() {
assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED), assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED),
new Stone(5, RED), new Stone(7, RED))); new Stone(5, RED), new Stone(7, RED)), defaultSettings);
assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED), new Stone(5, assertSet(INVALID, 0, Arrays.asList(new Stone(4, RED), new Stone(5,
BLUE), new Stone(6, RED))); BLUE), new Stone(6, RED)), defaultSettings);
assertSet(INVALID, 0, assertSet(INVALID, 0,
Arrays.asList(new Stone(4, RED), new Stone(5, RED))); Arrays.asList(new Stone(4, RED), new Stone(5, RED)),
defaultSettings);
assertSet(INVALID, 0, Arrays.asList(new Stone(4, BLUE), new Stone(5, assertSet(INVALID, 0, Arrays.asList(new Stone(4, BLUE), new Stone(5,
RED), new Stone(6, RED))); RED), new Stone(6, RED)), defaultSettings);
// Regression test: // Regression test:
assertSet(INVALID, 0, Arrays.asList(new Stone(12, ORANGE), new Stone( assertSet(INVALID, 0, Arrays.asList(new Stone(12, ORANGE), new Stone(
12, BLACK), new Stone(7, BLUE))); 12, BLACK), new Stone(7, BLUE)), defaultSettings);
} }
/** */ /** */
@Test @Test
public void manyJokersValid() { public void manyJokersValid() {
assertSet(GROUP, 3 * 13, Arrays.asList(new Stone(RED), assertSet(GROUP, 3 * 13,
new Stone(RED), new Stone(RED))); Arrays.asList(new Stone(RED), new Stone(RED), new Stone(RED)),
assertSet(GROUP, 4 * 13, Arrays.asList(new Stone(RED), defaultSettings);
new Stone(RED), new Stone(RED), new Stone(RED))); assertSet(GROUP, 4 * 13, Arrays.asList(new Stone(RED), new Stone(RED),
assertSet(RUN, 13 + 12 + 11 + 10 + 9, Arrays.asList(new Stone(RED), new Stone(RED), new Stone(RED)), defaultSettings);
new Stone(RED), new Stone(RED), new Stone(RED), new Stone(RED))); assertSet(RUN, 13 + 12 + 11 + 10 + 9,
assertSet(RUN, 5 * 10, Arrays.asList(new Stone(RED), Arrays.asList(new Stone(RED), new Stone(RED), new Stone(RED),
new Stone(RED), new Stone(RED), new Stone(RED), new Stone(12, RED))); new Stone(RED), new Stone(RED)), defaultSettings);
assertSet(RUN, 5 * 10, Arrays.asList(new Stone(RED), new Stone(RED),
new Stone(RED), new Stone(RED), new Stone(12, RED)),
defaultSettings);
} }
/** */ /** */
@Test @Test
public void manyJokersInvalid() { public void manyJokersInvalid() {
@ -178,7 +246,7 @@ public class StoneSetTest {
for (int i = 0; i < 14; i++) { for (int i = 0; i < 14; i++) {
stones.add(new Stone(RED)); stones.add(new Stone(RED));
} }
assertSet(INVALID, 0, stones); assertSet(INVALID, 0, stones, defaultSettings);
} }
// invalid Split // invalid Split

View file

@ -21,7 +21,7 @@ public class TableTest {
/** */ /** */
@Before @Before
public void setup() { public void setup() {
testTable = new Table(); testTable = new Table(new GameSettings());
} }
/** */ /** */