Exemple #1
0
        public async Task Calculate_GameCompleted_ExpectRemainingPointsReturned()
        {
            var game = new TennisGame
                       (
                new List <char>
            {
                'A',
                'A',
                'A',
                'A',
                'B',
                'B',
                'A',
                'B'
            }
                       );

            var set = await _sut.Calculate(game);

            var expectedRemaining = new List <char>
            {
                'B',
                'B',
                'A',
                'B'
            };

            set.Remaining.Points.ShouldBeEquivalentTo(expectedRemaining, options => options.WithStrictOrdering());
        }
        public void ScoreShouldBeFifteenLoveTest()
        {
            TennisGame tennisGame = new TennisGame("James", "Edwards");

            tennisGame.PointScored("James");
            Assert.AreEqual("Fifteen-Love", tennisGame.Score());
        }
Exemple #3
0
        public async Task Calculate_3PointsForA_4PointsForB_3PointsForA_ExpectGameComplete_WinnerA_ServerScore40_ReceiverScore40()
        {
            var game = new TennisGame
                       (
                new List <char>
            {
                'A',
                'A',
                'A',
                'B',
                'B',
                'B',
                'B',
                'A',
                'A',
                'A'
            }
                       );

            var set = await _sut.Calculate(game);

            set.Set.GameCompleted.Should().BeTrue();
            set.Set.Winner.Should().Be('A');
            set.Set.ServerScore.Should().Be(40);
            set.Set.ReceiverScore.Should().Be(40);
        }
Exemple #4
0
        public void ChangeSides()
        {
            TennisGame game = new TennisGame("Name_1", "Name_2");

            game.ChangeSides();
            Assert.IsTrue((game.LeftSide() == game.Player_2()) && (game.RightSide() == game.Player_1()));
        }
Exemple #5
0
        public void SetAdvantage()
        {
            TennisGame game = new TennisGame("Name_1", "Name_2");

            game.SetAdvantage(1);
            Assert.IsTrue(game.Advantage() == game.Player_1().Name());
        }
Exemple #6
0
        public void StartAdvantage()
        {
            TennisGame game = new TennisGame("Name_1", "Name_2");

            Assert.IsTrue(game.Advantage() == "Nothing");
            //We use player name or nothing to avoid creation third player
        }
Exemple #7
0
        public void PlayersDifferent()
        {
            TennisGame game = new TennisGame("Eman", "Eman");

            Assert.IsTrue(game.Player_1().Name() == "Eman_1");
            Assert.IsTrue(game.Player_2().Name() == "Eman_2");
        }
Exemple #8
0
        public void ChangeBall()
        {
            TennisGame game = new TennisGame("Name_1", "Name_2");

            game.ChangeBall();
            Assert.IsTrue(game.Ball() == 2);
        }
 public static void PlayerTwoScore(this TennisGame tennisGame, int points)
 {
     for (int i = 0; i < points; i++)
     {
         tennisGame.PlayerTwoScore();
     }
 }
Exemple #10
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);
        }
Exemple #11
0
        public async Task <List <TennisGame> > ReadFile(string filePath)
        {
            var gamesList = new List <TennisGame>();

            var fileLines = new List <string>();

            try
            {
                fileLines = await _streamReader.ReadLineAsync(filePath);
            }
            catch (Exception)
            {
            }

            foreach (var line in fileLines)
            {
                var tennisGame = new TennisGame(new List <char>());

                foreach (var character in line)
                {
                    tennisGame.Points.Add(character);
                }
                gamesList.Add(tennisGame);
            }

            return(gamesList);
        }
Exemple #12
0
        public async Task Calculate_Deuce_3PointsB_4PointsA_2PointsB_ExpectGameNotComplete_NoWinner_ServerScore40_ReceiverScore40()
        {
            var game = new TennisGame
                       (
                new List <char>
            {
                'B',
                'B',
                'B',
                'A',
                'A',
                'A',
                'A',
                'B',
                'B'
            }
                       );

            var set = await _sut.Calculate(game);

            set.Set.GameCompleted.Should().BeFalse();
            set.Set.Winner.Should().Be(' ');
            set.Set.ServerScore.Should().Be(40);
            set.Set.ReceiverScore.Should().Be(40);
            set.Set.AdvantagePoint.Should().Be('B');
        }
 private static void PlayerTwoScoresExtra(int extraScores, TennisGame game)
 {
     for (int points = 0; points < extraScores; points++)
     {
         PlayerTwoScores(game);
     }
 }
