From 02d30a8a069da68f9c5499ceea6703033720ff38 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 31 Jan 2024 13:22:30 +0100 Subject: [PATCH 1/6] add fillDrawDeck --- .../de/hsfulda/onses/services/GameService.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index bdee4d5..d1a440d 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -4,6 +4,8 @@ import de.hsfulda.onses.models.Card; import de.hsfulda.onses.models.Game; import de.hsfulda.onses.models.Player; +import java.util.Collections; + public class GameService { private final Game game; public GameService(Game game) { @@ -34,4 +36,20 @@ public class GameService { return legalMoveFound; } + public void fillDrawDeck() { + for (Card.Color i : Card.Color.values()){ + for (Card.Value j : Card.Value.values()){ + if (i != Card.Color.BLACK && j != Card.Value.CHOOSE && j != Card.Value.CHOOSEDRAW){ + game.addCardToDrawCardDeck(new Card().setColor(i).setValue(j)); + game.addCardToDrawCardDeck(new Card().setColor(i).setValue(j)); + } + } + } + + for (int i = 0; i != 4; i++){ + game.addCardToDrawCardDeck(new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSE)); + game.addCardToDrawCardDeck(new Card().setColor(Card.Color.BLACK).setValue(Card.Value.CHOOSEDRAW)); + } + } + } From b97fc758605664301f0b1907b83dda61f87f3ada Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 31 Jan 2024 13:29:04 +0100 Subject: [PATCH 2/6] Test.FillDrawCardDeck --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 8a22108..ec2d8a6 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -1,6 +1,7 @@ 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.*; @@ -63,5 +64,15 @@ public class GameServiceTest { // assert assertEquals(expected, answer); } + @Test + @DisplayName("FillDrawCardDeck") + public void FillDrawCardDeck() { + GameService gameService = new GameService(); + int expected = 112; + + gameService.fillDrawDeck(); + int answer = gameService.getGame().getDrawCardDeck().size(); + assertEquals(expected, answer); + } } From 9e2839db7f3f8f3975a3427e2651db93f28102ab Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 31 Jan 2024 13:32:40 +0100 Subject: [PATCH 3/6] add shuffleDeck --- src/main/java/de/hsfulda/onses/services/GameService.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/de/hsfulda/onses/services/GameService.java b/src/main/java/de/hsfulda/onses/services/GameService.java index d1a440d..d0c36ab 100644 --- a/src/main/java/de/hsfulda/onses/services/GameService.java +++ b/src/main/java/de/hsfulda/onses/services/GameService.java @@ -52,4 +52,8 @@ public class GameService { } } + public void shuffleDeck() { + Collections.shuffle(game.getDrawCardDeck()); + } + } From 22ca40565c5bb106270fec8ef3a0d1b869159a02 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 31 Jan 2024 13:34:27 +0100 Subject: [PATCH 4/6] Test.ShuffleDeck --- .../java/de/hsfulda/onses/GameServiceTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index ec2d8a6..a95ac91 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -75,4 +75,22 @@ public class GameServiceTest { assertEquals(expected, answer); } + + @Test + @DisplayName("ShuffelDeck") + public void ShuffelDeck() { + GameService shuffled = new GameService(); + GameService notshuffled = new GameService(); + + shuffled.fillDrawDeck(); + notshuffled.fillDrawDeck(); + shuffled.shuffleDeck(); + + for (int i = 0; i < 10; i++) { + if (shuffled.getGame().getDrawCardDeck().get(i).getValue() == notshuffled.getGame().getDrawCardDeck().get(i).getValue() && + shuffled.getGame().getDrawCardDeck().get(i).getColor() == notshuffled.getGame().getDrawCardDeck().get(i).getColor()) { + fail("Deck wurde nicht richtig gemischt"); + } + } + } } From 2c8cc9cf41be5b683c311036987e313af8380ede Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 31 Jan 2024 13:45:29 +0100 Subject: [PATCH 5/6] refactoring: Improve TestShuffleDeck --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index a95ac91..9910bea 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -86,9 +86,14 @@ public class GameServiceTest { notshuffled.fillDrawDeck(); shuffled.shuffleDeck(); - for (int i = 0; i < 10; i++) { + int counter = 0; + + for (int i = 0; i < 112; i++) { if (shuffled.getGame().getDrawCardDeck().get(i).getValue() == notshuffled.getGame().getDrawCardDeck().get(i).getValue() && shuffled.getGame().getDrawCardDeck().get(i).getColor() == notshuffled.getGame().getDrawCardDeck().get(i).getColor()) { + counter ++; + } + if (counter == 112) { fail("Deck wurde nicht richtig gemischt"); } } From 3f5b2b7d73eeb267ec6b57ddcdc4054e288413e9 Mon Sep 17 00:00:00 2001 From: fdai7906 Date: Wed, 31 Jan 2024 13:53:00 +0100 Subject: [PATCH 6/6] refactoring: TestShuffleDeck Improve Safety --- src/test/java/de/hsfulda/onses/GameServiceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/de/hsfulda/onses/GameServiceTest.java b/src/test/java/de/hsfulda/onses/GameServiceTest.java index 9910bea..b22147d 100644 --- a/src/test/java/de/hsfulda/onses/GameServiceTest.java +++ b/src/test/java/de/hsfulda/onses/GameServiceTest.java @@ -88,12 +88,12 @@ public class GameServiceTest { int counter = 0; - for (int i = 0; i < 112; i++) { + for (int i = 0; i < notshuffled.getGame().getDrawCardDeck().size(); i++) { if (shuffled.getGame().getDrawCardDeck().get(i).getValue() == notshuffled.getGame().getDrawCardDeck().get(i).getValue() && shuffled.getGame().getDrawCardDeck().get(i).getColor() == notshuffled.getGame().getDrawCardDeck().get(i).getColor()) { counter ++; } - if (counter == 112) { + if (counter == notshuffled.getGame().getDrawCardDeck().size()) { fail("Deck wurde nicht richtig gemischt"); } }