예제 #1
0
        public void PlayShouldReturnValidRoundResultObject()
        {
            var firstPlayer  = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();
            var round        = new Round(firstPlayer, secondPlayer, GameRulesProvider.Santase);

            var result = round.Play(0, 0);

            Assert.IsTrue(
                result.FirstPlayer.HasAtLeastOneTrick || result.SecondPlayer.HasAtLeastOneTrick,
                "result.FirstPlayer.HasAtLeastOneTrick || result.SecondPlayer.HasAtLeastOneTrick");

            Assert.IsTrue(
                result.FirstPlayer.RoundPoints > 0 || result.SecondPlayer.RoundPoints > 0,
                "result.FirstPlayer.RoundPoints > 0 || result.SecondPlayer.RoundPoints > 0");

            Assert.IsTrue(
                result.FirstPlayer.TrickCards.Count > 0 || result.SecondPlayer.TrickCards.Count > 0,
                "result.FirstPlayer.TrickCards.Count > 0 || result.SecondPlayer.TrickCards.Count > 0");

            Assert.IsTrue(
                result.FirstPlayer.RoundPoints >= 66 || result.SecondPlayer.RoundPoints >= 66 ||
                result.FirstPlayer.RoundPoints + result.SecondPlayer.RoundPoints >= 120,
                "result.FirstPlayer.RoundPoints >= 66 || result.SecondPlayer.RoundPoints >= 66 || result.FirstPlayer.RoundPoints + result.SecondPlayer.RoundPoints >= 120");
        }
예제 #2
0
        public void WinnersShouldBeEquallyDistributed()
        {
            const int GamesToPlay = 200;

            var firstPlayer  = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();

            var firstPlayerWinner  = 0;
            var secondPlayerWinner = 0;

            for (var i = 0; i < GamesToPlay; i++)
            {
                var firstToPlay = i % 2 == 0 ? PlayerPosition.FirstPlayer : PlayerPosition.SecondPlayer;
                var game        = new SantaseGame(firstPlayer, secondPlayer);
                var winner      = game.Start(firstToPlay);
                if (winner == PlayerPosition.FirstPlayer)
                {
                    firstPlayerWinner++;
                }
                else if (winner == PlayerPosition.SecondPlayer)
                {
                    secondPlayerWinner++;
                }
            }

            Assert.AreEqual(GamesToPlay, firstPlayerWinner + secondPlayerWinner);
            Assert.IsTrue(Math.Abs(firstPlayerWinner - secondPlayerWinner) < 150);
        }