Exemple #14
0
        public static void coinFlip()
        {
            int    heads     = 0;
            int    tails     = 1;
            int    count     = 0;
            var    startGame = new TennisGame();
            Random coinFlip  = new Random();

            startGame.PlayGame();

            Console.WriteLine("Press any key to play game");
            string anyKey = Console.ReadLine();

            while (count < 1)
            {
                int randomNumber = coinFlip.Next(0, 2);
                count = count + 1;
                if (randomNumber == heads)
                {
                    Console.WriteLine("COIN HAS BEEN FLIPPED - HEADS!\n" + "FIRST SERVE!\n");
                }
                else if (randomNumber == tails)
                {
                    Console.WriteLine("COIN HAS BEEN FLIPPED - Tails!\n" + "FIRST SERVE!\n");
                }
            }
            startGame.mainGame();
        }
Exemple #15
0
        public void PlayersCorrectly()
        {
            TennisGame game = new TennisGame("Name_1", "Name_2");

            Assert.IsTrue(game.Player_1().Name() == "Name_1");
            Assert.IsTrue(game.Player_2().Name() == "Name_2");
        }
Exemple #16
0
        public void UpFirstRound()
        {
            TennisGame game = new TennisGame("Name_1", "Name_2");

            game.UpRound(game.Player_1());
            Assert.IsTrue(game.Player_1().Score(0) == 15);
        }
        public void PlayerOneScoreThreePoints40Love()
        {
            var tennisGame = new TennisGame();

            tennisGame.PlayerOneScore(3);

            Assert.Equal("40 love", tennisGame.GetScore());
        }
        public void PlayerTwoScoreOnePointLove30()
        {
            var tennisGame = new TennisGame();

            tennisGame.PlayerTwoScore(2);

            Assert.Equal("love 30", tennisGame.GetScore());
        }
 private static void BothPlayersScoreAtEqualPace(int ScoringAtEqualPace, TennisGame game)
 {
     for (int points = 0; points < ScoringAtEqualPace; points++)
     {
         PlayerOneScores(game);
         PlayerTwoScores(game);
     }
 }
        public void PlayerOneScoreTwoPoints30Love()
        {
            var tennisGame = new TennisGame();

            tennisGame.PlayerOneScore(2);

            Assert.Equal("30 love", tennisGame.GetScore());
        }
Exemple #21
0
        public void ClearAdvantage()
        {
            TennisGame game = new TennisGame("Name_1", "Name_2");

            game.SetAdvantage(2);
            game.ClearAdvantage();
            Assert.IsTrue(game.Advantage() == "Nothing");
        }
        public void PlayerOneScorePoint15Love()
        {
            var tennisGame = new TennisGame();

            tennisGame.PlayerOneScore(1);

            Assert.Equal("15 love", tennisGame.GetScore());
        }
Exemple #23
0
        public void Fiften_Fiften_Home_Thirty_Fiften()
        {
            this.InitialPlayer(TennisScore.Fiften, TennisScore.Fiften);
            TennisGame tennisGame = new TennisGame(this.HomePlayer, this.AwayPlayer);
            var        excepct    = "Thirty_Fiften";
            var        actual     = tennisGame.GetCurrentScore(TennisPlayerType.HomePlayer);

            Assert.AreEqual(excepct, actual);
        }
Exemple #24
0
        public void ThrowExceptionOnWrongScore()
        {
            _player1.Setup(x => x.Score).Returns(-1);
            _player2.Setup(x => x.Score).Returns(-1);

            var sut = new TennisGame(_player1.Object, _player2.Object);

            Assert.Throws <IndexOutOfRangeException>(() => sut.Play());
        }
