summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-05-30 19:50:58 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-05-30 19:50:58 +0200
commitc398c081ed4d83660ec867cabfb0ee9bc56b90ad (patch)
treec0d736284d4bb12f37ae3eb1d2344eedcc121a3d
parentad2f22636921ac5afe60f48bda08274eb00e079a (diff)
downloadJRummikub-c398c081ed4d83660ec867cabfb0ee9bc56b90ad.tar
JRummikub-c398c081ed4d83660ec867cabfb0ee9bc56b90ad.zip
Test für Änderung der StoneSet Anzahl fertig
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@327 72836036-5685-4462-b002-a69064685172
-rw-r--r--mock/jrummikub/view/MockSettingsPanel.java16
-rw-r--r--src/jrummikub/view/ISettingsPanel.java5
-rw-r--r--src/jrummikub/view/impl/SettingsPanel.java14
-rw-r--r--test/jrummikub/control/SettingsControlTest.java51
-rw-r--r--test/jrummikub/model/StoneHeapTest.java23
5 files changed, 85 insertions, 24 deletions
diff --git a/mock/jrummikub/view/MockSettingsPanel.java b/mock/jrummikub/view/MockSettingsPanel.java
index 2140e05..a159524 100644
--- a/mock/jrummikub/view/MockSettingsPanel.java
+++ b/mock/jrummikub/view/MockSettingsPanel.java
@@ -42,11 +42,15 @@ public class MockSettingsPanel implements ISettingsPanel {
public MockEvent1<Integer> changeInitialMeldThresholdEvent = new MockEvent1<Integer>();
/** */
public MockEvent1<Integer> changeJokerNumberEvent = new MockEvent1<Integer>();
-
+ /** */
+ public MockEvent1<Integer> changeStoneSetNumberEvent = new MockEvent1<Integer>();
/** */
public int initialMeldThreshold;
/** */
public int jokerNumber;
+
+ public int stoneSetNumber;
+
@Override
public IEvent getAddPlayerEvent() {
return addPlayerEvent;
@@ -127,4 +131,14 @@ public class MockSettingsPanel implements ISettingsPanel {
return changePlayerTypeEvent;
}
+ @Override
+ public IEvent1<Integer> getChangeStoneSetNumberEvent() {
+ return changeStoneSetNumberEvent;
+ }
+
+ @Override
+ public void setStoneSetNumber(int number) {
+ stoneSetNumber = number;
+ }
+
}
diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java
index 8c30c78..3caa8cb 100644
--- a/src/jrummikub/view/ISettingsPanel.java
+++ b/src/jrummikub/view/ISettingsPanel.java
@@ -80,6 +80,8 @@ public interface ISettingsPanel {
* @return the event
*/
public IEvent1<Integer> getChangeInitialMeldThresholdEvent();
+
+ public IEvent1<Integer> getChangeStoneSetNumberEvent();
/**
* the start game event is emitted when the user wants to start the game
@@ -156,6 +158,8 @@ public interface ISettingsPanel {
* initial meld threshold
*/
public void setInitialMeldThreshold(int value);
+
+ public void setStoneSetNumber(int number);
/**
* Emitted when the joker number is changed
@@ -164,6 +168,7 @@ public interface ISettingsPanel {
*/
public IEvent1<Integer> getChangeJokerNumberEvent();
+
/**
* Sets the joker number in the option pane
*
diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java
index a5792e7..1eb8e45 100644
--- a/src/jrummikub/view/impl/SettingsPanel.java
+++ b/src/jrummikub/view/impl/SettingsPanel.java
@@ -75,6 +75,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private Event2<Integer, TurnControlFactory.Type> changePlayerTypeEvent = new Event2<Integer, TurnControlFactory.Type>();
private Event1<Integer> changeInitialMeldThresholdEvent = new Event1<Integer>();
private Event1<Integer> changeJokerNumberEvent = new Event1<Integer>();
+ private Event1<Integer> changeStoneSetNumberEvent = new Event1<Integer>();
@Override
public IEvent getStartGameEvent() {
@@ -107,6 +108,11 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}
@Override
+ public IEvent1<Integer> getChangeStoneSetNumberEvent() {
+ return changeStoneSetNumberEvent;
+ }
+
+ @Override
public void setError(SettingsError error) {
switch (error) {
case NO_ERROR:
@@ -246,8 +252,6 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
c.weightx = 1;
c.weighty = 1;
optionsPanel.add(makeFiller(), c);
-
- // TODO Knöpfe für Dinge
}
private JSpinner makeOptionSpinner(int row, int min, int max, int step,
@@ -517,4 +521,10 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
public IEvent2<Integer, Type> getChangePlayerTypeEvent() {
return changePlayerTypeEvent;
}
+
+ @Override
+ public void setStoneSetNumber(int number) {
+ // TODO Auto-generated method stub
+
+ }
}
diff --git a/test/jrummikub/control/SettingsControlTest.java b/test/jrummikub/control/SettingsControlTest.java
index 8fab97a..ff870d0 100644
--- a/test/jrummikub/control/SettingsControlTest.java
+++ b/test/jrummikub/control/SettingsControlTest.java
@@ -37,7 +37,8 @@ public class SettingsControlTest {
/** */
@Test
public void initialStateTest() {
- assertSame(ISettingsPanel.SettingsError.NO_ERROR, view.settingsPanel.error);
+ assertSame(ISettingsPanel.SettingsError.NO_ERROR,
+ view.settingsPanel.error);
view.settingsPanel.startGameEvent.emit();
assertNotNull(gameSettings);
assertEquals(2, gameSettings.getPlayerList().size());
@@ -156,7 +157,8 @@ public class SettingsControlTest {
view.settingsPanel.changePlayerNameEvent.emit(1, name2);
assertTrue(view.settingsPanel.startButtonEnabled);
- assertSame(ISettingsPanel.SettingsError.NO_ERROR, view.settingsPanel.error);
+ assertSame(ISettingsPanel.SettingsError.NO_ERROR,
+ view.settingsPanel.error);
view.settingsPanel.startGameEvent.emit();
assertNotNull(gameSettings);
@@ -175,38 +177,57 @@ public class SettingsControlTest {
view.settingsPanel.startGameEvent.emit();
assertNull(gameSettings);
}
-
+
/** */
@Test
public void initialMeldThresholdTest() {
- assertEquals(initialSettings.getInitialMeldThreshold(), view.settingsPanel.initialMeldThreshold);
-
+ assertEquals(initialSettings.getInitialMeldThreshold(),
+ view.settingsPanel.initialMeldThreshold);
+
view.settingsPanel.changeInitialMeldThresholdEvent.emit(25);
view.settingsPanel.startGameEvent.emit();
assertEquals(25, gameSettings.getInitialMeldThreshold());
}
-
+
/** */
@Test
public void jokerNumberTest() {
- assertEquals(initialSettings.getJokerNumber(), view.settingsPanel.jokerNumber);
-
+ assertEquals(initialSettings.getJokerNumber(),
+ view.settingsPanel.jokerNumber);
+
view.settingsPanel.changeJokerNumberEvent.emit(25);
view.settingsPanel.startGameEvent.emit();
assertEquals(25, gameSettings.getJokerNumber());
}
-
+
+ /** */
+ @Test
+ public void changeStoneSetNumberTest() {
+ assertEquals(initialSettings.getStoneSetNumber(),
+ view.settingsPanel.stoneSetNumber);
+
+ view.settingsPanel.changeStoneSetNumberEvent.emit(3);
+ view.settingsPanel.startGameEvent.emit();
+ assertEquals(3, gameSettings.getStoneSetNumber());
+
+ }
+
/** */
@Test
public void typeChangeTest() {
- view.settingsPanel.changePlayerTypeEvent.emit(0, TurnControlFactory.Type.COMPUTER);
- view.settingsPanel.changePlayerTypeEvent.emit(1, TurnControlFactory.Type.COMPUTER);
- view.settingsPanel.changePlayerTypeEvent.emit(1, TurnControlFactory.Type.HUMAN);
+ view.settingsPanel.changePlayerTypeEvent.emit(0,
+ TurnControlFactory.Type.COMPUTER);
+ view.settingsPanel.changePlayerTypeEvent.emit(1,
+ TurnControlFactory.Type.COMPUTER);
+ view.settingsPanel.changePlayerTypeEvent.emit(1,
+ TurnControlFactory.Type.HUMAN);
view.settingsPanel.startGameEvent.emit();
assertNotNull(gameSettings);
assertEquals(2, gameSettings.getPlayerList().size());
- assertSame(TurnControlFactory.Type.COMPUTER, gameSettings.getPlayerList().get(0).getTurnControlType());
- assertSame(TurnControlFactory.Type.HUMAN, gameSettings.getPlayerList().get(1).getTurnControlType());
+ assertSame(TurnControlFactory.Type.COMPUTER, gameSettings
+ .getPlayerList().get(0).getTurnControlType());
+ assertSame(TurnControlFactory.Type.HUMAN, gameSettings.getPlayerList()
+ .get(1).getTurnControlType());
}
-
+
}
diff --git a/test/jrummikub/model/StoneHeapTest.java b/test/jrummikub/model/StoneHeapTest.java
index f625187..ffe0cdf 100644
--- a/test/jrummikub/model/StoneHeapTest.java
+++ b/test/jrummikub/model/StoneHeapTest.java
@@ -13,11 +13,20 @@ import static org.junit.Assert.*;
*/
public class StoneHeapTest {
private StoneHeap testHeap;
+ private GameSettings testSettings;
/** */
@Before
public void createHeap() {
- testHeap = new StoneHeap(new GameSettings());
+ testHeap = new StoneHeap(testSettings = new GameSettings());
+ }
+
+ private int calculateTotalNumberOfStones() {
+ int totalStones = testSettings.getHighestCard()
+ * testSettings.getStoneSetNumber()
+ * testSettings.getStoneColors().size()
+ + testSettings.getJokerNumber();
+ return totalStones;
}
/**
@@ -25,7 +34,7 @@ public class StoneHeapTest {
*/
@Test
public void fullStoneHeap() {
- assertEquals(106, testHeap.heap.size());
+ assertEquals(calculateTotalNumberOfStones(), testHeap.heap.size());
}
/**
@@ -33,6 +42,8 @@ public class StoneHeapTest {
*/
@Test
public void fullColor() {
+ int stonesOfAColor = testSettings.getHighestCard()
+ * testSettings.getStoneSetNumber();
Map<StoneColor, Integer> counters = new HashMap<StoneColor, Integer>();
for (StoneColor c : EnumSet.allOf(StoneColor.class)) {
counters.put(c, 0);
@@ -44,7 +55,7 @@ public class StoneHeapTest {
counters.put(i.getColor(), count + 1);
}
for (StoneColor c : EnumSet.allOf(StoneColor.class)) {
- assertEquals(26, (long) counters.get(c));
+ assertEquals(stonesOfAColor, (long) counters.get(c));
}
}
@@ -58,14 +69,14 @@ public class StoneHeapTest {
if (i.isJoker())
countJoker++;
}
- assertEquals(2, countJoker);
+ assertEquals(testSettings.getJokerNumber(), countJoker);
}
/** */
@Test
public void drawStoneTest() {
assertNotNull(testHeap.drawStone());
- assertEquals(105, testHeap.heap.size());
+ assertEquals(calculateTotalNumberOfStones() - 1, testHeap.heap.size());
}
/** */
@@ -73,6 +84,6 @@ public class StoneHeapTest {
public void drawStonesTest() {
List<Stone> testStones = testHeap.drawStones(5);
assertEquals(5, testStones.size());
- assertEquals(101, testHeap.heap.size());
+ assertEquals(calculateTotalNumberOfStones() - 5, testHeap.heap.size());
}
}