Files
basic-computer-games/10_Blackjack/java/test/DeckTest.java
Dave Burke cdf194f770 Remove redundant Card record code
Java Records automatically acquire an implementation of equals and
hashCode that accounts for their components. They also have read
accessors for their components (card.suit() to get the suit).
2022-03-18 17:01:06 -05:00

33 lines
960 B
Java

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertAll;
import org.junit.jupiter.api.Test;
public class DeckTest {
@Test
void testInit() {
// When
Deck deck = new Deck((cards) -> cards);
deck.reshuffle();
// Then
long nCards = deck.size();
long nSuits = deck.getCards().stream()
.map(card -> card.suit())
.distinct()
.count();
long nValues = deck.getCards().stream()
.map(card -> card.value())
.distinct()
.count();
assertAll("deck",
() -> assertEquals(52, nCards, "Expected 52 cards in a deck, but got " + nCards),
() -> assertEquals(4, nSuits, "Expected 4 suits, but got " + nSuits),
() -> assertEquals(13, nValues, "Expected 13 values, but got " + nValues)
);
}
}