Browse Source

refactoring: addLastPlayedCardToDrawCardDeck

main
fdai7793 11 months ago
parent
commit
b9a8f9a26e
  1. 8
      src/main/java/de/hsfulda/onses/services/GameService.java
  2. 39
      src/test/java/de/hsfulda/onses/GameServiceTest.java

8
src/main/java/de/hsfulda/onses/services/GameService.java

@ -52,13 +52,17 @@ public class GameService {
} }
} }
public void playCard(Card card) {
// add lastPlayedCard back to drawCardDeck
public void addLastPlayedCardToDrawCardDeck() {
Card lastCard = game.getLastPlayedCard(); Card lastCard = game.getLastPlayedCard();
if (lastCard.getValue() == Card.Value.CHOOSE || lastCard.getValue() == Card.Value.CHOOSEDRAW) { if (lastCard.getValue() == Card.Value.CHOOSE || lastCard.getValue() == Card.Value.CHOOSEDRAW) {
lastCard.setColor(Card.Color.BLACK); lastCard.setColor(Card.Color.BLACK);
} }
game.addCardToDrawCardDeck(lastCard); game.addCardToDrawCardDeck(lastCard);
}
public void playCard(Card card) {
// add lastPlayedCard back to drawCardDeck
this.addLastPlayedCardToDrawCardDeck();
game.setLastPlayedCard(card); game.setLastPlayedCard(card);
// check for special rules (draw, colorchoose, skip,...) // check for special rules (draw, colorchoose, skip,...)
// Skip // Skip

39
src/test/java/de/hsfulda/onses/GameServiceTest.java

@ -3,6 +3,7 @@ package de.hsfulda.onses;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import de.hsfulda.onses.models.Card; import de.hsfulda.onses.models.Card;
@ -22,6 +23,7 @@ public class GameServiceTest {
// assert // assert
assertEquals(input, answer); assertEquals(input, answer);
} }
@Test @Test
@DisplayName("playCardBlackChoose") @DisplayName("playCardBlackChoose")
public void playCardBlackChoose() { public void playCardBlackChoose() {
@ -49,6 +51,7 @@ public class GameServiceTest {
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
} }
@Test @Test
@DisplayName("legalMoveSameColorBlue") @DisplayName("legalMoveSameColorBlue")
public void legalMoveSameColorBlue() { public void legalMoveSameColorBlue() {
@ -63,6 +66,7 @@ public class GameServiceTest {
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
} }
@Test @Test
@DisplayName("FillDrawCardDeck") @DisplayName("FillDrawCardDeck")
public void FillDrawCardDeck() { public void FillDrawCardDeck() {
@ -134,6 +138,7 @@ public class GameServiceTest {
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
} }
@Test @Test
@DisplayName("ShuffelDeck") @DisplayName("ShuffelDeck")
public void ShuffelDeck() { public void ShuffelDeck() {
@ -159,8 +164,7 @@ public class GameServiceTest {
@Test @Test
@DisplayName("RelationshipGameService_Game") @DisplayName("RelationshipGameService_Game")
public void RelationshipGameService_Game()
{
public void RelationshipGameService_Game() {
// arrange // arrange
GameService expected = new GameService(); GameService expected = new GameService();
//act //act
@ -168,10 +172,10 @@ public class GameServiceTest {
// assert // assert
assertEquals(expected, answer); assertEquals(expected, answer);
} }
@Test @Test
@DisplayName("allRelationsTest") @DisplayName("allRelationsTest")
public void allRelationsTest ()
{
public void allRelationsTest() {
// arrange // arrange
GameService expected = new GameService(); GameService expected = new GameService();
//act //act
@ -186,8 +190,7 @@ public class GameServiceTest {
@Test @Test
@DisplayName("SkipTest") @DisplayName("SkipTest")
public void SkipTest ()
{
public void SkipTest() {
GameService gameservice = new GameService(); GameService gameservice = new GameService();
boolean expected = gameservice.getGame().getPlayerService().getCurrentTurn(); boolean expected = gameservice.getGame().getPlayerService().getCurrentTurn();
@ -198,8 +201,7 @@ public class GameServiceTest {
@Test @Test
@DisplayName("ReverseTest") @DisplayName("ReverseTest")
public void ReverseTest ()
{
public void ReverseTest() {
GameService gameservice = new GameService(); GameService gameservice = new GameService();
boolean expected = gameservice.getGame().getPlayerService().getCurrentTurn(); boolean expected = gameservice.getGame().getPlayerService().getCurrentTurn();
@ -210,8 +212,7 @@ public class GameServiceTest {
@Test @Test
@DisplayName("ChooseTest") @DisplayName("ChooseTest")
public void ChooseTest ()
{
public void ChooseTest() {
GameService gameservice = new GameService(); GameService gameservice = new GameService();
boolean expected = true; boolean expected = true;
boolean answer = false; boolean answer = false;
@ -228,8 +229,7 @@ public class GameServiceTest {
@Test @Test
@DisplayName("ChooseDrawTest") @DisplayName("ChooseDrawTest")
public void ChooseDrawTest ()
{
public void ChooseDrawTest() {
GameService gameservice = new GameService(); GameService gameservice = new GameService();
boolean expected = true; boolean expected = true;
boolean answer = false; boolean answer = false;
@ -246,8 +246,7 @@ public class GameServiceTest {
@Test @Test
@DisplayName("DrawCardDeckTest") @DisplayName("DrawCardDeckTest")
public void DrawCardDeckTest ()
{
public void DrawCardDeckTest() {
GameService gameService = new GameService(); GameService gameService = new GameService();
int before = gameService.getGame().getDrawCardDeck().size(); int before = gameService.getGame().getDrawCardDeck().size();
gameService.drawCard(4); gameService.drawCard(4);
@ -260,15 +259,15 @@ public class GameServiceTest {
@Test @Test
@DisplayName("DrawCardDeckRemoveTest") @DisplayName("DrawCardDeckRemoveTest")
public void DrawCardDeckRemoveTest ()
{
public void DrawCardDeckRemoveTest() {
GameService gameService = new GameService(); GameService gameService = new GameService();
Card card = gameService.getGame().getDrawCardDeck().getFirst(); Card card = gameService.getGame().getDrawCardDeck().getFirst();
gameService.drawCard(1); gameService.drawCard(1);
int counter = 0; int counter = 0;
int expected = 0; int expected = 0;
for (int i = 0; i < gameService.getGame().getDrawCardDeck().size(); i++) { 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).getColor() == card.getColor() && gameService.getGame().getDrawCardDeck().get(i).getValue() == card.getValue())
counter++;
} }
if (card.getColor() == Card.Color.BLACK) expected = 3; if (card.getColor() == Card.Color.BLACK) expected = 3;
else expected = 1; else expected = 1;
@ -278,8 +277,7 @@ public class GameServiceTest {
@Test @Test
@DisplayName("CheckFirstCardIsSet") @DisplayName("CheckFirstCardIsSet")
public void CheckFirstCardIsSet ()
{
public void CheckFirstCardIsSet() {
GameService gameService = new GameService(); GameService gameService = new GameService();
Card card = gameService.getGame().getLastPlayedCard(); Card card = gameService.getGame().getLastPlayedCard();
@ -290,8 +288,7 @@ public class GameServiceTest {
@Test @Test
@DisplayName("CheckFirstCardIsNotBlack") @DisplayName("CheckFirstCardIsNotBlack")
public void CheckFirstCardIsNotBlack ()
{
public void CheckFirstCardIsNotBlack() {
GameService gameService = new GameService(); GameService gameService = new GameService();
Card card = gameService.getGame().getLastPlayedCard(); Card card = gameService.getGame().getLastPlayedCard();

Loading…
Cancel
Save