added some testmethods for the piecetest

This commit is contained in:
Benjamin Feyer
2024-12-02 04:19:52 +01:00
parent 2cb8e512e6
commit 798b6ebe1d

View File

@@ -203,17 +203,17 @@ public void disconnectClient(int id) {
*/ */
@Test @Test
public void testMove() { public void testMove() {
//sends the server in selectPiece //sends the server in firstRoll
serverGameLogic.setCurrentState(gameState); serverGameLogic.setCurrentState(gameState);
serverGameLogic.getGameState().setCurrentState(turnState); gameState.setCurrentState(turnState);
serverGameLogic.getGameState().getTurnState().setCurrentState(choosePieceState); turnState.setCurrentState(rollDiceState);
serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState); rollDiceState.setCurrentState(firstRollState);
//tests if the server is in selectPieces //tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState); assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(gameState.getCurrentState(), turnState); assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),choosePieceState); assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(choosePieceState.getCurrentState(),selectPieceState); assertEquals(rollDiceState.getCurrentState(),firstRollState);
//sets the active Player to host //sets the active Player to host
game.setActiveColor(hostColor); game.setActiveColor(hostColor);
@@ -241,17 +241,17 @@ public void testMove() {
*/ */
@Test @Test
public void testCantMove() { public void testCantMove() {
//sends the server in selectPiece //sends the server in firstRoll
serverGameLogic.setCurrentState(gameState); serverGameLogic.setCurrentState(gameState);
serverGameLogic.getGameState().setCurrentState(turnState); gameState.setCurrentState(turnState);
serverGameLogic.getGameState().getTurnState().setCurrentState(choosePieceState); turnState.setCurrentState(rollDiceState);
serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState); rollDiceState.setCurrentState(firstRollState);
//tests if the server is in selectPieces //tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState); assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(gameState.getCurrentState(), turnState); assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),choosePieceState); assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(choosePieceState.getCurrentState(),selectPieceState); assertEquals(rollDiceState.getCurrentState(),firstRollState);
//set active player to army //set active player to army
game.setActiveColor(clientColor); game.setActiveColor(clientColor);
@@ -293,17 +293,17 @@ public void testNoPossibleMove() {
*/ */
@Test @Test
public void testThrow() { public void testThrow() {
//sends the server in selectPiece //sends the server in firstRoll
serverGameLogic.setCurrentState(gameState); serverGameLogic.setCurrentState(gameState);
serverGameLogic.getGameState().setCurrentState(turnState); gameState.setCurrentState(turnState);
serverGameLogic.getGameState().getTurnState().setCurrentState(choosePieceState); turnState.setCurrentState(rollDiceState);
serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState); rollDiceState.setCurrentState(firstRollState);
//tests if the server is in selectPieces //tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState); assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(gameState.getCurrentState(), turnState); assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),choosePieceState); assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(choosePieceState.getCurrentState(),selectPieceState); assertEquals(rollDiceState.getCurrentState(),firstRollState);
//set active player to host //set active player to host
game.setActiveColor(hostColor); game.setActiveColor(hostColor);
@@ -335,17 +335,17 @@ public void testThrow() {
*/ */
@Test @Test
public void testGetThrown() { public void testGetThrown() {
//sends the server in selectPiece //sends the server in firstRoll
serverGameLogic.setCurrentState(gameState); serverGameLogic.setCurrentState(gameState);
serverGameLogic.getGameState().setCurrentState(turnState); gameState.setCurrentState(turnState);
serverGameLogic.getGameState().getTurnState().setCurrentState(choosePieceState); turnState.setCurrentState(rollDiceState);
serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState); rollDiceState.setCurrentState(firstRollState);
//tests if the server is in selectPieces //tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState); assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(gameState.getCurrentState(), turnState); assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),choosePieceState); assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(choosePieceState.getCurrentState(),selectPieceState); assertEquals(rollDiceState.getCurrentState(),firstRollState);
//set active player to host //set active player to host
game.setActiveColor(hostColor); game.setActiveColor(hostColor);
@@ -371,17 +371,17 @@ public void testGetThrown() {
*/ */
@Test @Test
public void testLeaveWaitingArea() { public void testLeaveWaitingArea() {
//sends the server in selectPiece //sends the server in firstRoll
serverGameLogic.setCurrentState(gameState); serverGameLogic.setCurrentState(gameState);
serverGameLogic.getGameState().setCurrentState(turnState); gameState.setCurrentState(turnState);
serverGameLogic.getGameState().getTurnState().setCurrentState(choosePieceState); turnState.setCurrentState(rollDiceState);
serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState); rollDiceState.setCurrentState(firstRollState);
//tests if the server is in selectPieces //tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState); assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(gameState.getCurrentState(), turnState); assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),choosePieceState); assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(choosePieceState.getCurrentState(),selectPieceState); assertEquals(rollDiceState.getCurrentState(),firstRollState);
//set active player to host //set active player to host
game.setActiveColor(hostColor); game.setActiveColor(hostColor);
@@ -444,23 +444,40 @@ public void testCantLeaveStartingField() {
*/ */
@Test @Test
public void testReachBonusField() { public void testReachBonusField() {
// TODO: Implement test logic for when a piece reaches a bonus field //sends the server in firstRoll
//sends the server in RollDice serverGameLogic.setCurrentState(gameState);
gameState.setCurrentState(turnState);
turnState.setCurrentState(rollDiceState);
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
//gets the top bonusCard
BonusCard card = game.getDrawPile().get(0); BonusCard card = game.getDrawPile().get(0);
//sets the active Player to Host //sets the active Player to Host
game.setActiveColor(hostColor); game.setActiveColor(hostColor);
//sets the dice-seed to 4 //sets the dice-seed to 4
game.setDie(die4);
//sends the requestDice-Message //sends the requestDice-Message
serverGameLogic.setCurrentState(serverGameLogic.getGameState()); serverGameLogic.received(new RequestDieMessage(),IDHost);
//requestMOve of hostPiece3 //requestMove of hostPiece3
serverGameLogic.received(new RequestMoveMessage(pieceHost3.getUuid()),IDHost);
//tests the position of hostPiece3 //tests the position of hostPiece3
assertTrue(game.getBoard().getInfield()[4].isOccupied());
assertEquals(game.getBoard().getInfield()[4].getOccupant(),pieceHost3);
//tests if the player has received a bonusCard //tests if the player has received a bonusCard
assertNotEquals(card, game.getDrawPile().get(0));
assertTrue(game.getPlayers().get(IDHost).getHandCards().stream().toList().contains(card));
} }
/** /**
@@ -543,7 +560,33 @@ public void testEnterHouse() {
*/ */
@Test @Test
public void testOnlyEnterOwnHouse() { public void testOnlyEnterOwnHouse() {
// TODO: Implement test logic to ensure a piece can only enter its own house //sends the server in firstRoll
serverGameLogic.setCurrentState(gameState);
gameState.setCurrentState(turnState);
turnState.setCurrentState(rollDiceState);
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
//set activePlayer to client
game.setActiveColor(hostColor);
//set the die in Game to 3
game.setDie(die3);
//sends the request-Dice-message
serverGameLogic.received(new RequestDieMessage(),IDHost);
//sends the requestMove-message for pieceClient1
serverGameLogic.received(new RequestMoveMessage(pieceHost1.getUuid()),IDHost);
//tests if hostPiece1 is at idx 20
assertTrue(game.getBoard().getInfield()[20].isOccupied());
assertEquals(game.getBoard().getInfield()[20].getOccupant(),pieceHost1);
} }
/** /**
@@ -554,7 +597,33 @@ public void testOnlyEnterOwnHouse() {
*/ */
@Test @Test
public void testActiveHomePiece() { public void testActiveHomePiece() {
// TODO: Implement test logic for activating a piece in the home area //sends the server in firstRoll
serverGameLogic.setCurrentState(gameState);
gameState.setCurrentState(turnState);
turnState.setCurrentState(rollDiceState);
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
//set activePlayer to client
game.setActiveColor(clientColor);
//set the die in Game to 2
game.setDie(die2);
//sends the request-Dice-message
serverGameLogic.received(new RequestDieMessage(),IDClient);
//sends the requestMove-message for pieceClient1
serverGameLogic.received(new RequestMoveMessage(pieceHost1.getUuid()),IDClient);
//tests if clientPiece1 is in the home at idx 3
assertTrue(game.getBoard().getPlayerData().get(clientColor).getHomeNodes()[3].isOccupied());
assertEquals(game.getBoard().getPlayerData().get(clientColor).getHomeNodes()[3].getOccupant(),pieceClient1);
} }
/** /**
@@ -565,16 +634,33 @@ public void testActiveHomePiece() {
*/ */
@Test @Test
public void testCantJumpOverFigureInHouse() { public void testCantJumpOverFigureInHouse() {
// TODO: Implement test logic to prevent jumping over another piece in the house //sends the server in firstRoll
//sets the active Player to Client serverGameLogic.setCurrentState(gameState);
gameState.setCurrentState(turnState);
turnState.setCurrentState(rollDiceState);
rollDiceState.setCurrentState(firstRollState);
//sets the dice-seed to 1 //tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
//set activePlayer to client
game.setActiveColor(clientColor);
//set the die in Game to 4
game.setDie(die4);
//send requestDice-Message //send requestDice-Message
serverGameLogic.received(new RequestDieMessage(),IDClient);
//sends requestMoveMessage with clientPiece 02 //sends requestMoveMessage with clientPiece 02
serverGameLogic.received(new RequestMoveMessage(pieceHost2.getUuid()),IDHost);
//tests, if the piece is in the first slot of the home //tests, if the clientPiece02 is at idx 19
assertTrue(game.getBoard().getInfield()[19].isOccupied());
assertEquals(game.getBoard().getInfield()[20].getOccupant(),pieceClient2);
} }
/** /**
@@ -596,18 +682,37 @@ public void testActiveHomePieceBlocked() {
*/ */
@Test @Test
public void testOnStartingFieldWithShield() { public void testOnStartingFieldWithShield() {
// TODO: Implement test logic for a piece on the starting field with a shield
//sets the color to host //sets the color to host
//sets the dice-seed to 2 //sets the dice to 2
game.setDie(die2);
//sets the shield of hostPiece1 true //sets the shield of hostPiece1 true
pieceHost1.setShield(ShieldState.ACTIVE);
//sends the server in firstRoll
serverGameLogic.setCurrentState(gameState);
gameState.setCurrentState(turnState);
turnState.setCurrentState(rollDiceState);
rollDiceState.setCurrentState(firstRollState);
//tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(rollDiceState.getCurrentState(),firstRollState);
//sends the requestDice-message //sends the requestDice-message
serverGameLogic.received(new RequestDieMessage(),IDHost);
//sends the moveMessage //sends the moveMessage
serverGameLogic.received(new RequestMoveMessage(pieceHost1.getUuid()),IDHost);
//tests the position of the hostPiece1 and that shield is suppressed //tests the position of the hostPiece1 and that shield is suppressed
assertTrue(game.getBoard().getInfield()[20].isOccupied());
assertEquals(game.getBoard().getInfield()[20].getOccupant(),pieceClient1);
assertEquals(pieceHost1.getShield(),ShieldState.SUPPRESSED);
} }
/** /**
@@ -627,17 +732,17 @@ public void testThrowFigureWithShield() {
//set die to 1 //set die to 1
game.setDie(die1); game.setDie(die1);
//sends the server in selectPiece //sends the server in firstRoll
serverGameLogic.setCurrentState(gameState); serverGameLogic.setCurrentState(gameState);
serverGameLogic.getGameState().setCurrentState(turnState); gameState.setCurrentState(turnState);
serverGameLogic.getGameState().getTurnState().setCurrentState(choosePieceState); turnState.setCurrentState(rollDiceState);
serverGameLogic.getGameState().getTurnState().getChoosePieceState().setCurrentState(selectPieceState); rollDiceState.setCurrentState(firstRollState);
//tests if the server is in selectPieces //tests if the server is in firstRoll
assertEquals(serverGameLogic.getCurrentState(),gameState); assertEquals(serverGameLogic.getCurrentState(),gameState);
assertEquals(gameState.getCurrentState(), turnState); assertEquals(gameState.getCurrentState(), turnState);
assertEquals(turnState.getCurrentState(),choosePieceState); assertEquals(turnState.getCurrentState(),rollDiceState);
assertEquals(choosePieceState.getCurrentState(),selectPieceState); assertEquals(rollDiceState.getCurrentState(),firstRollState);
//send requestDice //send requestDice
serverGameLogic.received(new RequestDieMessage(),IDHost); serverGameLogic.received(new RequestDieMessage(),IDHost);