From 2de3d41bfd1d4a57d6945200794323f34f249d2e Mon Sep 17 00:00:00 2001 From: Alexander Hartung Date: Fri, 21 Jan 2022 17:44:58 +0100 Subject: [PATCH] CardDeck with 13 Cards of each Symbol --- src/main/java/solitaer/Card.java | 19 +++++++++++++++++ src/main/java/solitaer/CardDeck.java | 10 ++++----- src/test/java/solitaer/CardDeckTest.java | 27 +++++++++++++++++++++++- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/main/java/solitaer/Card.java b/src/main/java/solitaer/Card.java index 9fed8b5..76cc107 100644 --- a/src/main/java/solitaer/Card.java +++ b/src/main/java/solitaer/Card.java @@ -1,5 +1,7 @@ package solitaer; +import java.util.Objects; + import javax.swing.JPanel; enum Symbol { @@ -44,6 +46,23 @@ public class Card extends JPanel { return "Card [nr=" + nr + ", symbol=" + symbol + ", faceUp=" + faceUp + "]"; } + @Override + public int hashCode() { + return Objects.hash(faceUp, nr, symbol); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Card other = (Card) obj; + return faceUp == other.faceUp && nr == other.nr && symbol == other.symbol; + } + } diff --git a/src/main/java/solitaer/CardDeck.java b/src/main/java/solitaer/CardDeck.java index 1387542..f5036df 100644 --- a/src/main/java/solitaer/CardDeck.java +++ b/src/main/java/solitaer/CardDeck.java @@ -8,19 +8,19 @@ public class CardDeck { public CardDeck() { for (int j = 0; j < 4; j++) { - for (int i = 0; i < 13; i++) { + for (int i = 1; i <= 13; i++) { switch (j) { case 0: - deck.add(new Card(1, Symbol.Herz, false)); + deck.add(new Card(i, Symbol.Herz, false)); break; case 1: - deck.add(new Card(1, Symbol.Karo, false)); + deck.add(new Card(i, Symbol.Karo, false)); break; case 2: - deck.add(new Card(1, Symbol.Kreuz, false)); + deck.add(new Card(i, Symbol.Kreuz, false)); break; case 3: - deck.add(new Card(1, Symbol.Pik, false)); + deck.add(new Card(i, Symbol.Pik, false)); break; } diff --git a/src/test/java/solitaer/CardDeckTest.java b/src/test/java/solitaer/CardDeckTest.java index 448cc87..daa7371 100644 --- a/src/test/java/solitaer/CardDeckTest.java +++ b/src/test/java/solitaer/CardDeckTest.java @@ -1,7 +1,6 @@ package solitaer; import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.Mockito.verify; import java.util.stream.Stream; @@ -50,5 +49,31 @@ class CardDeckTest { } + + @Test + void testCardDeckNumber() { + + boolean result = true; + + result = CheckAllCards(Symbol.Herz) && + CheckAllCards(Symbol.Karo) && + CheckAllCards(Symbol.Kreuz) && + CheckAllCards(Symbol.Pik); + + assertTrue(result); + } + + + private boolean CheckAllCards(Symbol _sym) { + boolean result = true; + for(int i =1; i<=13; i++) { + if(deck.getDeck().contains(new Card(i, _sym, false))== false) { + result = false; + break; + } + } + return result; + } + }