Exemplo n.º 1
0
        private bool ContainsDiscarded(Deck deck, List <Card> discard)
        {
            if (deck.RemainingCards == 0)
            {
                return(false);
            }
            List <Card> cards = deck.GetCards();

            foreach (Card c in discard)
            {
                if (cards.Contains(c))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        private bool ContainsFullDeck(Deck d)
        {
            bool        ret   = true;
            List <Card> cards = d.GetCards();

            foreach (Suit s in Enum.GetValues(typeof(Suit)))
            {
                for (int i = 2; i < 13; i++)
                {
                    Card card = new Card(s, i);
                    if (!cards.Contains(card))
                    {
                        WriteResult("Missing " + card);
                        ret = false;
                    }
                }
            }
            return(ret);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Compares 2 deck objects.
        /// </summary>
        /// <param name="obj">
        /// Deck object to be compared to this instance of a deck.
        /// </param>
        /// <returns>True if the cards in both decks are the same. False otherwise.</returns>
        public override bool Equals(object obj)
        {
            Deck deckComp = (Deck)obj;

            if (this.RemainingCards != deckComp.RemainingCards)
            {
                return(false);
            }
            List <Card> cardsComp = deckComp.GetCards();

            for (int i = 0; i < numCards; i++)
            {
                if (!this.cards[i].Equals(cardsComp[i]))
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 4
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);
        }