예제 #3
0
        public void PlayersMethodsShouldBeCalledCorrectNumberOfTimes()
        {
            const int NumberOfRounds = 10000;

            var firstPlayer  = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();

            for (var i = 0; i < NumberOfRounds; i++)
            {
                var round = i % 2 == 0
                                ? new Round(firstPlayer, secondPlayer, GameRulesProvider.Santase)
                                : new Round(secondPlayer, firstPlayer, GameRulesProvider.Santase);

                round.Play(0, 0);
            }

            Assert.AreEqual(firstPlayer.StartRoundCalledCount, NumberOfRounds);
            Assert.AreEqual(secondPlayer.StartRoundCalledCount, NumberOfRounds);

            Assert.AreEqual(firstPlayer.EndRoundCalledCount, NumberOfRounds);
            Assert.AreEqual(secondPlayer.EndRoundCalledCount, NumberOfRounds);

            Assert.Greater(firstPlayer.GetTurnWhenFirst, NumberOfRounds);
            Assert.Greater(firstPlayer.GetTurnWhenSecond, NumberOfRounds);
            Assert.Greater(secondPlayer.GetTurnWhenFirst, NumberOfRounds);
            Assert.Greater(secondPlayer.GetTurnWhenSecond, NumberOfRounds);

            Assert.GreaterOrEqual(firstPlayer.GetTurnWhenFirst, secondPlayer.GetTurnWhenSecond);
            Assert.GreaterOrEqual(secondPlayer.GetTurnWhenFirst, firstPlayer.GetTurnWhenSecond);
        }
        public void PlayShouldReturnValidRoundResultObject()
        {
            var firstPlayer = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();
            var round = new Round(firstPlayer, secondPlayer, GameRulesProvider.Santase);

            var result = round.Play(0, 0);

            Assert.IsTrue(
                result.FirstPlayer.HasAtLeastOneTrick || result.SecondPlayer.HasAtLeastOneTrick,
                "result.FirstPlayer.HasAtLeastOneTrick || result.SecondPlayer.HasAtLeastOneTrick");

            Assert.IsTrue(
                result.FirstPlayer.RoundPoints > 0 || result.SecondPlayer.RoundPoints > 0,
                "result.FirstPlayer.RoundPoints > 0 || result.SecondPlayer.RoundPoints > 0");

            Assert.IsTrue(
                result.FirstPlayer.TrickCards.Count > 0 || result.SecondPlayer.TrickCards.Count > 0,
                "result.FirstPlayer.TrickCards.Count > 0 || result.SecondPlayer.TrickCards.Count > 0");

            Assert.IsTrue(
                result.FirstPlayer.RoundPoints >= 66 || result.SecondPlayer.RoundPoints >= 66
                || result.FirstPlayer.RoundPoints + result.SecondPlayer.RoundPoints >= 120,
                "result.FirstPlayer.RoundPoints >= 66 || result.SecondPlayer.RoundPoints >= 66 || result.FirstPlayer.RoundPoints + result.SecondPlayer.RoundPoints >= 120");
        }
        public void PlayersMethodsShouldBeCalledCorrectNumberOfTimes()
        {
            const int NumberOfRounds = 10000;

            var firstPlayer = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();

            for (var i = 0; i < NumberOfRounds; i++)
            {
                var round = i % 2 == 0
                                ? new Round(firstPlayer, secondPlayer, GameRulesProvider.Santase)
                                : new Round(secondPlayer, firstPlayer, GameRulesProvider.Santase);

                round.Play(0, 0);
            }

            Assert.AreEqual(firstPlayer.StartRoundCalledCount, NumberOfRounds);
            Assert.AreEqual(secondPlayer.StartRoundCalledCount, NumberOfRounds);

            Assert.AreEqual(firstPlayer.EndRoundCalledCount, NumberOfRounds);
            Assert.AreEqual(secondPlayer.EndRoundCalledCount, NumberOfRounds);

            Assert.Greater(firstPlayer.GetTurnWhenFirst, NumberOfRounds);
            Assert.Greater(firstPlayer.GetTurnWhenSecond, NumberOfRounds);
            Assert.Greater(secondPlayer.GetTurnWhenFirst, NumberOfRounds);
            Assert.Greater(secondPlayer.GetTurnWhenSecond, NumberOfRounds);

            Assert.GreaterOrEqual(firstPlayer.GetTurnWhenFirst, secondPlayer.GetTurnWhenSecond);
            Assert.GreaterOrEqual(secondPlayer.GetTurnWhenFirst, firstPlayer.GetTurnWhenSecond);
        }
예제 #6
0
 public void StartGameShouldReturnOneOfThePlayersAsWinner()
 {
     var firstPlayer = new ValidPlayerWithMethodsCallCounting();
     var secondPlayer = new ValidPlayerWithMethodsCallCounting();
     var game = new SantaseGame(firstPlayer, secondPlayer);
     var winner = game.Start();
     Assert.IsTrue(winner != PlayerPosition.NoOne);
 }
