Browse Source

Refactor CardDeck and CardDeckTest

feature_solitaer_001
Alexander Hartung 3 years ago
parent
commit
a10127d1b2
  1. 14
      src/main/java/solitaer/CardDeck.java
  2. 10
      src/test/java/solitaer/CardDeckTest.java

14
src/main/java/solitaer/CardDeck.java

@ -7,20 +7,20 @@ public class CardDeck {
private ArrayList<Card> deck = new ArrayList<Card>(); private ArrayList<Card> deck = new ArrayList<Card>();
public CardDeck() { public CardDeck() {
for (int j = 0; j < 4; j++) {
for (int i = 1; i <= 13; i++) {
switch (j) {
for (int symboleZähler = 0; symboleZähler < 4; symboleZähler++) {
for (int nrZähler = 1; nrZähler <= 13; nrZähler++) {
switch (symboleZähler) {
case 0: case 0:
deck.add(new Card(i, Symbol.Herz, false));
deck.add(new Card(nrZähler, Symbol.Herz, false));
break; break;
case 1: case 1:
deck.add(new Card(i, Symbol.Karo, false));
deck.add(new Card(nrZähler, Symbol.Karo, false));
break; break;
case 2: case 2:
deck.add(new Card(i, Symbol.Kreuz, false));
deck.add(new Card(nrZähler, Symbol.Kreuz, false));
break; break;
case 3: case 3:
deck.add(new Card(i, Symbol.Pik, false));
deck.add(new Card(nrZähler, Symbol.Pik, false));
break; break;
} }

10
src/test/java/solitaer/CardDeckTest.java

@ -24,12 +24,13 @@ class CardDeckTest {
@ParameterizedTest @ParameterizedTest
@MethodSource("testSymbole") @MethodSource("testSymbole")
//Jedes Symbol muss einmal vorhand sein
void testCardDeckSymbole(String msg, Symbol _sym) { void testCardDeckSymbole(String msg, Symbol _sym) {
boolean result = false; boolean result = false;
for(int i = 0; i<deck.getDeck().size(); i++) {
if(deck.getDeck().get(i).getSymbol() == _sym) {
for(int allCardZähler = 0; allCardZähler<deck.getDeck().size(); allCardZähler++) {
if(deck.getDeck().get(allCardZähler).getSymbol() == _sym) {
result = true; result = true;
break; break;
} }
@ -51,6 +52,7 @@ class CardDeckTest {
} }
@Test @Test
//Jedes Symbol muss 13 mal vorrhanden sein
void testCardDeckNumber() { void testCardDeckNumber() {
boolean result = true; boolean result = true;
@ -66,8 +68,8 @@ class CardDeckTest {
private boolean CheckAllCards(Symbol _sym) { private boolean CheckAllCards(Symbol _sym) {
boolean result = true; boolean result = true;
for(int i =1; i<=13; i++) {
if(deck.getDeck().contains(new Card(i, _sym, false))== false) {
for(int nrZähler =1; nrZähler<=13; nrZähler++) {
if(deck.getDeck().contains(new Card(nrZähler, _sym, false))== false) {
result = false; result = false;
break; break;
} }

Loading…
Cancel
Save