Exemple #25
0
        public static void Main(string[] args)
        {
            TennisGame game = new TennisGame();

            while (game.IsOngoing())
            {
                game.PlayBall();
            }
        }
        public void DeuceThreePoints()
        {
            var tennisGame = new TennisGame();

            tennisGame.PlayerOneScore(3);
            tennisGame.PlayerTwoScore(3);

            Assert.Equal("deuce", tennisGame.GetScore());
        }
        public void AdvantagePlayerTwo()
        {
            var tennisGame = new TennisGame();

            tennisGame.PlayerOneScore(4);
            tennisGame.PlayerTwoScore(5);

            Assert.Equal("advantage player2", tennisGame.GetScore());
        }
        public void BothScoreTwice()
        {
            var tennisGame = new TennisGame();

            tennisGame.PlayerOneScore(2);
            tennisGame.PlayerTwoScore(2);

            Assert.Equal("30 all", tennisGame.GetScore());
        }
        public void ScoreShouldBeThiryFifteenTest()
        {
            TennisGame tennisGame = new TennisGame("James", "Edwards");

            tennisGame.PointScored("James");
            tennisGame.PointScored("James");
            tennisGame.PointScored("Edwards");
            Assert.AreEqual("Thirty-Fifteen", tennisGame.Score());
        }
        public void WinnerPlayerTwo()
        {
            var tennisGame = new TennisGame();

            tennisGame.PlayerOneScore(2);
            tennisGame.PlayerTwoScore(4);

            Assert.Equal("winner player2", tennisGame.GetScore());
        }
 public void Init()
 {
     _game = new TennisGame();
 }
Exemple #32
0
 public void GetScore_ShouldReturnAdvPlayer1_WhenScoreIs4And5()
 {
     TennisGame game = new TennisGame(4, 5);
     Assert.AreEqual("Adv Player2", game.GetScore());
 }
Exemple #33
0
        public void RealisticTennisGame()
        {
            TennisGame game = new TennisGame(0, 0);
            Assert.AreEqual("Love-Love", game.GetScore());

            string[] points = { "player1", "player1", "player2", "player2", "player1", "player1" };
            string[] expectedScores = { "Fifteen-Love", "Thirty-Love", "Thirty-Fifteen", "Thirty-Thirty", "Forty-Thirty", "Win Player1" };
            for (int i = 0; i < expectedScores.Length; i++)
            {
                game.WonPoint(points[i]);
                Assert.AreEqual(expectedScores[i], game.GetScore());
            }
        }
Exemple #34
0
 public void GetScore_ShouldReturnThirtyLove_WhenScoreIs2And0()
 {
     TennisGame game = new TennisGame(2, 0);
     Assert.AreEqual("Thirty-Love", game.GetScore());
 }
Exemple #35
0
 public void GetScore_ShouldReturnLoveFifteen_WhenScoreIs0And1()
 {
     TennisGame game = new TennisGame(0, 1);
     Assert.AreEqual("Love-Fifteen", game.GetScore());
 }
Exemple #36
0
 public void GetScore_ShouldReturnWinPlayer2_WhenScoreIs2And4()
 {
     TennisGame game = new TennisGame(2, 4);
     Assert.AreEqual("Win Player2", game.GetScore());
 }
Exemple #37
0
 public void GetScore_ShouldReturnWinPlayer1_WhenScoreIs4And2()
 {
     TennisGame game = new TennisGame(4, 2);
     Assert.AreEqual("Win Player1", game.GetScore());
 }
Exemple #38
0
 public void GetScore_ShouldReturnThirtyThirty_WhenScoreIs2And2()
 {
     TennisGame game = new TennisGame(2, 2);
     Assert.AreEqual("Thirty-Thirty", game.GetScore());
 }
 public void CheckGame1()
 {
     TennisGame game = new TennisGame("player1", "player2");
     RealisticTennisGame(game);
 }
Exemple #40
0
 public void GetScore_ShouldReturnFifteenLove_WhenScoreIs1And0()
 {
     TennisGame game = new TennisGame(1, 0);
     Assert.AreEqual("Fifteen-Love", game.GetScore());
 }
 public void checkTennisGame1()
 {
     TennisGame game = new TennisGame("player1", "player2");
     checkAllScores(game);
 }
Exemple #42
0
 public void GetScore_ShouldReturnAdvPlayer2_WhenScoreIs5And4()
 {
     TennisGame game = new TennisGame(5, 4);
     Assert.AreEqual("Adv Player1", game.GetScore());
 }
Exemple #43
0
 public void GetScore_ShouldReturnDeuce_WhenScoreIs6And6()
 {
     TennisGame game = new TennisGame(6, 6);
     Assert.AreEqual("Deuce", game.GetScore());
 }
Exemple #44
0
 public void GetScore_ShouldReturnLoveLove_WhenScoreIs0And0()
 {
     TennisGame game = new TennisGame(0, 0);
     Assert.AreEqual("Love-Love", game.GetScore());
 }