Example #1
0
        /// <summary>
        /// Entry point for demo console application.
        /// </summary>
        public static void Main()
        {
            Deck deck = new Deck();
            while (deck.NumberOfRemainingCards > 0)
            {
                Console.WriteLine(deck.deal_one_card().ToString());
            }

            Console.WriteLine("\r\nShuffling...\r\n");
            deck.shuffle();
            while (deck.NumberOfRemainingCards > 0)
            {
                Console.WriteLine(deck.deal_one_card().ToString());
            }

            Console.WriteLine("\r\nTesting second implementation\r\n");
            Deck_FisherYates deck2 = new Deck_FisherYates();
            while (deck2.NumberOfRemainingCards > 0)
            {
                Console.WriteLine(deck2.deal_one_card().ToString());
            }

            Console.WriteLine("\r\nShuffling...\r\n");
            deck2.shuffle();
            while (deck2.NumberOfRemainingCards > 0)
            {
                Console.WriteLine(deck2.deal_one_card().ToString());
            }

            Console.WriteLine("Demo completed.");
        }
Example #2
0
 public void TestDeal()
 {
     Deck deck = new Deck();
     Card card = deck.deal_one_card();
     Assert.IsNotNull(card);
     while (deck.NumberOfRemainingCards > 0)
     {
         deck.deal_one_card();
     }
     Assert.IsNull(deck.deal_one_card());
 }
Example #3
0
        public void TestShuffle()
        {
            Deck deck = new Deck();
            while (deck.NumberOfRemainingCards > 0)
            {
                deck.deal_one_card();
            }

            Assert.AreEqual(0, deck.NumberOfRemainingCards);
            Assert.IsNull(deck.deal_one_card());
            deck.shuffle();
            Assert.AreEqual(52, deck.NumberOfRemainingCards);
        }
Example #4
0
        public void TestConstructor()
        {
            Deck deck = new Deck();
            Assert.AreEqual(52, deck.NumberOfRemainingCards);

            // Ensure all suites/values are represented
            Array values = Enum.GetValues(typeof(FaceValue));
            Array suites = Enum.GetValues(typeof(Suite));

            int[] suiteCounts = new int[suites.Length];
            int[] valueCounts = new int[values.Length];
            while (deck.NumberOfRemainingCards > 0)
            {
                Card card = deck.deal_one_card();
                suiteCounts[(int)card.Suite - 1] += 1;
                valueCounts[(int)card.FaceValue - 1] += 1;
            }

            // There should be 13 cards of each of the 4 suites
            foreach (int index in suiteCounts)
            {
                Assert.AreEqual(13, index);
            }

            // There should be 4 suites for each of the face values
            foreach (int index in valueCounts)
            {
                Assert.AreEqual(4, index);
            }
        }