Browse Source

CardDeck with 13 Cards of each Symbol

feature_solitaer_001
Alexander Hartung 3 years ago
parent
commit
2de3d41bfd
  1. 19
      src/main/java/solitaer/Card.java
  2. 10
      src/main/java/solitaer/CardDeck.java
  3. 27
      src/test/java/solitaer/CardDeckTest.java

19
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;
}
}

10
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;
}

27
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;
@ -51,4 +50,30 @@ 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;
}
}
Loading…
Cancel
Save