added some gameTests and reformatted ServerStateTests
This commit is contained in:
@@ -2,25 +2,169 @@
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import pp.mdga.game.card.PowerCard;
|
||||
import pp.mdga.game.card.ShieldCard;
|
||||
import pp.mdga.game.card.SwapCard;
|
||||
import pp.mdga.game.card.TurboCard;
|
||||
import pp.mdga.message.client.LobbyReadyMessage;
|
||||
import pp.mdga.message.client.SelectTSKMessage;
|
||||
import pp.mdga.message.client.StartGameMessage;
|
||||
import pp.mdga.message.server.PlayCardMessage;
|
||||
import pp.mdga.message.server.ServerMessage;
|
||||
import pp.mdga.server.ServerGameLogic;
|
||||
import pp.mdga.server.ServerSender;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* this test-class tests the testcases T001-T016
|
||||
*/
|
||||
public class GameTest {
|
||||
|
||||
private ServerGameLogic logic;
|
||||
private Game game;
|
||||
|
||||
private Player playerHost;
|
||||
private int IDHost;
|
||||
private Player playerClient;
|
||||
private int IDClient;
|
||||
|
||||
/**
|
||||
* this method is used to set the variables for this test-class
|
||||
*/
|
||||
@Before
|
||||
public void setup() {
|
||||
game = new Game();
|
||||
logic = new ServerGameLogic(new ServerSender() {
|
||||
@Override
|
||||
public void send(int id, ServerMessage message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(ServerMessage message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnectClient(int id) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
|
||||
}
|
||||
}, game);
|
||||
|
||||
playerHost = new Player("Host");
|
||||
IDHost = 1;
|
||||
playerClient = new Player("Client");
|
||||
IDClient = 2;
|
||||
|
||||
game.addPlayer(IDHost, playerHost);
|
||||
game.setHost(IDHost);
|
||||
game.addPlayer(IDClient, playerClient);
|
||||
}
|
||||
|
||||
/**
|
||||
* this method tests, that, at the beginning of the game, all players have one piece on the start-field and one powerCard
|
||||
* <p>
|
||||
* T001
|
||||
*/
|
||||
@Test
|
||||
public void testStartLineUp() {
|
||||
// TODO: Implement test logic for starting line-up
|
||||
//tests if both player have no color and are not ready
|
||||
assertFalse(playerClient.isReady());
|
||||
assertFalse(playerHost.isReady());
|
||||
assertEquals(playerClient.getColor(), Color.NONE);
|
||||
assertEquals(playerHost.getColor(), Color.NONE);
|
||||
|
||||
//send the selectTSK-message
|
||||
logic.received(new SelectTSKMessage(Color.CYBER), IDClient);
|
||||
logic.received(new SelectTSKMessage(Color.ARMY), IDHost);
|
||||
|
||||
//tests if the Tsk's are set correctly
|
||||
assertFalse(playerClient.isReady());
|
||||
assertFalse(playerHost.isReady());
|
||||
assertEquals(playerClient.getColor(), Color.CYBER);
|
||||
assertEquals(playerHost.getColor(), Color.ARMY);
|
||||
|
||||
//sends and tests the readyMessage for the client
|
||||
logic.received(new LobbyReadyMessage(), IDClient);
|
||||
assertTrue(playerClient.isReady());
|
||||
assertFalse(playerHost.isReady());
|
||||
|
||||
//try to start the game, which should fail
|
||||
logic.received(new StartGameMessage(), IDHost);
|
||||
assertEquals(logic.getCurrentState(), logic.getLobbyState());
|
||||
|
||||
//sends and tests the readyMessage for the host
|
||||
logic.received(new LobbyReadyMessage(), IDHost);
|
||||
assertTrue(playerClient.isReady());
|
||||
assertTrue(playerHost.isReady());
|
||||
|
||||
//tests if the game has started after the gameStartMessage
|
||||
logic.received(new StartGameMessage(), IDHost);
|
||||
assertEquals(logic.getCurrentState(), logic.getGameState());
|
||||
|
||||
//tests the start positions for the pieces
|
||||
assertTrue(game.getBoard().getInfield()[playerHost.getStartNodeIndex()].isOccupied());
|
||||
assertTrue(game.getBoard().getInfield()[playerHost.getStartNodeIndex()].isOccupied(playerHost.getColor()));
|
||||
assertTrue(game.getBoard().getInfield()[playerClient.getStartNodeIndex()].isOccupied());
|
||||
assertTrue(game.getBoard().getInfield()[playerClient.getStartNodeIndex()].isOccupied(playerClient.getColor()));
|
||||
|
||||
//tests if the players have no handCards
|
||||
assertFalse(playerHost.getHandCards().isEmpty());
|
||||
assertFalse(playerClient.getHandCards().isEmpty());
|
||||
assertEquals(1, playerHost.getHandCards().size());
|
||||
assertEquals(1, playerClient.getHandCards().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* this method tests the drawPile
|
||||
* <p>
|
||||
* T002
|
||||
*/
|
||||
@Test
|
||||
public void testCreatePowerCardDeck() {
|
||||
// TODO: Implement test logic for creating power card deck
|
||||
//tests if both player have no color and are not ready
|
||||
assertFalse(playerClient.isReady());
|
||||
assertFalse(playerHost.isReady());
|
||||
assertEquals(playerClient.getColor(), Color.NONE);
|
||||
assertEquals(playerHost.getColor(), Color.NONE);
|
||||
|
||||
//send the selectTSK-message
|
||||
logic.received(new SelectTSKMessage(Color.CYBER), IDClient);
|
||||
logic.received(new SelectTSKMessage(Color.ARMY), IDHost);
|
||||
|
||||
//sends and tests the readyMessage for the client
|
||||
logic.received(new LobbyReadyMessage(), IDClient);
|
||||
logic.received(new LobbyReadyMessage(), IDHost);
|
||||
assertTrue(playerClient.isReady());
|
||||
assertTrue(playerHost.isReady());
|
||||
|
||||
//tests if the game has started after the gameStartMessage
|
||||
logic.received(new StartGameMessage(), IDHost);
|
||||
assertEquals(logic.getCurrentState(), logic.getGameState());
|
||||
|
||||
//tests if the players have no handCards
|
||||
assertFalse(playerHost.getHandCards().isEmpty());
|
||||
assertFalse(playerClient.getHandCards().isEmpty());
|
||||
assertEquals(1, playerHost.getHandCards().size());
|
||||
assertEquals(1, playerClient.getHandCards().size());
|
||||
|
||||
assertEquals(38, game.getDrawPile().size());
|
||||
ArrayList<PowerCard> cards = new ArrayList<>(game.getDrawPile());
|
||||
cards.add(playerClient.getHandCards().get(0));
|
||||
cards.add(playerHost.getHandCards().get(0));
|
||||
|
||||
//tests if the right amount of PowerCards are in the DrawPile
|
||||
assertEquals(12, cards.stream().filter((powerCard -> powerCard instanceof ShieldCard)).toArray().length);
|
||||
assertEquals(12, cards.stream().filter((powerCard -> powerCard instanceof SwapCard)).toArray().length);
|
||||
assertEquals(16, cards.stream().filter((powerCard -> powerCard instanceof TurboCard)).toArray().length);
|
||||
}
|
||||
|
||||
// UC-Game-02
|
||||
@@ -70,10 +214,32 @@ public void testChangeActivePlayer() {
|
||||
// TODO: Implement test logic for changing the active player
|
||||
}
|
||||
|
||||
// UC-Game-09
|
||||
/**
|
||||
* this test-method tests the chances fo the turbo-card
|
||||
* <p>
|
||||
* T012
|
||||
*/
|
||||
@Test
|
||||
public void testUseTurbo() {
|
||||
// TODO: Implement test logic for using a turbo power-up
|
||||
Die die = new Die();
|
||||
|
||||
ArrayList<Integer> modifier0 = new ArrayList<>();
|
||||
ArrayList<Integer> modifier1 = new ArrayList<>();
|
||||
ArrayList<Integer> modifier2 = new ArrayList<>();
|
||||
for (int i = 0; i < 10000000; i++) {
|
||||
die.modify();
|
||||
switch (die.getDieModifier()) {
|
||||
case 0 -> modifier0.add(0);
|
||||
case 1 -> modifier1.add(1);
|
||||
default -> modifier2.add(2);
|
||||
}
|
||||
}
|
||||
//System.out.println("modifier2.size(): " + modifier2.size() + " modifier1.size(): " + modifier1.size()+" modifier0.size(): " + modifier0.size());
|
||||
|
||||
//test with 5% range for the correct changes
|
||||
assertTrue(5700000 < modifier2.size() && modifier2.size() < 6300000);
|
||||
assertTrue(1950000 < modifier1.size() && modifier1.size() < 2050000);
|
||||
assertTrue(1950000 < modifier0.size() && modifier0.size() < 2050000);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -224,7 +224,6 @@ public void shutdown() {
|
||||
pieceClient1.setState(home);
|
||||
game.getBoard().setPieceOnBoard(19, pieceClient2); //for UC 13, 15
|
||||
pieceClient2.setState(active);
|
||||
//game.getBoard().setPieceOnBoard(); //todo
|
||||
|
||||
//set the host-pieces here
|
||||
game.getBoard().setPieceOnBoard(28, pieceHost0); //for UC 02,14 ,15, 03.01,4
|
||||
@@ -242,7 +241,6 @@ public void shutdown() {
|
||||
game.getBoard().setPieceOnBoard(12,pieceCyber1); //
|
||||
pieceCyber1.setState(active);
|
||||
game.getPlayerByColor(cyberColor).addWaitingPiece(pieceClient3); //for uc 7
|
||||
//game..... todo
|
||||
|
||||
//initializes the states
|
||||
gameState= serverGameLogic.getGameState();
|
||||
|
||||
@@ -354,7 +354,7 @@ public void testServerGameSubStatesToInterrupt() {
|
||||
*/
|
||||
@Test
|
||||
public void testServerGameToCeremony() {
|
||||
game.getBoard().setPieceOnBoard(22,null);
|
||||
game.getBoard().setPieceOnBoard(22, null);
|
||||
Piece piece1 = playerClient.getWaitingArea()[0];
|
||||
piece1.setState(PieceState.HOMEFINISHED);
|
||||
Piece piece2 = playerClient.getWaitingArea()[1];
|
||||
@@ -366,10 +366,10 @@ public void testServerGameToCeremony() {
|
||||
playerClient.removeWaitingPiece(piece2);
|
||||
playerClient.removeWaitingPiece(piece3);
|
||||
playerClient.removeWaitingPiece(piece4);
|
||||
playerClient.setPieceInHome(3,piece1);
|
||||
playerClient.setPieceInHome(2,piece2);
|
||||
playerClient.setPieceInHome(1,piece1);
|
||||
game.getBoard().setPieceOnBoard(29,piece4);
|
||||
playerClient.setPieceInHome(3, piece1);
|
||||
playerClient.setPieceInHome(2, piece2);
|
||||
playerClient.setPieceInHome(1, piece1);
|
||||
game.getBoard().setPieceOnBoard(29, piece4);
|
||||
|
||||
game.setActiveColor(playerClientColor);
|
||||
playerClient.setHandCards(new ArrayList<>());
|
||||
@@ -393,13 +393,13 @@ public void testServerGameToCeremony() {
|
||||
//sends the server in StartPiece
|
||||
assertEquals(choosePieceState.getCurrentState(), selectPieceState);
|
||||
|
||||
serverGameLogic.received(new RequestMoveMessage(piece4),IDPlayerClient);
|
||||
assertEquals(serverGameLogic.getCurrentState(),gameState);
|
||||
assertEquals(gameState.getCurrentState(),turnState);
|
||||
assertEquals(turnState.getCurrentState(),movePieceState);
|
||||
serverGameLogic.received(new RequestMoveMessage(piece4), IDPlayerClient);
|
||||
assertEquals(serverGameLogic.getCurrentState(), gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertEquals(turnState.getCurrentState(), movePieceState);
|
||||
|
||||
serverGameLogic.received(new AnimationEndMessage(),IDPlayerClient);
|
||||
serverGameLogic.received(new AnimationEndMessage(),IDPlayerHost);
|
||||
serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
|
||||
serverGameLogic.received(new AnimationEndMessage(), IDPlayerHost);
|
||||
|
||||
assertTrue(playerClient.isFinished());
|
||||
|
||||
@@ -672,12 +672,12 @@ public void testTurnToAnimation() {
|
||||
|
||||
//sends the second animationEndMessage
|
||||
serverGameLogic.received(animationEnd, IDPlayerHost);
|
||||
serverGameLogic.received(animationEnd,IDPlayerClient);
|
||||
serverGameLogic.received(animationEnd, IDPlayerClient);
|
||||
|
||||
//tests if the server is in the AnimationState
|
||||
assertEquals(serverGameLogic.getCurrentState(), gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertNotSame(game.getActiveColor(),playerClientColor);
|
||||
assertNotSame(game.getActiveColor(), playerClientColor);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -688,7 +688,7 @@ public void testTurnToAnimation() {
|
||||
*/
|
||||
@Test
|
||||
public void testTurnToGameEndState() {
|
||||
game.getBoard().setPieceOnBoard(22,null);
|
||||
game.getBoard().setPieceOnBoard(22, null);
|
||||
Piece piece1 = playerClient.getWaitingArea()[0];
|
||||
piece1.setState(PieceState.HOMEFINISHED);
|
||||
Piece piece2 = playerClient.getWaitingArea()[1];
|
||||
@@ -700,10 +700,10 @@ public void testTurnToGameEndState() {
|
||||
playerClient.removeWaitingPiece(piece2);
|
||||
playerClient.removeWaitingPiece(piece3);
|
||||
playerClient.removeWaitingPiece(piece4);
|
||||
playerClient.setPieceInHome(3,piece1);
|
||||
playerClient.setPieceInHome(2,piece2);
|
||||
playerClient.setPieceInHome(1,piece1);
|
||||
game.getBoard().setPieceOnBoard(29,piece4);
|
||||
playerClient.setPieceInHome(3, piece1);
|
||||
playerClient.setPieceInHome(2, piece2);
|
||||
playerClient.setPieceInHome(1, piece1);
|
||||
game.getBoard().setPieceOnBoard(29, piece4);
|
||||
|
||||
game.setActiveColor(playerClientColor);
|
||||
playerClient.setHandCards(new ArrayList<>());
|
||||
@@ -727,13 +727,13 @@ public void testTurnToGameEndState() {
|
||||
//sends the server in StartPiece
|
||||
assertEquals(choosePieceState.getCurrentState(), selectPieceState);
|
||||
|
||||
serverGameLogic.received(new RequestMoveMessage(piece4),IDPlayerClient);
|
||||
assertEquals(serverGameLogic.getCurrentState(),gameState);
|
||||
assertEquals(gameState.getCurrentState(),turnState);
|
||||
assertEquals(turnState.getCurrentState(),movePieceState);
|
||||
serverGameLogic.received(new RequestMoveMessage(piece4), IDPlayerClient);
|
||||
assertEquals(serverGameLogic.getCurrentState(), gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertEquals(turnState.getCurrentState(), movePieceState);
|
||||
|
||||
serverGameLogic.received(new AnimationEndMessage(),IDPlayerClient);
|
||||
serverGameLogic.received(new AnimationEndMessage(),IDPlayerHost);
|
||||
serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
|
||||
serverGameLogic.received(new AnimationEndMessage(), IDPlayerHost);
|
||||
|
||||
assertTrue(playerClient.isFinished());
|
||||
|
||||
@@ -911,23 +911,23 @@ public void testMovePieceToTurnEndState() {
|
||||
//tests if the server is in SelectPiece
|
||||
assertEquals(serverGameLogic.getCurrentState(), gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertEquals(turnState.getCurrentState(),choosePieceState);
|
||||
assertEquals(choosePieceState.getCurrentState(),selectPieceState);
|
||||
assertEquals(turnState.getCurrentState(), choosePieceState);
|
||||
assertEquals(choosePieceState.getCurrentState(), selectPieceState);
|
||||
|
||||
serverGameLogic.received(new RequestMoveMessage(pieceClient4),IDPlayerClient);
|
||||
serverGameLogic.received(new RequestMoveMessage(pieceClient4), IDPlayerClient);
|
||||
|
||||
//tests if the server is in SelectPiece
|
||||
assertEquals(serverGameLogic.getCurrentState(), gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertEquals(turnState.getCurrentState(),movePieceState);
|
||||
assertEquals(turnState.getCurrentState(), movePieceState);
|
||||
|
||||
serverGameLogic.received(new AnimationEndMessage(),IDPlayerClient);
|
||||
serverGameLogic.received(new AnimationEndMessage(),IDPlayerHost);
|
||||
serverGameLogic.received(new AnimationEndMessage(), IDPlayerClient);
|
||||
serverGameLogic.received(new AnimationEndMessage(), IDPlayerHost);
|
||||
|
||||
assertEquals(serverGameLogic.getCurrentState(), gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertNotEquals(turnState.getCurrentState(),movePieceState);
|
||||
assertNotSame(game.getActiveColor(),playerClientColor);
|
||||
assertNotEquals(turnState.getCurrentState(), movePieceState);
|
||||
assertNotSame(game.getActiveColor(), playerClientColor);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1250,7 +1250,7 @@ public void testNoPieceToNoTurn() {
|
||||
//tests if the server is in WaitPiece
|
||||
assertEquals(serverGameLogic.getCurrentState(), gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertNotSame(game.getActiveColor(),playerClientColor);
|
||||
assertNotSame(game.getActiveColor(), playerClientColor);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1283,7 +1283,7 @@ public void testNoTurnToTurnEndState() {
|
||||
//tests if the server is in WaitPiece
|
||||
assertEquals(serverGameLogic.getCurrentState(), gameState);
|
||||
assertEquals(gameState.getCurrentState(), turnState);
|
||||
assertNotSame(game.getActiveColor(),playerClientColor);
|
||||
assertNotSame(game.getActiveColor(), playerClientColor);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1369,7 +1369,7 @@ public void testWaitingPieceToMovePiece() {
|
||||
assertEquals(turnState.getCurrentState(), choosePieceState);
|
||||
assertEquals(choosePieceState.getCurrentState(), waitingPieceState);
|
||||
|
||||
serverGameLogic.received(new RequestMoveMessage(playerClient.getWaitingPiece()),IDPlayerClient);
|
||||
serverGameLogic.received(new RequestMoveMessage(playerClient.getWaitingPiece()), IDPlayerClient);
|
||||
|
||||
//tests if the server is in WaitPiece
|
||||
assertEquals(serverGameLogic.getCurrentState(), gameState);
|
||||
|
||||
Reference in New Issue
Block a user