Browse Source

CardDeck with different Symbole

feature_solitaer_001
Alexander Hartung 3 years ago
parent
commit
84fab3b084
  1. 23
      src/main/java/solitaer/Card.java
  2. 29
      src/main/java/solitaer/CardDeck.java
  3. 39
      src/test/java/solitaer/CardDeckTest.java

23
src/main/java/solitaer/Card.java

@ -23,6 +23,27 @@ public class Card extends JPanel {
this.faceUp = faceUp; this.faceUp = faceUp;
} }
public boolean isFaceUp() {
return faceUp;
}
public void setFaceUp(boolean faceUp) {
this.faceUp = faceUp;
}
public int getNr() {
return nr;
}
public Symbol getSymbol() {
return symbol;
}
@Override
public String toString() {
return "Card [nr=" + nr + ", symbol=" + symbol + ", faceUp=" + faceUp + "]";
}
} }

29
src/main/java/solitaer/CardDeck.java

@ -3,21 +3,34 @@ package solitaer;
import java.util.ArrayList; import java.util.ArrayList;
public class CardDeck { public class CardDeck {
private ArrayList<Card> deck = new ArrayList<Card>(); private ArrayList<Card> deck = new ArrayList<Card>();
public CardDeck() { public CardDeck() {
for(int i= 0; i<52; i++) {
deck.add(new Card(i, Symbol.Herz, false));
for (int j = 0; j < 4; j++) {
for (int i = 0; i < 13; i++) {
switch (j) {
case 0:
deck.add(new Card(1, Symbol.Herz, false));
break;
case 1:
deck.add(new Card(1, Symbol.Karo, false));
break;
case 2:
deck.add(new Card(1, Symbol.Kreuz, false));
break;
case 3:
deck.add(new Card(1, Symbol.Pik, false));
break;
}
}
} }
}
}
public ArrayList<Card> getDeck() { public ArrayList<Card> getDeck() {
return deck; return deck;
} }
} }

39
src/test/java/solitaer/CardDeckTest.java

@ -1,21 +1,54 @@
package solitaer; package solitaer;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.verify;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class CardDeckTest { class CardDeckTest {
private CardDeck deck = new CardDeck();
@Test @Test
void testCardDeckSize() {
CardDeck deck = new CardDeck();
void testCardDeckSize() {
int result = deck.getDeck().size(); int result = deck.getDeck().size();
assertEquals(52, result, "Kartendeck muss genau 52 Carden haben") ; assertEquals(52, result, "Kartendeck muss genau 52 Carden haben") ;
} }
@ParameterizedTest
@MethodSource("testSymbole")
void testCardDeckSymbole(String msg, Symbol _sym) {
boolean result = false;
for(int i = 0; i<deck.getDeck().size(); i++) {
if(deck.getDeck().get(i).getSymbol() == _sym) {
result = true;
break;
}
}
assertTrue(result, msg);
}
private static Stream<Arguments> testSymbole(){
return Stream.of(
Arguments.of("Herz", Symbol.Herz),
Arguments.of("Karo", Symbol.Karo),
Arguments.of("Pik", Symbol.Pik),
Arguments.of("Kreuz",Symbol.Kreuz)
);
}
} }
Loading…
Cancel
Save