예제 #1
0
        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);
        }