Question: I need to make a junit test called DeckTest. Below is the code for the Deck and Card classes. The test needs to test that
I need to make a junit test called DeckTest. Below is the code for the Deck and Card classes. The test needs to test that there are 52 cards, check for 4 of each kind and 13 of each suit. It should also test that the shuffle works and test that the make deck and get deck works. Thank You.
THE DECK CLASS
package code;
import java.util.ArrayList;
import java.util.Collections;
public class Deck {
private ArrayList
public Deck() {
makeDeck();
shuffleDeck();
this.deck = getDeck();
}
public ArrayList
return this.deck;
}
public void makeDeck() {
ArrayList
for(int i = 1; i< 14; i++) {
Card card1 = new Card("HEARTS", i);
Card card2 = new Card("SPADES", i);
Card card3 = new Card("CLUBS", i);
Card card4 = new Card("DIAMONDS", i);
deck.add(card1);
deck.add(card2);
deck.add(card3);
deck.add(card4);
}
this.deck = deck;
}
public void shuffleDeck() {
Collections.shuffle(this.deck);
}
public static void main(String[] args) {
Deck deck = new Deck();
System.out.println(deck.getDeck());
}
}
THE CARD CLASS
package code;
public class Card {
private String suit;
private int rank;
public Card(String suit, int rank) {
this.rank = rank;
this.suit = suit;
}
public String getSuit() {
return suit;
}
public void setSuit(String suit) {
this.suit = suit;
}
public int getRank() {
return rank;
}
public void setRank(int rank) {
this.rank = rank;
}
@Override
public String toString() {
return "Card [suit=" + suit + ", rank=" + rank + "]";
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
