Files
basic-computer-games/10_Blackjack/java/test/DeckTest.java
Dave Burke 0b1f57ae4f Refactor to allow testing side effects
By externalizing the source of i/o and randomness for shuffling, we can
inject non-interactive and deterministic behavior during unit tests.
2022-02-07 21:59:02 -06:00

33 lines
966 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.getSuit())
.distinct()
.count();
long nValues = deck.getCards().stream()
.map(card -> card.getValue())
.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)
);
}
}