|
|
@ -1,8 +1,10 @@ |
|
|
|
|
|
|
|
package de.hsfulda.onses; |
|
|
|
|
|
|
|
import de.hsfulda.onses.models.Game; |
|
|
|
import org.junit.jupiter.api.DisplayName; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
|
|
|
|
import de.hsfulda.onses.models.Card; |
|
|
@ -17,11 +19,13 @@ public class GameServiceTest { |
|
|
|
Card input = new Card().setColor(Card.Color.RED).setValue(Card.Value.EIGHT); |
|
|
|
// act |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
gameService.playCard(input); |
|
|
|
Card answer = gameService.getGame().getLastPlayedCard(); |
|
|
|
// assert |
|
|
|
assertEquals(input, answer); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("playCardBlackChoose") |
|
|
|
public void playCardBlackChoose() { |
|
|
@ -29,6 +33,7 @@ public class GameServiceTest { |
|
|
|
Card input = new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE); |
|
|
|
// act |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
gameService.playCard(input); |
|
|
|
Card answer = gameService.getGame().getLastPlayedCard(); |
|
|
|
// assert |
|
|
@ -43,12 +48,14 @@ public class GameServiceTest { |
|
|
|
boolean expected = true; |
|
|
|
// act |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.RED).setValue(Card.Value.FIVE)); |
|
|
|
|
|
|
|
boolean answer = gameService.legalMove(input); |
|
|
|
// assert |
|
|
|
assertEquals(expected, answer); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("legalMoveSameColorBlue") |
|
|
|
public void legalMoveSameColorBlue() { |
|
|
@ -57,16 +64,19 @@ public class GameServiceTest { |
|
|
|
boolean expected = true; |
|
|
|
// act |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.BLUE).setValue(Card.Value.ONE)); |
|
|
|
|
|
|
|
boolean answer = gameService.legalMove(input); |
|
|
|
// assert |
|
|
|
assertEquals(expected, answer); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("FillDrawCardDeck") |
|
|
|
public void FillDrawCardDeck() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
int expected = gameService.getGame().getDrawCardDeck().size() + 112; |
|
|
|
|
|
|
|
gameService.fillDrawDeck(); |
|
|
@ -83,6 +93,7 @@ public class GameServiceTest { |
|
|
|
boolean expected = true; |
|
|
|
// act |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.ONE)); |
|
|
|
|
|
|
|
boolean answer = gameService.legalMove(input); |
|
|
@ -98,6 +109,7 @@ public class GameServiceTest { |
|
|
|
boolean expected = true; |
|
|
|
// act |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.THREE)); |
|
|
|
|
|
|
|
boolean answer = gameService.legalMove(input); |
|
|
@ -113,6 +125,7 @@ public class GameServiceTest { |
|
|
|
boolean expected = true; |
|
|
|
// act |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.THREE)); |
|
|
|
|
|
|
|
boolean answer = gameService.legalMove(input); |
|
|
@ -128,12 +141,14 @@ public class GameServiceTest { |
|
|
|
boolean expected = true; |
|
|
|
// act |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.GREEN).setValue(Card.Value.FIVE)); |
|
|
|
|
|
|
|
boolean answer = gameService.legalMove(input); |
|
|
|
// assert |
|
|
|
assertEquals(expected, answer); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("ShuffelDeck") |
|
|
|
public void ShuffelDeck() { |
|
|
@ -159,8 +174,7 @@ public class GameServiceTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("RelationshipGameService_Game") |
|
|
|
public void RelationshipGameService_Game() |
|
|
|
{ |
|
|
|
public void RelationshipGameService_Game() { |
|
|
|
// arrange |
|
|
|
GameService expected = new GameService(); |
|
|
|
//act |
|
|
@ -168,10 +182,10 @@ public class GameServiceTest { |
|
|
|
// assert |
|
|
|
assertEquals(expected, answer); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("allRelationsTest") |
|
|
|
public void allRelationsTest () |
|
|
|
{ |
|
|
|
public void allRelationsTest() { |
|
|
|
// arrange |
|
|
|
GameService expected = new GameService(); |
|
|
|
//act |
|
|
@ -186,39 +200,39 @@ public class GameServiceTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("SkipTest") |
|
|
|
public void SkipTest () |
|
|
|
{ |
|
|
|
GameService gameservice = new GameService(); |
|
|
|
boolean expected = gameservice.getGame().getPlayerService().getCurrentTurn(); |
|
|
|
public void SkipTest() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
boolean expected = gameService.getGame().getPlayerService().getCurrentTurn(); |
|
|
|
|
|
|
|
gameservice.playCard(new Card().setValue(Card.Value.SKIP).setColor(Card.Color.BLACK)); |
|
|
|
gameService.playCard(new Card().setValue(Card.Value.SKIP).setColor(Card.Color.BLACK)); |
|
|
|
|
|
|
|
assertEquals(expected, gameservice.getGame().getPlayerService().getCurrentTurn()); |
|
|
|
assertEquals(expected, gameService.getGame().getPlayerService().getCurrentTurn()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("ReverseTest") |
|
|
|
public void ReverseTest () |
|
|
|
{ |
|
|
|
GameService gameservice = new GameService(); |
|
|
|
boolean expected = gameservice.getGame().getPlayerService().getCurrentTurn(); |
|
|
|
public void ReverseTest() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
boolean expected = gameService.getGame().getPlayerService().getCurrentTurn(); |
|
|
|
|
|
|
|
gameservice.playCard(new Card().setValue(Card.Value.REVERSE).setColor(Card.Color.BLACK)); |
|
|
|
gameService.playCard(new Card().setValue(Card.Value.REVERSE).setColor(Card.Color.BLACK)); |
|
|
|
|
|
|
|
assertEquals(expected, gameservice.getGame().getPlayerService().getCurrentTurn()); |
|
|
|
assertEquals(expected, gameService.getGame().getPlayerService().getCurrentTurn()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("ChooseTest") |
|
|
|
public void ChooseTest () |
|
|
|
{ |
|
|
|
GameService gameservice = new GameService(); |
|
|
|
public void ChooseTest() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
boolean expected = true; |
|
|
|
boolean answer = false; |
|
|
|
|
|
|
|
gameservice.playCard(new Card().setValue(Card.Value.CHOOSE).setColor(Card.Color.BLACK)); |
|
|
|
gameService.playCard(new Card().setValue(Card.Value.CHOOSE).setColor(Card.Color.BLACK)); |
|
|
|
|
|
|
|
if (gameservice.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) { |
|
|
|
if (gameService.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) { |
|
|
|
answer = true; |
|
|
|
} |
|
|
|
|
|
|
@ -228,27 +242,61 @@ public class GameServiceTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("ChooseDrawTest") |
|
|
|
public void ChooseDrawTest () |
|
|
|
{ |
|
|
|
GameService gameservice = new GameService(); |
|
|
|
public void ChooseDrawTest() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
boolean expected = true; |
|
|
|
boolean answer = false; |
|
|
|
|
|
|
|
gameservice.playCard(new Card().setValue(Card.Value.CHOOSEDRAW).setColor(Card.Color.BLACK)); |
|
|
|
gameService.playCard(new Card().setValue(Card.Value.CHOOSEDRAW).setColor(Card.Color.BLACK)); |
|
|
|
|
|
|
|
if (gameservice.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) { |
|
|
|
if (gameService.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK) { |
|
|
|
answer = true; |
|
|
|
} |
|
|
|
|
|
|
|
assertEquals(expected, answer); |
|
|
|
|
|
|
|
} |
|
|
|
@Test |
|
|
|
@DisplayName("DrawByChoiceForceKeep") |
|
|
|
public void DrawByChoiceForceKeep() { |
|
|
|
|
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
Card input = new Card().setColor(Card.Color.RED).setValue(Card.Value.ONE); |
|
|
|
|
|
|
|
gameService.getGame().getDrawCardDeck().clear(); |
|
|
|
gameService.getGame().getPlayerService().setCurrentTurn(true); |
|
|
|
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.GREEN).setValue(Card.Value.SEVEN)); |
|
|
|
gameService.getGame().addCardToDrawCardDeck(input); |
|
|
|
gameService.getGame().getPlayerService().getPlayerList().getFirst().addCardToPlayerDeck(new Card().setColor(Card.Color.BLUE).setValue(Card.Value.TWO)); |
|
|
|
gameService.drawCard(1); |
|
|
|
|
|
|
|
Card answer = gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().getLast(); |
|
|
|
|
|
|
|
assertEquals(input, answer); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("DrawCardPlayerDeckBot") |
|
|
|
public void DrawCardPlayerDeckBot() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
gameService.getGame().getPlayerService().setCurrentTurn(false); |
|
|
|
int before = gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().size(); |
|
|
|
gameService.drawCard(2); |
|
|
|
int after = gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().size(); |
|
|
|
|
|
|
|
int expected = 2; |
|
|
|
int answer = after - before; |
|
|
|
assertEquals(expected, answer); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("DrawCardDeckTest") |
|
|
|
public void DrawCardDeckTest () |
|
|
|
{ |
|
|
|
public void DrawCardDeckTest() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
int before = gameService.getGame().getDrawCardDeck().size(); |
|
|
|
gameService.drawCard(4); |
|
|
|
int after = gameService.getGame().getDrawCardDeck().size(); |
|
|
@ -257,23 +305,173 @@ public class GameServiceTest { |
|
|
|
int answer = before - after; |
|
|
|
assertEquals(expected, answer); |
|
|
|
} |
|
|
|
@Test |
|
|
|
@DisplayName("DrawCardPlayerDeck") |
|
|
|
public void DrawCardPlayerDeck() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
gameService.getGame().getPlayerService().setCurrentTurn(true); |
|
|
|
int before = gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().size(); |
|
|
|
gameService.drawCard(4); |
|
|
|
int after = gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().size(); |
|
|
|
|
|
|
|
int expected = 4; |
|
|
|
int answer = after - before; |
|
|
|
assertEquals(expected, answer); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("DrawCardDeckRemoveTest") |
|
|
|
public void DrawCardDeckRemoveTest () |
|
|
|
{ |
|
|
|
@DisplayName("DrawByChoiceForcePlay") |
|
|
|
public void DrawByChoiceForcePlay() { |
|
|
|
|
|
|
|
GameService gameService = new GameService(); |
|
|
|
Card card = gameService.getGame().getDrawCardDeck().getFirst(); |
|
|
|
gameService.setTest(true); |
|
|
|
Card input = new Card().setColor(Card.Color.RED).setValue(Card.Value.ONE); |
|
|
|
|
|
|
|
gameService.getGame().getDrawCardDeck().clear(); |
|
|
|
gameService.getGame().getPlayerService().setCurrentTurn(true); |
|
|
|
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.RED).setValue(Card.Value.SEVEN)); |
|
|
|
gameService.getGame().addCardToDrawCardDeck(input); |
|
|
|
gameService.getGame().getPlayerService().getPlayerList().getFirst().addCardToPlayerDeck(new Card().setColor(Card.Color.BLUE).setValue(Card.Value.TWO)); |
|
|
|
gameService.drawCard(1); |
|
|
|
int counter = 0; |
|
|
|
int expected = 0; |
|
|
|
|
|
|
|
Card answer = gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().getLast(); |
|
|
|
|
|
|
|
assertNotEquals(input, answer); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("CheckThatBotDeckHasSevenCardsAfterGameStart") |
|
|
|
public void CheckThatBotDeckHasSevenCardsAfterGameStart() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
|
|
|
|
gameService.setTest(true); |
|
|
|
int expected = 7; |
|
|
|
int actual = gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().size(); |
|
|
|
|
|
|
|
assertEquals(expected, actual); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("CheckFirstCardIsSet") |
|
|
|
public void CheckFirstCardIsSet() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
Card card = gameService.getGame().getLastPlayedCard(); |
|
|
|
|
|
|
|
boolean answer = card != null; |
|
|
|
|
|
|
|
assertTrue(answer); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("CheckFirstCardIsNotBlack") |
|
|
|
public void CheckFirstCardIsNotBlack() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
Card card = gameService.getGame().getLastPlayedCard(); |
|
|
|
|
|
|
|
boolean answer = card.getColor() != Card.Color.BLACK; |
|
|
|
|
|
|
|
assertTrue(answer); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("CheckResetOnBlackCards") |
|
|
|
public void CheckResetOnBlackCards() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
gameService.getGame().setLastPlayedCard(new Card().setColor(Card.Color.RED).setValue(Card.Value.FIVE)); |
|
|
|
gameService.playCard(new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE)); |
|
|
|
gameService.playCard(new Card().setColor(Card.Color.YELLOW).setValue(Card.Value.FIVE)); |
|
|
|
|
|
|
|
Card card = gameService.getGame().getDrawCardDeck().getLast(); |
|
|
|
|
|
|
|
assertEquals(Card.Color.BLACK, card.getColor()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("CheckThatPlayerReceivedSevenCards") |
|
|
|
public void CheckThatPlayerReceivedSevenCards() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
|
|
|
|
gameService.setTest(true); |
|
|
|
int numberOfCards = gameService.getGame().getPlayerService().getPlayerList().getFirst().getPlayerDeck().size(); |
|
|
|
|
|
|
|
assertEquals(7, numberOfCards); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("CheckThatFirstCardGetsRemovedFromDrawCardDeck") |
|
|
|
public void CheckThatFirstCardGetsRemovedFromDrawCardDeck() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
|
|
|
|
gameService.setTest(true); |
|
|
|
Card lastPlayedCard = gameService.getGame().getLastPlayedCard(); |
|
|
|
|
|
|
|
boolean lastPlayedCardDoesNotExistInDrawCardDeck = true; |
|
|
|
|
|
|
|
for (int i = 0; i < gameService.getGame().getDrawCardDeck().size(); i++) { |
|
|
|
if (gameService.getGame().getDrawCardDeck().get(i).getColor() == card.getColor() && gameService.getGame().getDrawCardDeck().get(i).getValue() == card.getValue()) counter++; |
|
|
|
if (gameService.getGame().getDrawCardDeck().get(i) == lastPlayedCard) { |
|
|
|
lastPlayedCardDoesNotExistInDrawCardDeck = false; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if (card.getColor() == Card.Color.BLACK) expected = 3; |
|
|
|
else expected = 1; |
|
|
|
|
|
|
|
assertEquals(expected, counter); |
|
|
|
assertTrue(lastPlayedCardDoesNotExistInDrawCardDeck); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("ChooseColorBotTest") |
|
|
|
public void ChooseColorBotTest() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
gameService.setTest(true); |
|
|
|
Card card = new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE); |
|
|
|
boolean answer = false; |
|
|
|
|
|
|
|
gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().clear(); |
|
|
|
gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().add(card); |
|
|
|
|
|
|
|
gameService.getGame().getPlayerService().setCurrentTurn(false); |
|
|
|
gameService.playCard(card); |
|
|
|
|
|
|
|
if (gameService.getGame().getLastPlayedCard().getColor() != Card.Color.BLACK){ |
|
|
|
answer = true; |
|
|
|
} |
|
|
|
|
|
|
|
assertTrue(answer); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("CheckIfTestWasInitializedWithFalse") |
|
|
|
public void CheckIfTestWasInitializedWithFalse() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
|
|
|
|
assertFalse(gameService.getTest()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("CheckIfTestCanBeSetToTrue") |
|
|
|
public void CheckIfTestCanBeSetToTrue() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
|
|
|
|
gameService.setTest(true); |
|
|
|
|
|
|
|
assertTrue(gameService.getTest()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@DisplayName("CheckIfBotMovesAutomaticallyAfterPlayer") |
|
|
|
public void CheckIfBotMovesAutomaticallyAfterPlayer() { |
|
|
|
GameService gameService = new GameService(); |
|
|
|
|
|
|
|
Card card = new Card().setColor(Card.Color.BLUE).setValue(Card.Value.ONE); |
|
|
|
gameService.getGame().getPlayerService().getPlayerList().getLast().getPlayerDeck().add(new Card().setColor(Card.Color.BLUE).setValue(Card.Value.FIVE)); |
|
|
|
|
|
|
|
gameService.playCard(card); |
|
|
|
|
|
|
|
boolean answer = gameService.getGame().getLastPlayedCard() != card; |
|
|
|
|
|
|
|
assertTrue(answer); |
|
|
|
} |
|
|
|
} |