Esempio n. 1
0
        public void DealerCanDeal([Values(0, 1, 2)] int playerIndex)
        {
            // Arrange
            string[] hands = new string[]
            {
                "♣2♦3♥4♠5♣7", "♣5♦7♥10♠Q♣A", "♥6♠9♣10♦J♣K"
            };

            MockDeck mockDeck = new MockDeck(3, hands);

            Dealer dealer = new Dealer(mockDeck);

            Player[] players = new Player[]
            {
                new Player("Jonas", 0, new ConsolePlayer()),
                new Player("Karl", 0, new ConsolePlayer()),
                new Player("Anna", 0, new ConsolePlayer())
            };

            // Act
            dealer.Deal(players);

            // Assert
            Assert.AreEqual(players[playerIndex].Hand.Count(), 5);

            Assert.IsTrue(mockDeck.DealerShuffledTheDeckBeforeDrawingCards);

            CollectionAssert.AreEqual(
                HandTest.StringToCards(hands[playerIndex]), players[playerIndex].Hand);
        }
Esempio n. 2
0
 public MockDeck(int numberOfPlayers,
                 params string[] hands)
 {
     Card[][] handCards = hands.Select(h => HandTest.StringToCards(h)).ToArray();
     for (int i = 0; i < 5; ++i)
     {
         for (int j = 0; j < numberOfPlayers; ++j)
         {
             cards.Add(handCards[j][i]);
         }
     }
 }
Esempio n. 3
0
        public void PlayerCanGiveBackHand()
        {
            // Arrange
            Player player = new Player("Jonas", 0, new ConsolePlayer());

            Card[] initialCards = HandTest.StringToCards("♣2♦3♥4♠5♣7");
            foreach (Card card in initialCards)
            {
                player.RecieveCard(card);
            }

            // Act

            Card[] cardsGivenBack = player.GiveBackHand().ToArray();

            // Assert

            Assert.AreEqual(0, player.Hand.Count());

            CollectionAssert.AreEqual(initialCards, cardsGivenBack);
        }
Esempio n. 4
0
        public void PlayerCanThrowCards(
            [Values(true, false)] bool exchangeFirstCard,
            [Values(true, false)] bool exchangeSecondCard,
            [Values(true, false)] bool exchangeThirdCard,
            [Values(true, false)] bool exchangeFourthCard,
            [Values(true, false)] bool exchangeFifthCard
            )
        {
            // Arrange
            bool[] exchangeCard = new bool[] {
                exchangeFirstCard,
                exchangeSecondCard,
                exchangeThirdCard,
                exchangeFourthCard,
                exchangeFifthCard
            };

            List <int> indicesOfCardsForExchange =
                Enumerable.Range(0, 5).Zip(exchangeCard).Where(pair =>
                                                               pair.Second).Select(pair => pair.First).ToList();

            MockPlayerLogic playerLogic = new MockPlayerLogic(indicesOfCardsForExchange);
            Player          player      = new Player("Jonas", 0, playerLogic);

            Card[] initialCards = HandTest.StringToCards("♣2♦3♥4♠5♣7");
            foreach (Card card in initialCards)
            {
                player.RecieveCard(card);
            }
            List <Card> graveyard = new List <Card>();

            // Act
            player.ThrowCards(graveyard);

            // Assert
            int noOfExchangedCards = indicesOfCardsForExchange.Count;

            Assert.AreEqual(5 - noOfExchangedCards, player.Hand.Count());

            Card[] replacementCards =
                HandTest.StringToCards("♣5♦7♥10♠Q♣A")
                .Take(noOfExchangedCards)
                .ToArray();

            foreach (Card card in replacementCards)
            {
                player.RecieveCard(card);
            }

            Card[] playerShouldNowHowTheseCards =
                initialCards
                .Zip(exchangeCard)
                .Where(pair => !pair.Second)
                .Select(pair => pair.First)
                .Concat(replacementCards)
                .OrderBy(c => c.Rank)
                .ThenBy(c => c.Suite)
                .ToArray();

            CollectionAssert.AreEqual(playerShouldNowHowTheseCards, player.Hand);
        }