private bool DrawCards(Deck deck, int numDraw, List <Card> discard) { bool ret; WriteResult("Testing draw " + numDraw + " card...."); int finalSize = deck.RemainingCards != 0 ? deck.RemainingCards - numDraw : 0; finalSize = finalSize < 0 ? 0 : finalSize; bool deckEmpty = deck.RemainingCards == 0?true:false; for (int i = 0; i < numDraw; i++) { Card c = deck.DealOneCard(); if (deckEmpty) { if (c != null) { WriteResult("Failed - card returned on empty"); return(false); } if (deck.RemainingCards != 0) { WriteResult("Failed - remaining cards added after empty deal"); return(false); } continue; } deckEmpty = deck.RemainingCards == 0 ? true : false; discard.Add(c); } ret = deck.RemainingCards == finalSize; WriteResult("Deck Size = " + deck.RemainingCards); if (!ret) { WriteResult("Failed - Deck Size"); return(ret); } if (ContainsDiscarded(deck, discard)) { WriteResult("Failed - Deck contains discarded cards"); return(false); } WriteResult("Passed"); return(true); }
private bool Test4_ShuffleTest() { Console.WriteLine("Shuffle test....."); Deck deck = new Deck(); Deck deck2 = new Deck(); deck.Shuffle(); deck2.Shuffle(); //make sure do not match if (deck.Equals(deck2)) { WriteResult("Fail - Shuffled decks match"); return(false); } List <Card> cards = deck.GetCards(); deck.Shuffle(); if (CardsMatch(cards, deck.GetCards())) { WriteResult("Fail - Deck matches after shuffle"); return(false); } List <Card> discard = new List <Card>(); discard.Add(deck.DealOneCard()); deck.Shuffle(); if (ContainsDiscarded(deck, discard)) { WriteResult("Fail - shuffled deck contains discarded cards"); return(false); } for (int i = 0; i < 14; i++) { discard.Add(deck.DealOneCard()); } deck.Shuffle(); if (ContainsDiscarded(deck, discard)) { WriteResult("Fail - deck contains discarded cards after many discard"); return(false); } deck.Shuffle(); deck.Shuffle(); deck.Shuffle(); if (ContainsDiscarded(deck, discard)) { WriteResult("Fail - deck contains discarded cards after many shuffle"); return(false); } for (int i = 0; i < deck.RemainingCards; i++) { discard.Add(deck.DealOneCard()); } try { deck.Shuffle(); } catch { WriteResult("Fail - threw exception on shuffle empty deck"); return(false); } WriteResult("Passed"); return(true); }