Exemplo n.º 1
0
        public void sortTest2()
        {
            // Allocate a deck of cards
            cardDeck d = new cardDeck();
            card c = new card();
            // Shuffle the cards manually
            for (int i = 0; i < 51; i++)
            {
                int idx = (r.Next()) % 52;
                if (i == idx) idx = (r.Next()) % 52;
                c = d.deck[idx];
                d.deck[idx] = d.deck[i];
                d.deck[i] = c;
            }

            // sort
            d.sort();

            // Validate the cards manually
            int errorCnt = 0;
            for (int j = 0; j < 51; j++)
            {
                if (j != d.deck[j].sortOrder()) errorCnt++;
            }
            Assert.IsTrue(errorCnt == 0);
        }
Exemplo n.º 2
0
        public void shuffleTest1()
        {
            // Allocate a deck of cards
            cardDeck deck = new cardDeck();

            // Shuffle
            deck.shuffle();

            // Use the validate method to see if all of the cards are in place
            Assert.IsTrue(deck.validateDeck());
        }
Exemplo n.º 3
0
        public void shuffleTest3()
        {
            // Allocate 5 deck of cards

            // Delay 1 1/2 seconds between deck allocations to
            // ensure that each card has a differently seeded random
            // number generator
            //
            cardDeck d1 = new cardDeck();
            Thread.Sleep(1500);
            cardDeck d2 = new cardDeck();
            Thread.Sleep(1500);
            cardDeck d3 = new cardDeck();
            Thread.Sleep(1500);
            cardDeck d4 = new cardDeck();
            Thread.Sleep(1500);
            cardDeck d5 = new cardDeck();

            // sort
            d1.sort();
            d2.sort();
            d3.sort();
            d4.sort();
            d5.sort();

            // Shuffle
            d1.shuffle();
            d2.shuffle();
            d3.shuffle();
            d4.shuffle();
            d5.shuffle();

            // Test to see if all card decks have been shuffled
            int[] errorCnt = { 0, 0, 0, 0, 0 };
            for (int j = 0; j < 52; j++)
            {
                // Test to see if each card is in its original order in the deck
                if (j == d1.deck[j].sortOrder()) errorCnt[0]++;
                if (j == d2.deck[j].sortOrder()) errorCnt[1]++;
                if (j == d3.deck[j].sortOrder()) errorCnt[2]++;
                if (j == d4.deck[j].sortOrder()) errorCnt[3]++;
                if (j == d5.deck[j].sortOrder()) errorCnt[4]++;
            }

            // It might be possible for one or two cards to be in its original order
            // Three such insidents will be flagged as a failure
            Assert.IsTrue(errorCnt[0] < 3
                       && errorCnt[1] < 3
                       && errorCnt[2] < 3
                       && errorCnt[3] < 3
                       && errorCnt[4] < 3);
        }
Exemplo n.º 4
0
        public void sortTest1()
        {
            // Allocate a deck of cards
            cardDeck d = new cardDeck();

            // The deck of cards is sorted by default.
            // Shuffle the cards manually
            card c = new card();
            for (int i = 0; i < 51; i++)
            {
                int idx = (r.Next()) % 52;
                c = d.deck[idx];
                d.deck[idx] = d.deck[i];
                d.deck[i] = c;
            }

            // Sort the cards
            d.sort();

            // Use the validate method to see if all of the cards are in place
            Assert.IsTrue(d.validateDeck());
        }
Exemplo n.º 5
0
        public void shuffleTest2()
        {
            // Allocate a deck of cards
            cardDeck d = new cardDeck();

            // Cards are in a sorted state after deck allocation

            // Shuffle
            d.shuffle();

            // Validate the shuffling of the deck manually
            int errorCnt = 0;
            for (int j = 51; j >= 0; j--)
            {
                // Test to see if each card is in its original order in the deck
                if (j == d.deck[j].sortOrder()) errorCnt++;
            }

            // It might be possible for one or two cards to be in its original order
            // Three such insidents will be flagged as a failure
            Assert.IsTrue(errorCnt < 3);
        }
Exemplo n.º 6
0
        public void sortTest3()
        {
            int idx;

            // Allocate 5 deck of cards
            cardDeck d1 = new cardDeck();
            cardDeck d2 = new cardDeck();
            cardDeck d3 = new cardDeck();
            cardDeck d4 = new cardDeck();
            cardDeck d5 = new cardDeck();
            card c = new card();

            // Shuffle the cards manually
            for (int i = 0; i < 51; i++)
            {
                // Each deck gets shuffled with different values
                idx = (r.Next()) % 52;
                if (i == idx) idx = (r.Next()) % 52;
                c = d1.deck[idx];
                d1.deck[idx] = d1.deck[i];
                d1.deck[i] = c;

                // Each deck gets shuffled with different values
                idx = (r.Next()) % 52;
                if (i == idx) idx = (r.Next()) % 52;
                c = d2.deck[idx];
                d2.deck[idx] = d2.deck[i];
                d2.deck[i] = c;

                // Each deck gets shuffled with different values
                idx = (r.Next()) % 52;
                if (i == idx) idx = (r.Next()) % 52;
                c = d3.deck[idx];
                d3.deck[idx] = d3.deck[i];
                d3.deck[i] = c;

                // Each deck gets shuffled with different values
                idx = (r.Next()) % 52;
                if (i == idx) idx = (r.Next()) % 52;
                c = d4.deck[idx];
                d4.deck[idx] = d4.deck[i];
                d4.deck[i] = c;

                // Each deck gets shuffled with different values
                idx = (r.Next()) % 52;
                if (i == idx) idx = (r.Next()) % 52;
                c = d5.deck[idx];
                d5.deck[idx] = d5.deck[i];
                d5.deck[i] = c;
            }

            // sort
            d1.sort();
            d2.sort();
            d3.sort();
            d4.sort();
            d5.sort();

            // Validate the cards manually
            int [] errorCnt = { 0, 0, 0, 0, 0 };
            for (int j = 0; j < 51; j++)
            {
                if (j != d1.deck[j].sortOrder()) errorCnt[0]++;
                if (j != d2.deck[j].sortOrder()) errorCnt[1]++;
                if (j != d3.deck[j].sortOrder()) errorCnt[2]++;
                if (j != d4.deck[j].sortOrder()) errorCnt[3]++;
                if (j != d5.deck[j].sortOrder()) errorCnt[4]++;
            }
            Assert.IsTrue(errorCnt[0] == 0
                       && errorCnt[1] == 0
                       && errorCnt[2] == 0
                       && errorCnt[3] == 0
                       && errorCnt[4] == 0);
        }