예제 #7
0
        public void StartGameShouldReturnOneOfThePlayersAsWinner()
        {
            var firstPlayer  = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();
            var game         = new SantaseGame(firstPlayer, secondPlayer);
            var winner       = game.Start();

            Assert.IsTrue(winner != PlayerPosition.NoOne);
        }
        public void PlayersStartRoundShouldBeCalledWithCorrectScoreValues()
        {
            var firstPlayer = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();
            var round = new Round(firstPlayer, secondPlayer, GameRulesProvider.Santase);

            round.Play(9, 4);

            Assert.AreEqual(firstPlayer.MyTotalPoints, 9);
            Assert.AreEqual(firstPlayer.OpponentTotalPoints, 4);
            Assert.AreEqual(secondPlayer.MyTotalPoints, 4);
            Assert.AreEqual(secondPlayer.OpponentTotalPoints, 9);
        }
예제 #9
0
        public void PlayersStartRoundShouldBeCalledWithCorrectScoreValues()
        {
            var firstPlayer  = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();
            var round        = new Round(firstPlayer, secondPlayer, GameRulesProvider.Santase);

            round.Play(9, 4);

            Assert.AreEqual(firstPlayer.MyTotalPoints, 9);
            Assert.AreEqual(firstPlayer.OpponentTotalPoints, 4);
            Assert.AreEqual(secondPlayer.MyTotalPoints, 4);
            Assert.AreEqual(secondPlayer.OpponentTotalPoints, 9);
        }
예제 #10
0
        public void PlayersMethodsShouldBeCalledCorrectNumberOfTimes()
        {
            const int GamesToPlay = 200;

            var firstPlayer = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();

            for (var i = 0; i < GamesToPlay; i++)
            {
                var firstToPlay = i % 2 == 0 ? PlayerPosition.FirstPlayer : PlayerPosition.SecondPlayer;
                var game = new SantaseGame(firstPlayer, secondPlayer);
                game.Start(firstToPlay);
            }

            // StartGame()
            Assert.AreEqual(GamesToPlay, firstPlayer.StartGameCalledCount);
            Assert.AreEqual(GamesToPlay, secondPlayer.StartGameCalledCount);

            // EndGame()
            Assert.AreEqual(GamesToPlay, firstPlayer.EndGameCalledCount);
            Assert.AreEqual(GamesToPlay, secondPlayer.EndGameCalledCount);

            // StartRound()
            Assert.GreaterOrEqual(
                firstPlayer.StartRoundCalledCount,
                4 * GamesToPlay,
                "Not started at least 4 rounds per game for the first player");
            Assert.GreaterOrEqual(
                secondPlayer.StartRoundCalledCount,
                4 * GamesToPlay,
                "Not started at least 4 rounds per game for the second player");

            // EndRound()
            Assert.GreaterOrEqual(
                firstPlayer.EndRoundCalledCount,
                GamesToPlay * 4,
                "Not ended at least 4 rounds per game for the first player");
            Assert.GreaterOrEqual(
                secondPlayer.EndRoundCalledCount,
                GamesToPlay * 4,
                "Not ended at least 4 rounds per game for the second player");

            // GetTurn() and EndTurn()
            Assert.IsTrue(firstPlayer.GetTurnWhenFirst > GamesToPlay * 10);
            Assert.IsTrue(firstPlayer.GetTurnWhenSecond > GamesToPlay * 10);
            Assert.IsTrue(firstPlayer.EndTurnCalledCount > GamesToPlay * 10);

            Assert.IsTrue(secondPlayer.GetTurnWhenFirst > GamesToPlay * 10);
            Assert.IsTrue(secondPlayer.GetTurnWhenSecond > GamesToPlay * 10);
            Assert.IsTrue(secondPlayer.EndTurnCalledCount > GamesToPlay * 10);
        }
