Exemplo n.º 1
0
        public void TestHitAndClearHand()
        {
            var deck   = new DeckOfCards();
            var player = new Player("Player");

            player.DoHit(deck);
            Assert.IsFalse(player.HandBusted);
            Assert.IsFalse(player.HandHeld);
            var card = player.PlayerHand.LastCardDelt;

            Assert.AreEqual(Card.Suits.Heart, card.Suit);
            Assert.AreEqual(1, card.Value);
            player.DoHit(deck);
            card = player.PlayerHand.LastCardDelt;
            Assert.AreEqual(Card.Suits.Heart, card.Suit);
            Assert.AreEqual(2, card.Value);

            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();

            player.DoHit(deck);
            player.DoHit(deck);
            player.DoHit(deck);
            Assert.IsTrue(player.HandBusted);
            Assert.IsTrue(player.HandHeld);

            player.ClearHand();
            Assert.IsFalse(player.HandBusted);
            Assert.IsFalse(player.HandHeld);
            Assert.AreEqual(0, player.Bet);
            Assert.AreEqual(0, player.PlayerHand.Cards.Count);
        }
Exemplo n.º 2
0
        public void TestCreateDeck()
        {
            var deck = new DeckOfCards();

            for (var cnt = 0; cnt < DeckOfCards.HighCardValue; cnt++)
            {
                var card = deck.GetNextCard();
                Assert.AreEqual(Card.Suits.Heart, card.Suit);
                Assert.AreEqual(cnt + 1, card.Value);
            }

            for (var cnt = 0; cnt < DeckOfCards.HighCardValue; cnt++)
            {
                var card = deck.GetNextCard();
                Assert.AreEqual(Card.Suits.Club, card.Suit);
                Assert.AreEqual(cnt + 1, card.Value);
            }

            for (var cnt = 0; cnt < DeckOfCards.HighCardValue; cnt++)
            {
                var card = deck.GetNextCard();
                Assert.AreEqual(Card.Suits.Diamond, card.Suit);
                Assert.AreEqual(cnt + 1, card.Value);
            }

            for (var cnt = 0; cnt < DeckOfCards.HighCardValue; cnt++)
            {
                var card = deck.GetNextCard();
                Assert.AreEqual(Card.Suits.Spade, card.Suit);
                Assert.AreEqual(cnt + 1, card.Value);
            }
        }
Exemplo n.º 3
0
        public void TestShuffle()
        {
            var deck            = new DeckOfCards();
            var totalNotShuffle = 0;
            var cardsChecked    = 0;

            deck.ShuffleDeck();
            var card1 = deck.GetNextCard();

            while (cardsChecked < DeckOfCards.MaxDeck - 1)
            {
                cardsChecked++;
                var card2 = deck.GetNextCard();

                if ((card1.Suit == card2.Suit) &&
                    (card1.Value == card2.Value))
                {
                    totalNotShuffle++;
                }

                card1 = card2;
            }

            var percentageNotShuffled = (totalNotShuffle / 52.0M) * 100M;

            Assert.IsFalse(percentageNotShuffled > 10);
        }
Exemplo n.º 4
0
        public void TestInitPlayer()
        {
            var deck   = new DeckOfCards();
            var player = new Player("Testing");

            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            player.GetCard(deck);
            player.GetCard(deck);
            player.GetCard(deck);
            Assert.AreEqual(3, player.PlayerHand.Cards.Count);
            Assert.AreEqual(27, player.PlayerHand.TotalHand());
            Assert.IsTrue(player.HandBusted);
            Assert.IsTrue(player.HandHeld);

            player.ClearHand();
            Assert.AreEqual(0, player.PlayerHand.Cards.Count);
            Assert.AreEqual(0, player.PlayerHand.TotalHand());
            Assert.IsFalse(player.HandBusted);
            Assert.IsFalse(player.HandHeld);
        }
Exemplo n.º 5
0
        public void TestTotalError()
        {
            var deck   = new DeckOfCards();
            var player = new Player("Testing");

            player.GetCard(deck);
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            player.GetCard(deck);
            Assert.AreEqual(19, player.PlayerHand.TotalHand());

            deck   = new DeckOfCards();
            player = new Player("Testing");
            deck.GetNextCard();
            player.GetCard(deck);
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            player.GetCard(deck);
            Assert.AreEqual(10, player.PlayerHand.TotalHand());

            deck   = new DeckOfCards();
            player = new Player("Testing");
            deck.GetNextCard();
            player.GetCard(deck);
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            player.GetCard(deck);
            Assert.AreEqual(8, player.PlayerHand.TotalHand());
        }
Exemplo n.º 6
0
        public void TestBlackJack()
        {
            var deck   = new DeckOfCards();
            var player = new Player("Testing");

            player.GetCard(deck);
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            deck.GetNextCard();
            player.GetCard(deck);
            Assert.IsTrue(player.HasBackJack());
        }