rendered paste body public void testDeal() { // Create a deck of cards CardDeck cardDeck = new CardDeck(); cardDeck.buildDeck(); // Deal three hands of various sizes Card[] hand1 = cardDeck.deal(5); Card[] hand2 = cardDeck.deal(10); Card[] hand3 = cardDeck.deal(20); // Make sure the dealt hands are of the correct size assertEquals(5, hand1.length); assertEquals(10, hand2.length); assertEquals(20, hand3.length); // Make sure the deck of cards were unchanged String[] suits = {"S", "H", "D", "C"}; for (int suitPos = 0 ; suitPos < suits.length; suitPos++){ String suit = suits[suitPos]; for (int facePos = 0; facePos < 13; facePos ++){ int pos = 13*suitPos+facePos; assertEquals(suit, cardDeck.cards[pos].suit); assertEquals((facePos + 1), cardDeck.cards[pos].face); } } // Make sure the correct cards were dealt int totalCardPos = 0; for (Card[] cards : new Card[][] { hand1, hand2, hand3 }) { for (Card cardInHand : cards) { Card cardInDeck = cardDeck.cards[totalCardPos]; assertEquals(cardInDeck.face, cardInHand.face); assertEquals(cardInDeck.suit, cardInHand.suit); totalCardPos++; } } // Make sure deal returns empty array when passed 0 Card[] hand4 = cardDeck.deal(0); assertEquals(0, hand4.length); // Make sure deal return empty array when passed too large value Card[] hand5 = cardDeck.deal(18); assertEquals(0, hand5.length); }