예제 #11
0
        public void PlayersMethodsShouldBeCalledCorrectNumberOfTimes()
        {
            const int GamesToPlay = 200;

            var firstPlayer  = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();

            for (var i = 0; i < GamesToPlay; i++)
            {
                var firstToPlay = i % 2 == 0 ? PlayerPosition.FirstPlayer : PlayerPosition.SecondPlayer;
                var game        = new SantaseGame(firstPlayer, secondPlayer);
                game.Start(firstToPlay);
            }

            // StartGame()
            Assert.AreEqual(GamesToPlay, firstPlayer.StartGameCalledCount);
            Assert.AreEqual(GamesToPlay, secondPlayer.StartGameCalledCount);

            // EndGame()
            Assert.AreEqual(GamesToPlay, firstPlayer.EndGameCalledCount);
            Assert.AreEqual(GamesToPlay, secondPlayer.EndGameCalledCount);

            // StartRound()
            Assert.GreaterOrEqual(
                firstPlayer.StartRoundCalledCount,
                4 * GamesToPlay,
                "Not started at least 4 rounds per game for the first player");
            Assert.GreaterOrEqual(
                secondPlayer.StartRoundCalledCount,
                4 * GamesToPlay,
                "Not started at least 4 rounds per game for the second player");

            // EndRound()
            Assert.GreaterOrEqual(
                firstPlayer.EndRoundCalledCount,
                GamesToPlay * 4,
                "Not ended at least 4 rounds per game for the first player");
            Assert.GreaterOrEqual(
                secondPlayer.EndRoundCalledCount,
                GamesToPlay * 4,
                "Not ended at least 4 rounds per game for the second player");

            // GetTurn() and EndTurn()
            Assert.IsTrue(firstPlayer.GetTurnWhenFirst > GamesToPlay * 10);
            Assert.IsTrue(firstPlayer.GetTurnWhenSecond > GamesToPlay * 10);
            Assert.IsTrue(firstPlayer.EndTurnCalledCount > GamesToPlay * 10);

            Assert.IsTrue(secondPlayer.GetTurnWhenFirst > GamesToPlay * 10);
            Assert.IsTrue(secondPlayer.GetTurnWhenSecond > GamesToPlay * 10);
            Assert.IsTrue(secondPlayer.EndTurnCalledCount > GamesToPlay * 10);
        }
예제 #12
0
        public void StartingGameShouldRestartTheGameToReuseGameInstance()
        {
            const int GamesToPlay = 20;

            var firstPlayer  = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();
            var game         = new SantaseGame(firstPlayer, secondPlayer, GameRulesProvider.Santase, new NoLogger());

            for (var i = 0; i < GamesToPlay; i++)
            {
                game.Start(i % 2 == 0 ? PlayerPosition.FirstPlayer : PlayerPosition.SecondPlayer);
            }

            Assert.True(
                firstPlayer.StartRoundCalledCount >= 4 * GamesToPlay,
                "Not started at least 4 rounds per game for the first player");
            Assert.True(
                secondPlayer.StartRoundCalledCount >= 4 * GamesToPlay,
                "Not started at least 4 rounds per game for the second player");
        }
        public void PlayersStartRoundAndEndRoundShouldBeCalledAndShouldReceiveEqualNumberOfCards()
        {
            var firstPlayer = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();
            var round = new Round(firstPlayer, secondPlayer, GameRulesProvider.Santase);

            round.Play(0, 0);

            Assert.AreEqual(firstPlayer.AddCardCalledCount, secondPlayer.AddCardCalledCount);

            Assert.AreEqual(firstPlayer.StartRoundCalledCount, 1);
            Assert.AreEqual(secondPlayer.StartRoundCalledCount, 1);

            Assert.AreEqual(firstPlayer.EndRoundCalledCount, 1);
            Assert.AreEqual(secondPlayer.EndRoundCalledCount, 1);

            Assert.GreaterOrEqual(firstPlayer.AddCardCalledCount, 2);
            Assert.GreaterOrEqual(secondPlayer.AddCardCalledCount, 2);
            Assert.LessOrEqual(firstPlayer.AddCardCalledCount, 6);
            Assert.LessOrEqual(secondPlayer.AddCardCalledCount, 6);
        }
