Пример #1
0
        public void GetScore_ShouldShouldReturnExpectedValue(int player1ScoredCount, int player2ScoredCount, string score)
        {
            //Arrange
            var player1 = new Player("Player1");
            var player2 = new Player("Player2");
            var game    = new TennisGame(player1, player2);

            //Act
            int i = 0, j = 0;

            for (; i < player1ScoredCount || j < player2ScoredCount; j++, i++)
            {
                if (i < player1ScoredCount)
                {
                    game.PlayerScored(player1);
                }
                if (j < player2ScoredCount)
                {
                    game.PlayerScored(player2);
                }
            }

            var result = game.GetScore();

            //Assert
            result.ShouldBe(score);
        }
Пример #2
0
        public void GetScore_Start_Shouldbe15_15()
        {
            //Arrange
            var player1 = new Player("Player1");
            var player2 = new Player("Player2");
            var game    = new TennisGame(player1, player2);


            //Act
            game.PlayerScored(player1);
            game.PlayerScored(player2);
            var score = game.GetScore();

            //Assert
            score.ShouldBe("15-15");
        }
Пример #3
0
        public void GetScore_ShouldBeDeuse(int score)
        {
            //Arrange
            var player1 = new Player("Player1");
            var player2 = new Player("Player2");
            var game    = new TennisGame(player1, player2);

            //Act
            for (int i = 0; i < score; i++)
            {
                game.PlayerScored(player1);
                game.PlayerScored(player2);
            }

            var result = game.GetScore();

            //Assert
            result.ShouldBe("deuse");
        }
Пример #4
0
        public void GetScore_Player2ShouldBeInAdvantage(int player2Score)
        {
            //Arrange
            var player1 = new Player("Player1");
            var player2 = new Player("Player2");
            var game    = new TennisGame(player1, player2);

            //Act
            for (int i = 0; i < player2Score; i++)
            {
                game.PlayerScored(player1);
                game.PlayerScored(player2);
            }

            game.PlayerScored(player2);

            var result = game.GetScore();

            //Assert
            result.ShouldBe("Player2 advantage");
        }
Пример #5
0
        public void GetScore_Player1OverScores_ShouldThrowError()
        {
            //Arrange
            var player1 = new Player("Player1");
            var player2 = new Player("Player2");
            var game    = new TennisGame(player1, player2);

            //Act
            game.PlayerScored(player2); // 0-15
            game.PlayerScored(player1); // 15-15
            game.PlayerScored(player1); // 30-15
            game.PlayerScored(player2); // 30-30
            game.PlayerScored(player2); // 30-40
            game.PlayerScored(player1); // 40-40
            game.PlayerScored(player1); // advantage 1
            game.PlayerScored(player1); // player 1 wins

            Assert.Throws <InvalidOperationException>(() => game.PlayerScored(player1));
        }
Пример #6
0
        public void GetScore_Player2ShouldWinAfterAdvantage()
        {
            //Arrange
            var player1 = new Player("Player1");
            var player2 = new Player("Player2");
            var game    = new TennisGame(player1, player2);

            //Act
            game.PlayerScored(player2);
            game.PlayerScored(player1);
            game.PlayerScored(player1);
            game.PlayerScored(player2);
            game.PlayerScored(player2);
            game.PlayerScored(player1);
            game.PlayerScored(player2);
            game.PlayerScored(player2);

            var result = game.GetScore();

            //Assert
            result.ShouldBe("Player2 win");
        }