public void TestFailed_OnGame_Complete_Extra_Bowl()
        {
            //-- Arrange
            TenPinsGame game = new TenPinsGame();

            for (int i = 0; i < 10; i++)
            {
                //bowl 1 for each ball in a frame
                game.Bowl(1);
                game.Bowl(1);
            }

            Action action = () => game.Bowl(2);

            action.Should().Throw <GameOverException>();
        }
Esempio n. 2
0
        public void should_calculate_score(string gameInput, int expectedScore, string reason)
        {
            int result = 0;
            var game   = new TenPinsGame(gameInput);

            foreach (var input in game.ListOfKickedPins)
            {
                result = game.Bowl(input);
            }

            Assert.AreEqual(expectedScore, result, reason);
        }
        public void should_calculate_score(string reason, string gameInput, int expectedScore)
        {
            int result = 0;
            var game   = new TenPinsGame();

            var bowls = gameInput.Split(',').Select(s => Convert.ToInt32(s));

            foreach (var input in bowls)
            {
                result = game.Bowl(input);
            }

            Assert.AreEqual(expectedScore, result, reason);
        }
        public void Test_Game_With_Single_Throw_NoBonuses_FrameIncomplete()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            var         intInputList  = new [] { 1 };
            int         expectedScore = 0;
            int         actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
        public void Test_Game_With_Three_Throws_NoBonuses()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            var         intInputList  = new [] { 1, 1, 5 };
            int         expectedScore = 2;
            int         actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
        public void Test_Regular_Game_Complete_With_Bonuses()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            var         intInputList  = new[] { 10, 7, 3, 9, 0, 10, 0, 8, 8, 2, 0, 6, 10, 10, 10, 8, 1 };
            int         expectedScore = 167;
            int         actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
        public void Test_Almost_Perfect_Game_Complete_With_Spare_On_Every_Frame()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            var         intInputList  = new [] { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 };
            int         expectedScore = 150;
            int         actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
        public void Test_Intermittent_Score_Till_RegularGameComplete_With_Bonuses()
        {
            //-- Arrange
            TenPinsGame game                         = new TenPinsGame();
            var         intInputList                 = new[] { 10, 7, 3, 9, 0, 10, 0, 8, 8, 2, 0, 6, 10, 10, 10, 8, 1 };
            var         expectedScoresList           = new [] { 0, 0, 20, 39, 48, 48, 48, 74, 74, 74, 84, 90, 90, 90, 120, 148, 167 };
            var         inputValuesAndExpectedScores = intInputList.Zip(expectedScoresList, (kickedPins, correspondingExpectedScore) => (kickedPins, correspondingExpectedScore));
            int         actualScore                  = 0;

            //-- Act
            foreach (var input in inputValuesAndExpectedScores)
            {
                actualScore = game.Bowl(input.kickedPins);
                //-- Assert
                Assert.AreEqual(input.correspondingExpectedScore, actualScore);
            }
        }
Esempio n. 9
0
        public void Test_Regular_Game_Complete_With_Bonuses()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            GameParser  gameParser    = new GameParser();
            List <int>  intInputList  = gameParser.ParseGameInputString("10, 7, 3, 9, 0, 10, 0, 8, 8, 2, 0, 6, 10, 10, 10, 8, 1");
            int         expectedScore = 167;
            int         actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
Esempio n. 10
0
        public void Test_Almost_Perfect_Game_Complete_With_Spare_On_Every_Frame()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            GameParser  gameParser    = new GameParser();
            List <int>  intInputList  = gameParser.ParseGameInputString("5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5");
            int         expectedScore = 150;
            int         actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
Esempio n. 11
0
        public void Test_Game_Complete_With_Single_Miss_On_Every_Frame_NoBonuses()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            GameParser  gameParser    = new GameParser();
            List <int>  intInputList  = gameParser.ParseGameInputString("9, 0, 9,0, 9,0,9, 0, 9, 0, 9, 0, 9,0 , 9,0, 9,0, 9,0");
            int         expectedScore = 90;
            int         actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
Esempio n. 12
0
        public void Test_Perfect_Game_Complete()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            GameParser  gameParser    = new GameParser();
            List <int>  intInputList  = gameParser.ParseGameInputString("10,10,10,10,10,10,10,10,10,10,10,10");
            int         expectedScore = 300;
            int         actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
Esempio n. 13
0
        public void Test_Game_With_Two_Throws_Spare()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            GameParser  gameParser    = new GameParser();
            List <int>  intInputList  = gameParser.ParseGameInputString("1, 9");
            int         expectedScore = 0;
            int         actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
        public void Test_Game_Complete_With_All_Misses_But_With_Last_FivePins()
        {
            //-- Arrange
            TenPinsGame game = new TenPinsGame();

            var intInputList  = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5 };
            int expectedScore = 5;
            int actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