예제 #14
0
        public void PlayersStartRoundAndEndRoundShouldBeCalledAndShouldReceiveEqualNumberOfCards()
        {
            var firstPlayer  = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();
            var round        = new Round(firstPlayer, secondPlayer, GameRulesProvider.Santase);

            round.Play(0, 0);

            Assert.Equal(firstPlayer.AddCardCalledCount, secondPlayer.AddCardCalledCount);

            Assert.Equal(1, firstPlayer.StartRoundCalledCount);
            Assert.Equal(1, secondPlayer.StartRoundCalledCount);

            Assert.Equal(1, firstPlayer.EndRoundCalledCount);
            Assert.Equal(1, secondPlayer.EndRoundCalledCount);

            Assert.True(firstPlayer.AddCardCalledCount >= 2);
            Assert.True(secondPlayer.AddCardCalledCount >= 2);
            Assert.True(firstPlayer.AddCardCalledCount <= GameRulesProvider.Santase.CardsAtStartOfTheRound);
            Assert.True(secondPlayer.AddCardCalledCount <= GameRulesProvider.Santase.CardsAtStartOfTheRound);
        }
예제 #15
0
        public void PlayersStartRoundAndEndRoundShouldBeCalledAndShouldReceiveEqualNumberOfCards()
        {
            var firstPlayer  = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();
            var round        = new Round(firstPlayer, secondPlayer, GameRulesProvider.Santase);

            round.Play(0, 0);

            Assert.AreEqual(firstPlayer.AddCardCalledCount, secondPlayer.AddCardCalledCount);

            Assert.AreEqual(firstPlayer.StartRoundCalledCount, 1);
            Assert.AreEqual(secondPlayer.StartRoundCalledCount, 1);

            Assert.AreEqual(firstPlayer.EndRoundCalledCount, 1);
            Assert.AreEqual(secondPlayer.EndRoundCalledCount, 1);

            Assert.GreaterOrEqual(firstPlayer.AddCardCalledCount, 2);
            Assert.GreaterOrEqual(secondPlayer.AddCardCalledCount, 2);
            Assert.LessOrEqual(firstPlayer.AddCardCalledCount, 6);
            Assert.LessOrEqual(secondPlayer.AddCardCalledCount, 6);
        }
예제 #16
0
        public void StartingGameShouldRestartTheGameToReuseGameInstance()
        {
            const int GamesToPlay = 20;

            var firstPlayer = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();
            var game = new SantaseGame(firstPlayer, secondPlayer, GameRulesProvider.Santase, new NoLogger());

            for (var i = 0; i < GamesToPlay; i++)
            {
                game.Start(i % 2 == 0 ? PlayerPosition.FirstPlayer : PlayerPosition.SecondPlayer);
            }

            Assert.GreaterOrEqual(
                firstPlayer.StartRoundCalledCount,
                4 * GamesToPlay,
                "Not started at least 4 rounds per game for the first player");
            Assert.GreaterOrEqual(
                secondPlayer.StartRoundCalledCount,
                4 * GamesToPlay,
                "Not started at least 4 rounds per game for the second player");
        }
예제 #17
0
        public void WinnersShouldBeEquallyDistributed()
        {
            const int GamesToPlay = 200;

            var firstPlayer = new ValidPlayerWithMethodsCallCounting();
            var secondPlayer = new ValidPlayerWithMethodsCallCounting();

            var firstPlayerWinner = 0;
            var secondPlayerWinner = 0;

            for (var i = 0; i < GamesToPlay; i++)
            {
                var firstToPlay = i % 2 == 0 ? PlayerPosition.FirstPlayer : PlayerPosition.SecondPlayer;
                var game = new SantaseGame(firstPlayer, secondPlayer);
                var winner = game.Start(firstToPlay);
                if (winner == PlayerPosition.FirstPlayer)
                {
                    firstPlayerWinner++;
                }
                else if (winner == PlayerPosition.SecondPlayer)
                {
                    secondPlayerWinner++;
                }
            }

            Assert.AreEqual(GamesToPlay, firstPlayerWinner + secondPlayerWinner);
            Assert.IsTrue(Math.Abs(firstPlayerWinner - secondPlayerWinner) < 150);
        }