Пример #1
0
        public void DeckOfCards_ShuffleCardsOptionsTrue_SuccessDeckOfCardsCreatedNotSortedByAscendingSuitAndRank()
        {
            // Arrange

            // Act
            var deck = new DeckOfCards(true);

            // Assert
            Assert.IsNotNull(deck);
            Assert.IsTrue(VerifyCardsAreOutOfOrder(deck));
        }
Пример #2
0
        public void DeckOfCards_NoConstructorOptions_SuccessDeckOfCardsCreatedWithValidCards()
        {
            // Arrange

            // Act
            var deck = new DeckOfCards();

            // Assert
            Assert.IsNotNull(deck);
            Assert.IsTrue(deck.IsValid(deck));
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
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);
        }
Пример #7
0
        private static bool VerifyCardsAreOutOfOrder(DeckOfCards deck)
        {
            var sortedDeck = new DeckOfCards().Cards;

            return deck.Cards
                .Where((t, i) =>
                    !(sortedDeck[i].Rank == t.Rank ||
                      sortedDeck[i].Suit == t.Suit))
                .Any();
        }
Пример #8
0
        public void IsValid_DeckOfCardsHasMoreThanOneCardOfSameRankAndSuit_FailureReturnsFalse()
        {
            // Arrange
            var deck = new DeckOfCards();
            var tempCards = new List<Card>
            {
                new Card(CardRank.Ace, CardSuit.Spades),
                new Card(CardRank.Ace, CardSuit.Spades)
            };

            // Act
            deck.Cards = tempCards;

            // Assert
            Assert.IsFalse(deck.IsValid(deck));
        }
Пример #9
0
        public void IsValid_DeckOfCardsHasGreaterThan52Cards_FailureReturnsFalse()
        {
            // Arrange
            var deck = new DeckOfCards();
            var tempCards = deck.Cards;

            // Act
            tempCards.Add(new Card(CardRank.Ace, CardSuit.Spades));
            deck.Cards = tempCards;

            // Assert
            Assert.AreEqual(53, deck.Cards.Count);
            Assert.IsFalse(deck.IsValid(deck));
        }
Пример #10
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);
        }