Test für RoundControl fertig
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@128 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
db7489a5c7
commit
e2f82f3f28
10 changed files with 296 additions and 36 deletions
|
@ -1,16 +1,16 @@
|
||||||
package jrummikub.control;
|
package jrummikub.control;
|
||||||
|
|
||||||
import jrummikub.model.GameState;
|
import jrummikub.model.IGameState;
|
||||||
import jrummikub.model.IHand;
|
import jrummikub.model.IHand;
|
||||||
import jrummikub.model.Player;
|
import jrummikub.model.Player;
|
||||||
import jrummikub.model.Position;
|
import jrummikub.model.Position;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
|
|
||||||
public class RoundControl {
|
public class RoundControl {
|
||||||
private GameState gameState;
|
private IGameState gameState;
|
||||||
private IView view;
|
private IView view;
|
||||||
|
|
||||||
public RoundControl(GameState gameState, IView view) {
|
public RoundControl(IGameState gameState, IView view) {
|
||||||
this.gameState = gameState;
|
this.gameState = gameState;
|
||||||
this.view = view;
|
this.view = view;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/** Class managing the overall and momentary GameState */
|
/** Class managing the overall and momentary GameState */
|
||||||
public class GameState {
|
public class GameState implements IGameState {
|
||||||
private ITable table;
|
private ITable table;
|
||||||
private List<Player> players;
|
private List<Player> players;
|
||||||
private int activePlayer;
|
private int activePlayer;
|
||||||
|
@ -22,27 +22,33 @@ public class GameState {
|
||||||
gameHeap = new StoneHeap();
|
gameHeap = new StoneHeap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ITable getTable() {
|
public ITable getTable() {
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getPlayerCount() {
|
public int getPlayerCount() {
|
||||||
return players.size();
|
return players.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getPlayer(int i) {
|
@Override
|
||||||
|
public IPlayer getPlayer(int i) {
|
||||||
return players.get(i);
|
return players.get(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Changes the activePlayer to the next {@link Player} in the list */
|
/** Changes the activePlayer to the next {@link Player} in the list */
|
||||||
|
@Override
|
||||||
public void nextPlayer() {
|
public void nextPlayer() {
|
||||||
activePlayer = (activePlayer + 1) % players.size();
|
activePlayer = (activePlayer + 1) % players.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getActivePlayer() {
|
@Override
|
||||||
|
public IPlayer getActivePlayer() {
|
||||||
return players.get(activePlayer);
|
return players.get(activePlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public StoneHeap getGameHeap() {
|
public StoneHeap getGameHeap() {
|
||||||
return gameHeap;
|
return gameHeap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package jrummikub.model;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
||||||
/** Class managing player data. No methods in release 1 */
|
/** Class managing player data. No methods in release 1 */
|
||||||
public class Player {
|
public class Player implements IPlayer {
|
||||||
|
|
||||||
private IHand hand;
|
private IHand hand;
|
||||||
private Color color;
|
private Color color;
|
||||||
|
@ -15,10 +15,12 @@ public class Player {
|
||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public IHand getHand() {
|
public IHand getHand() {
|
||||||
return hand;
|
return hand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Color getColor() {
|
public Color getColor() {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,16 @@
|
||||||
package jrummikub.control;
|
package jrummikub.control;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
import jrummikub.model.GameState;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNotSame;
|
||||||
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import jrummikub.model.MockGameState;
|
||||||
|
import jrummikub.model.MockTable;
|
||||||
|
import jrummikub.model.Position;
|
||||||
|
import jrummikub.model.Stone;
|
||||||
|
import jrummikub.model.StoneSet;
|
||||||
import jrummikub.view.MockView;
|
import jrummikub.view.MockView;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -9,13 +18,13 @@ import org.junit.Test;
|
||||||
|
|
||||||
public class RoundControlTest {
|
public class RoundControlTest {
|
||||||
private MockView view;
|
private MockView view;
|
||||||
private GameState testGameState;
|
private MockGameState testGameState;
|
||||||
private RoundControl testRound;
|
private RoundControl testRound;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
view = new MockView();
|
view = new MockView();
|
||||||
testGameState = new GameState();
|
testGameState = new MockGameState();
|
||||||
testRound = new RoundControl(testGameState, view);
|
testRound = new RoundControl(testGameState, view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +36,23 @@ public class RoundControlTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkTurnStartSetUp() {
|
||||||
|
assertNotNull(view.currentPlayerName);
|
||||||
|
assertNotNull(view.getTablePanel().leftPlayerName);
|
||||||
|
assertNotNull(view.getTablePanel().topPlayerName);
|
||||||
|
assertNotNull(view.getTablePanel().rightPlayerName);
|
||||||
|
assertTrue(view.displayStartTurnPanel);
|
||||||
|
assertFalse(view.startTurnEvent.listeners.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void resetTurnStart() {
|
||||||
|
view.currentPlayerName = null;
|
||||||
|
view.getTablePanel().leftPlayerName = null;
|
||||||
|
view.getTablePanel().topPlayerName = null;
|
||||||
|
view.getTablePanel().rightPlayerName = null;
|
||||||
|
view.displayStartTurnPanel = false;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDeal() {
|
public void testDeal() {
|
||||||
testRound.deal();
|
testRound.deal();
|
||||||
|
@ -38,11 +64,108 @@ public class RoundControlTest {
|
||||||
testRound.startRound();
|
testRound.startRound();
|
||||||
checkCorrectlyDealed();
|
checkCorrectlyDealed();
|
||||||
|
|
||||||
assertNotNull(view.currentPlayerName);
|
checkTurnStartSetUp();
|
||||||
assertNotNull(view.getTablePanel().leftPlayerName);
|
}
|
||||||
assertNotNull(view.getTablePanel().topPlayerName);
|
|
||||||
assertNotNull(view.getTablePanel().rightPlayerName);
|
@Test
|
||||||
assertTrue(view.displayStartTurnPanel);
|
public void testTableValidHandChanged() {
|
||||||
assertFalse(view.startTurnEvent.listeners.isEmpty());
|
testRound.startRound();
|
||||||
|
MockTable oldTable = testGameState.table;
|
||||||
|
MockTable newTable = new MockTable();
|
||||||
|
newTable.valid = true;
|
||||||
|
oldTable.clonedTable = newTable;
|
||||||
|
|
||||||
|
view.startTurnEvent.emit();
|
||||||
|
assertFalse(view.displayStartTurnPanel);
|
||||||
|
testGameState.players.get(0).hand.stones.remove(0);
|
||||||
|
resetTurnStart();
|
||||||
|
view.getPlayerPanel().endTurnEvent.emit();
|
||||||
|
|
||||||
|
assertNotSame(oldTable, testGameState.table);
|
||||||
|
assertSame(newTable, testGameState.table);
|
||||||
|
assertEquals(1, testGameState.activePlayer);
|
||||||
|
|
||||||
|
checkTurnStartSetUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTableInvalidHandChanged() {
|
||||||
|
testRound.startRound();
|
||||||
|
MockTable oldTable = testGameState.table;
|
||||||
|
MockTable newTable = new MockTable();
|
||||||
|
newTable.valid = false;
|
||||||
|
oldTable.clonedTable = newTable;
|
||||||
|
|
||||||
|
view.startTurnEvent.emit();
|
||||||
|
assertFalse(view.displayStartTurnPanel);
|
||||||
|
Stone stone = testGameState.players.get(0).hand.stones.remove(0);
|
||||||
|
newTable.drop(new StoneSet(stone), new Position(0, 0));
|
||||||
|
resetTurnStart();
|
||||||
|
view.getPlayerPanel().endTurnEvent.emit();
|
||||||
|
|
||||||
|
assertSame(oldTable, testGameState.table);
|
||||||
|
assertNotSame(newTable, testGameState.table);
|
||||||
|
assertEquals(1, testGameState.activePlayer);
|
||||||
|
assertEquals(14 + 3, testGameState.players.get(0).hand.getSize());
|
||||||
|
checkTurnStartSetUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTableValidHandUnchanged() {
|
||||||
|
testRound.startRound();
|
||||||
|
MockTable oldTable = testGameState.table;
|
||||||
|
MockTable newTable = new MockTable();
|
||||||
|
newTable.valid = true;
|
||||||
|
oldTable.clonedTable = newTable;
|
||||||
|
|
||||||
|
view.startTurnEvent.emit();
|
||||||
|
assertFalse(view.displayStartTurnPanel);
|
||||||
|
resetTurnStart();
|
||||||
|
view.getPlayerPanel().endTurnEvent.emit();
|
||||||
|
|
||||||
|
assertEquals(14 + 1, testGameState.players.get(0).hand.getSize());
|
||||||
|
assertEquals(1, testGameState.activePlayer);
|
||||||
|
assertSame(newTable, testGameState.table);
|
||||||
|
assertNotSame(oldTable, testGameState.table);
|
||||||
|
|
||||||
|
checkTurnStartSetUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTableInvalidHandUnchanged() {
|
||||||
|
testRound.startRound();
|
||||||
|
MockTable oldTable = testGameState.table;
|
||||||
|
MockTable newTable = new MockTable();
|
||||||
|
newTable.valid = false;
|
||||||
|
oldTable.clonedTable = newTable;
|
||||||
|
|
||||||
|
view.startTurnEvent.emit();
|
||||||
|
assertFalse(view.displayStartTurnPanel);
|
||||||
|
resetTurnStart();
|
||||||
|
view.getPlayerPanel().endTurnEvent.emit();
|
||||||
|
|
||||||
|
assertEquals(14 + 1, testGameState.players.get(0).hand.getSize());
|
||||||
|
assertEquals(1, testGameState.activePlayer);
|
||||||
|
assertNotSame(newTable, testGameState.table);
|
||||||
|
assertSame(oldTable, testGameState.table);
|
||||||
|
|
||||||
|
checkTurnStartSetUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWinning() {
|
||||||
|
testRound.startRound();
|
||||||
|
MockTable oldTable = testGameState.table;
|
||||||
|
MockTable newTable = new MockTable();
|
||||||
|
newTable.valid = true;
|
||||||
|
oldTable.clonedTable = newTable;
|
||||||
|
|
||||||
|
view.startTurnEvent.emit();
|
||||||
|
assertFalse(view.displayStartTurnPanel);
|
||||||
|
testGameState.players.get(0).hand.stones.clear();
|
||||||
|
resetTurnStart();
|
||||||
|
view.getPlayerPanel().endTurnEvent.emit();
|
||||||
|
|
||||||
|
assertTrue(view.displayWinPanel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class GameStateTest {
|
public class GameStateTest {
|
||||||
private GameState testGame;
|
private IGameState testGame;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void createGame() {
|
public void createGame() {
|
||||||
|
|
54
test/jrummikub/model/MockGameState.java
Normal file
54
test/jrummikub/model/MockGameState.java
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
package jrummikub.model;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MockGameState implements IGameState {
|
||||||
|
public MockTable table;
|
||||||
|
public List<MockPlayer> players;
|
||||||
|
public int activePlayer;
|
||||||
|
public StoneHeap gameHeap;
|
||||||
|
|
||||||
|
public MockGameState() {
|
||||||
|
table = new MockTable();
|
||||||
|
players = new ArrayList<MockPlayer>();
|
||||||
|
players.add(new MockPlayer(Color.red));
|
||||||
|
players.add(new MockPlayer(Color.yellow));
|
||||||
|
players.add(new MockPlayer(Color.green));
|
||||||
|
players.add(new MockPlayer(Color.black));
|
||||||
|
activePlayer = 0;
|
||||||
|
gameHeap = new StoneHeap();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ITable getTable() {
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPlayerCount() {
|
||||||
|
return players.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPlayer getPlayer(int i) {
|
||||||
|
return players.get(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Changes the activePlayer to the next {@link Player} in the list */
|
||||||
|
@Override
|
||||||
|
public void nextPlayer() {
|
||||||
|
activePlayer = (activePlayer + 1) % players.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IPlayer getActivePlayer() {
|
||||||
|
return players.get(activePlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StoneHeap getGameHeap() {
|
||||||
|
return gameHeap;
|
||||||
|
}
|
||||||
|
}
|
49
test/jrummikub/model/MockHand.java
Normal file
49
test/jrummikub/model/MockHand.java
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
package jrummikub.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import jrummikub.util.Pair;
|
||||||
|
|
||||||
|
public class MockHand implements IHand {
|
||||||
|
|
||||||
|
public List<Stone> stones = new ArrayList<Stone>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stone pickUp(Position position) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drop(Stone object, Position position) {
|
||||||
|
stones.add(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Position getPosition(Stone object) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pickUp(Stone object) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSize() {
|
||||||
|
return stones.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<Pair<Stone, Position>> iterator() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MockHand clone() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
26
test/jrummikub/model/MockPlayer.java
Normal file
26
test/jrummikub/model/MockPlayer.java
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
package jrummikub.model;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
|
public class MockPlayer implements IPlayer {
|
||||||
|
|
||||||
|
public MockHand hand;
|
||||||
|
public Color color;
|
||||||
|
|
||||||
|
// private String name;
|
||||||
|
|
||||||
|
public MockPlayer(Color color) {
|
||||||
|
hand = new MockHand();
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IHand getHand() {
|
||||||
|
return hand;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Color getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,15 +1,19 @@
|
||||||
package jrummikub.model;
|
package jrummikub.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
import jrummikub.view.MockStoneCollectionPanel;
|
|
||||||
|
|
||||||
public class MockTable implements ITable {
|
public class MockTable implements ITable {
|
||||||
public Map<Stone, StoneSet> findStoneSet = new HashMap<Stone, StoneSet>();
|
public Map<Stone, StoneSet> findStoneSet = new HashMap<Stone, StoneSet>();
|
||||||
|
public boolean valid = false;
|
||||||
|
public MockTable clonedTable;
|
||||||
|
public List<Pair<StoneSet, Position>> sets = new ArrayList<Pair<StoneSet, Position>>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pickUpStone(Stone stone) {
|
public void pickUpStone(Stone stone) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
@ -18,8 +22,7 @@ public class MockTable implements ITable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
// TODO Auto-generated method stub
|
return valid;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -30,8 +33,7 @@ public class MockTable implements ITable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drop(StoneSet object, Position position) {
|
public void drop(StoneSet object, Position position) {
|
||||||
// TODO Auto-generated method stub
|
sets.add(new Pair<StoneSet, Position>(object, position));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,28 +45,26 @@ public class MockTable implements ITable {
|
||||||
@Override
|
@Override
|
||||||
public void pickUp(StoneSet object) {
|
public void pickUp(StoneSet object) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Pair<StoneSet, Position>> iterator() {
|
public Iterator<Pair<StoneSet, Position>> iterator() {
|
||||||
// TODO Auto-generated method stub
|
return sets.iterator();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StoneSet findStoneSet(Stone stone) {
|
public StoneSet findStoneSet(Stone stone) {
|
||||||
return findStoneSet.get(stone);
|
return findStoneSet.get(stone);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MockTable clone() {
|
public MockTable clone() {
|
||||||
return null;
|
return clonedTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
// TODO Auto-generated method stub
|
return sets.size();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package jrummikub.view;
|
package jrummikub.view;
|
||||||
|
|
||||||
import jrummikub.util.Event;
|
|
||||||
import jrummikub.util.IEvent;
|
import jrummikub.util.IEvent;
|
||||||
|
import jrummikub.util.MockEvent;
|
||||||
|
|
||||||
public class MockPlayerPanel implements IPlayerPanel {
|
public class MockPlayerPanel implements IPlayerPanel {
|
||||||
public Event endTurnEvent = new Event();
|
public MockEvent endTurnEvent = new MockEvent();
|
||||||
public MockHandPanel handPanel = new MockHandPanel();
|
public MockHandPanel handPanel = new MockHandPanel();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IHandPanel getHandPanel() {
|
public IHandPanel getHandPanel() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
@ -16,7 +16,7 @@ public class MockPlayerPanel implements IPlayerPanel {
|
||||||
@Override
|
@Override
|
||||||
public void setTimeLeft(int time) {
|
public void setTimeLeft(int time) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -35,5 +35,5 @@ public class MockPlayerPanel implements IPlayerPanel {
|
||||||
public IEvent getEndTurnEvent() {
|
public IEvent getEndTurnEvent() {
|
||||||
return endTurnEvent;
|
return endTurnEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue