예제 #1
0
        public void DeckMaintainsCorrectCountThroughNegativeTake()
        {
            // Arrange
            ICardOrderingProvider cardOrderingProvider = new SuitMajorSortedCardOrderingProvider();
            ICardDeck             cardDeck             = new SnapCardDeck(cardOrderingProvider);

            // Act
            // Weirdly the deck is modelled on a pile of cards (rather than an actual deck) and therefore
            // has no requirement that any given card be unique (which has odd implications
            // for the SortedCardOrderingProvider!). We will abuse this fact by filling the deck up
            // with multiple instances of the same card

            for (int i = 0; i < 5; i++)   // Add 5
            {
                cardDeck.Add(new SnapCard(Suit.Diamonds, Rank.Five));
            }
            for (int i = 0; i < 150; i++)   // Try to remove 150, actually remove 5.
            {
                cardDeck.Take();
            }
            for (int i = 0; i < 200; i++)   // Add 200
            {
                cardDeck.Add(new SnapCard(Suit.Diamonds, Rank.Five));
            }

            // Assert
            Assert.IsTrue(cardDeck.Count == (5 - 5 + 200));
        }
예제 #2
0
        public void DeckReturnsNullOnTakeWhenEmpty()
        {
            // Arrange
            ICardOrderingProvider cardOrderingProvider = new SuitMajorSortedCardOrderingProvider();
            ICardDeck             cardDeck             = new SnapCardDeck(cardOrderingProvider);

            // Act
            var test = cardDeck.Take();

            // Assert
            Assert.IsNull(test);
        }
예제 #3
0
        public void DeckCanTakeCard()
        {
            // Arrange
            ICardOrderingProvider cardOrderingProvider = new SuitMajorSortedCardOrderingProvider();
            ICardDeck             cardDeck             = new SnapCardDeck(cardOrderingProvider);
            ICard card = new SnapCard(Suit.Spades, Rank.Ace);

            // Act
            cardDeck.Add(card);
            var test = cardDeck.Take();

            // Assert
            Assert.IsTrue(cardDeck.IsEmpty);
        }
예제 #4
0
        public void DeckCanTakeCorrectCard()
        {
            // Arrange
            ICardOrderingProvider cardOrderingProvider = new SuitMajorSortedCardOrderingProvider();
            ICardDeck             cardDeck             = new SnapCardDeck(cardOrderingProvider);
            ICard card = new SnapCard(Suit.Spades, Rank.Ace);

            // Act
            cardDeck.Add(new SnapCard(Suit.Spades, Rank.Two));
            cardDeck.Add(card);
            cardDeck.Add(new SnapCard(Suit.Hearts, Rank.Queen));
            var test = cardDeck.Take();

            // Assert
            // As we're using the SortedCardOrderingProvider, the ace of spades should always be the
            // top card in the deck. Given that Take() removes cards from the top of the deck, no matter
            // what we do, if the Ace of Spades is in the deck, Take() should return it.
            Assert.IsTrue(test.Suit == card.Suit && test.Rank == card.Rank);
        }