Esempio n. 15
0
        public void Test_Game_Complete_With_All_Misses_But_With_Last_FivePins()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            GameParser  gameParser    = new GameParser();
            List <int>  intInputList  = gameParser.ParseGameInputString("0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,5 ");
            int         expectedScore = 5;
            int         actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
        public void Test_Perfect_Game_Complete()
        {
            //-- Arrange
            TenPinsGame game = new TenPinsGame();

            var intInputList  = new [] { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 };
            int expectedScore = 300;
            int actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
        public void Test_Game_Complete_With_Single_Miss_On_Every_Frame_NoBonuses()
        {
            //-- Arrange
            TenPinsGame game = new TenPinsGame();

            var intInputList  = new [] { 9, 0, 9, 0, 9, 0, 9, 0, 9, 0, 9, 0, 9, 0, 9, 0, 9, 0, 9, 0 };
            int expectedScore = 90;
            int actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
        public void Test_Game_Complete_With_Only_Strike_On_Last_Frame_And_Two_Single_Bonuses()
        {
            //-- Arrange
            TenPinsGame game = new TenPinsGame();

            var intInputList  = new [] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 1, 1 };
            int expectedScore = 12;
            int actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
        public void Test_Game_Complete_With_Factorial_Increments_On_Every_Frame()
        {
            //-- Arrange
            TenPinsGame game = new TenPinsGame();

            var intInputList  = new [] { 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0 };
            int expectedScore = 55;
            int actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
        public void Test_Game_Complete_With_Just_One_Spare_And_Single_One()
        {
            //-- Arrange
            TenPinsGame game = new TenPinsGame();

            var intInputList  = new [] { 0, 0, 0, 0, 0, 10, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            int expectedScore = 12;
            int actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
Esempio n. 21
0
        public void Test_Game_Complete_With_Only_Strike_On_Last_Frame_And_Pair_Bonus()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            GameParser  gameParser    = new GameParser();
            List <int>  intInputList  = gameParser.ParseGameInputString("0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 0,0, 10, 2, 0");
            int         expectedScore = 12;
            int         actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
        public void Test_Game_With_Four_Throws_Three_Strike_And_Miss()
        {
            //-- Arrange
            TenPinsGame game = new TenPinsGame();

            var intInputList  = new [] { 10, 10, 10, 0 };
            int expectedScore = 50;
            int actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
Esempio n. 23
0
        public void TestsFailed_OnGame_With_Letter_Instead_Of_Integer()
        {
            //-- Arrange
            TenPinsGame game = new TenPinsGame();

            //-- Act
            try
            {
                var input = "O";
                game.Bowl(Convert.ToInt32(input));
            }
            catch (FormatException ex)
            {
                Assert.AreEqual("Input string was not in a correct format.", ex.Message);
                return;
            }

            //-- Assert
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 24
0
        public void TestFailed_OnGame_KickedPinsInput_OutOfRange_AboveMax()
        {
            //-- Arrange
            TenPinsGame game               = new TenPinsGame();
            var         kickedPinsCount    = 11;
            var         startingPinsNumber = ConstTenPinsGameData.StartingPinsNumber;

            //-- Act
            try
            {
                game.Bowl(kickedPinsCount);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual($"The kicked pins count is '{kickedPinsCount}', but has to be between 0 and {startingPinsNumber}. Pls check.", ex.Message);
                return;
            }

            //-- Assert
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 25
0
        public void TestFailed_OnGame_With_Empty_Value()
        {
            //-- Arrange

            //-- Act
            try
            {
                TenPinsGame game = new TenPinsGame("0,");
                foreach (var input in game.ListOfKickedPins)
                {
                    game.Bowl(input);
                }
            }
            catch (FormatException ex)
            {
                return;
            }

            //-- Assert
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 26
0
        public void TestFailed_OnGame_With_Negative_Value()
        {
            //-- Arrange
            TenPinsGame game = new TenPinsGame("0,-1, 0");

            //-- Act
            try
            {
                foreach (var input in game.ListOfKickedPins)
                {
                    game.Bowl(input);
                }
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("The kicked pins count is '-1', but has to be between 0 and 10. Pls check.", ex.Message);
                return;
            }

            //-- Assert
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 27
0
        public void TestsFailed_OnGame_With_Strike_And_Next_Two_Throws_Higher_Than_StartingPins()
        {
            //-- Arrange
            TenPinsGame game         = new TenPinsGame();
            GameParser  gameParser   = new GameParser();
            List <int>  intInputList = gameParser.ParseGameInputString("10, 9, 5");

            //-- Act
            try
            {
                foreach (var input in intInputList)
                {
                    game.Bowl(input);
                }
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("The 2nd throw pins of 5 is higher than allowed for this frame. Pls check.", ex.Message);
                return;
            }

            //-- Assert
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 28
0
        public void TestFailed_OnGame_Complete_With_No_Misses_And_Two_Bonuses()
        {
            //-- Arrange
            TenPinsGame game         = new TenPinsGame();
            GameParser  gameParser   = new GameParser();
            List <int>  intInputList = gameParser.ParseGameInputString("1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1, 2");

            //-- Act
            try
            {
                foreach (var input in intInputList)
                {
                    game.Bowl(input);
                }
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("Sorry, you have played All available bowl-throws for this game. Pls start a new game.", ex.Message);
                return;
            }

            //-- Assert
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 29
0
        public void TestFailed_OnGame_Complete_With_No_Misses_But_OutOfRange_Throws_Sum()
        {
            //-- Arrange
            TenPinsGame game         = new TenPinsGame();
            GameParser  gameParser   = new GameParser();
            List <int>  intInputList = gameParser.ParseGameInputString("6,6, 6,6, 6,6, 6,6, 6,6, 6,6, 6,6, 6,6, 6,6, 6,6");

            //-- Act
            try
            {
                foreach (var input in intInputList)
                {
                    game.Bowl(input);
                }
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("The 2nd throw pins of 6 is higher than allowed for this frame. Pls check.", ex.Message);
                return;
            }

            //-- Assert
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
        public void TestFailed_OnGame_Complete_With_Last_Spare_And_Excessive_Bonuses()
        {
            //-- Arrange
            TenPinsGame game = new TenPinsGame();

            for (int i = 0; i < 9; i++)
            {
                //bowl 1 for each ball in a frame
                game.Bowl(1);
                game.Bowl(1);
            }

            //10th frame spare and bonus
            game.Bowl(1);
            game.Bowl(9);
            game.Bowl(2);

            //extra bonus
            Action action = () => game.Bowl(1);

            action.Should().Throw <Exception>();
        }