コード例 #1
0
        protected GameBase(string gameInput)
        {
            ListOfKickedPins = new List <int>();
            var gameParser = new GameParser();

            ListOfKickedPins = gameParser.ParseGameInputString(gameInput);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
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);
        }
コード例 #6
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);
        }
コード例 #7
0
        public void Test_Game_Complete_With_Only_Strike_On_Last_Frame_And_Two_Single_Bonuses()
        {
            //-- 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, 1, 1");
            int         expectedScore = 12;
            int         actualScore   = 0;

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

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
コード例 #8
0
        public void Test_Game_Complete_With_Factorial_Increments_On_Every_Frame()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            GameParser  gameParser    = new GameParser();
            List <int>  intInputList  = gameParser.ParseGameInputString("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);
        }
コード例 #9
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);
        }
コード例 #10
0
        public void TestFailed_Game_Input_IntoParser_Empty()
        {
            //-- Arrange
            GameParser gameParser = new GameParser();

            //-- Act
            try
            {
                gameParser.ParseGameInputString("");
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("You have an invalid input ``. Pls check.", ex.Message);
                return;
            }

            //-- Assert
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
コード例 #11
0
        public void Test_Intermittent_Score_Till_RegularGameComplete_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");
            List <int>  expectedScoresList = new List <int> {
                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);
            }
        }
コード例 #12
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");
        }
コード例 #13
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");
        }
コード例 #14
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");
        }
コード例 #15
0
    protected Game(string gameInput)
    {
        var gameParser = new GameParser();

        ListOfItemss = gameParser.ParseGameInputString(gameInput);
    }