Beispiel #1
0
        public void Test_Game_Shuffle(bool createDeck)
        {
            const int numberOfShuffles = 1;

            IBattleOutput battleOutput = new Fake_BattleOutput();
            Game          game         = new Game(battleOutput);
            CardPile      deck         = new CardPile();

            if (createDeck)
            {
                game.CreateDeck(deck);
            }

            List <Card> preShuffleCards = deck.GetAll();

            deck.Shuffle(numberOfShuffles);
            List <Card> postShuffleCards = deck.GetAll();

            Assert.True(preShuffleCards.Count == postShuffleCards.Count);

            if (!createDeck)
            {
                Assert.Equal <Card>(preShuffleCards, postShuffleCards);
            }
            else
            {
                Assert.NotEqual <Card>(preShuffleCards, postShuffleCards);
                foreach (Card card in preShuffleCards)
                {
                    Assert.Contains(postShuffleCards, c => (string.Equals(c.Name, card.Name) && (c.Value == card.Value)));
                }
            }
        }
Beispiel #2
0
        //[InlineData(1000)]
        public void Test_Program_RunGameParallel(int numberOfRuns)
        {
            IBattleOutput battleOutput = new Fake_BattleOutput();

            Parallel.For(0, numberOfRuns, i =>
            {
                GameResults gameResults = Program.RunGame(battleOutput);

                Assert.True(gameResults.WinningPlayer.NumberOfCards == 52);
                Assert.True(gameResults.LosingPlayer.NumberOfCards == 0);
                Assert.True(gameResults.NumberOfRounds >= 1);
            });
        }
Beispiel #3
0
        public void Test_Program_RunGame(int numberOfRuns)
        {
            IBattleOutput battleOutput = new Fake_BattleOutput();

            for (int i = 0; i < numberOfRuns; i++)
            {
                GameResults gameResults = Program.RunGame(battleOutput);

                Assert.True(gameResults.WinningPlayer.NumberOfCards == 52);
                Assert.True(gameResults.LosingPlayer.NumberOfCards == 0);
                Assert.True(gameResults.NumberOfRounds >= 1);           //  Pathological case:  game ends in 1 round (many tie battles with eventual winner)
            }
        }
Beispiel #4
0
        public void Test_Game_DealCards(int numberOfCards)
        {
            List <Card>   cards        = Enumerable.Repeat(new Card(CardSuit.SPADE, CardRank.RANK_KING), numberOfCards).ToList();
            CardPile      deck         = new CardPile(cards);
            IBattleOutput battleOutput = new Fake_BattleOutput();
            Game          game         = new Game(battleOutput);
            Player        player1      = new Player();
            Player        player2      = new Player();

            game.DealCards(deck, player1, player2);

            int dealtCardsToPlayer = (int)Math.Floor(numberOfCards / 2m);

            Assert.True(dealtCardsToPlayer <= player1.NumberOfCards);       //  For odd numberOfCards, player 1 gets an extra card
            Assert.True(dealtCardsToPlayer == player2.NumberOfCards);
        }
Beispiel #5
0
        public void Test_Game_CreateDeck()
        {
            IBattleOutput battleOutput = new Fake_BattleOutput();
            Game          game         = new Game(battleOutput);
            CardPile      deck         = new CardPile();

            game.CreateDeck(deck);

            List <Card> cards = CreateCardDeck();

            List <Card> deckCards = deck.GetAll();

            foreach (Card card in cards)
            {
                Assert.Contains(deckCards, c => (string.Equals(c.Name, card.Name) && (c.Value == card.Value)));
            }

            Assert.True(cards.Count == deckCards.Count);
        }