예제 #1
0
        public void AddCard_ValidCardProvided_SuccessCardAddedCardToHand()
        {
            // Arrange
            var deck = new DeckOfCards(true);
            var cardHand = new CardHand();

            // Act
            cardHand.AddCard(deck.GetCard(new GetRandomCardStrategy()));

            // Assert
            Assert.AreEqual(1, cardHand.Count);
        }
예제 #2
0
        public void GetCard_GetRandomCardStrategy_SuccessRandomCardReturnedAndMarkedAsPlayed()
        {
            // Arrange
            var deck = new DeckOfCards(true);

            // Act
            var newCard = deck.GetCard(new GetRandomCardStrategy());

            // Assert
            Assert.IsNotNull(newCard);
            Assert.IsTrue(newCard.HasBeenPlayed);
            Assert.AreEqual(51, deck.Cards.Count);
        }
예제 #3
0
        public void HandRank_Valid4CardHandProvided_SuccessSumOfCardRanksReturned()
        {
            // Arrange
            var deck = new DeckOfCards();
            var hand = new CardHand();

            for (var cardIndex = 0; cardIndex < 4; cardIndex++)
            {
                // Note: In an unshuffled deck, the 1st four cards are all deuces
                hand.AddCard(deck.GetCard(new GetNextCardStrategy()));
            }

            // Act
            var rank = hand.HandRank;

            // Assert
            Assert.AreEqual(4, hand.Count);
            Assert.AreEqual(8, rank);
        }
예제 #4
0
        public void GetCard_ZeroCardsRemainingInDeck_FailureReturnsNull()
        {
            // Arrange
            var deck = new DeckOfCards(true);
            Card newCard;

            // Act
            for (int i = 0; i < 52; i++)
            {
                newCard = deck.GetCard(new GetNextCardStrategy());
            }
            newCard = deck.GetCard(new GetNextCardStrategy());

            // Assert
            Assert.AreEqual(0, deck.Cards.Count);
            Assert.IsNull(newCard);
        }
예제 #5
0
        public void RemoveCard_ValidCardProvided_SuccessCardRemovedCardFromHand()
        {
            // Arrange
            const int numCards = 4;
            Card addedCard = null;
            var deck = new DeckOfCards(true);
            var cardHand = new CardHand();

            for (var i = 0; i < numCards; i++)
            {
               addedCard = cardHand.AddCard(deck.GetCard(new GetNextCardStrategy()));
            }

            // Act
            var removedCard = cardHand.RemoveCard(addedCard);

            // Assert
            Assert.IsNotNull(removedCard);
            Assert.AreEqual(numCards - 1, cardHand.Count);
        }