Files
basic-computer-games/10_Blackjack/java/test/DeckTest.java
Dave Burke 15c26cbe09 Limit number of decks to 1
The subroutine to get a card shuffles 52 cards when the deck is run
through:

100 REM--SUBROUTINE TO GET A CARD.  RESULT IS PUT IN X.
110 IF C<51 THEN 230
120 PRINT "RESHUFFLING"
130 FOR D=D TO 1 STEP -1
140 C=C-1
150 C(C)=D(D)
160 NEXT D
170 FOR C1=52 TO C STEP -1
180 C2=INT(RND(1)*(C1-C+1))+C
190 C3=C(C2)
200 C(C2)=C(C1)
210 C(C1)=C3
220 NEXT C1
230 X=C(C)
240 C=C+1
250 RETURN
2022-02-03 08:31:04 -06:00

32 lines
924 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();
// 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)
);
}
}