Esempio n. 1
0
        public void GamesFromDB_Test()
        {
            string gameInput;
            int    expectedValue;
            bool   causesException;

            gameInput       = TestContext.DataRow["GameInput"].ToString();
            expectedValue   = Convert.ToInt32(TestContext.DataRow["ExpectedValue"]);
            causesException = Convert.ToBoolean(TestContext.DataRow["CausesException"]);

            TenPinsGame game = new TenPinsGame();


            try
            {
                var actualValue = game.ShowScore(gameInput);
                Assert.AreEqual(expectedValue, actualValue,
                                $"The Game: '{gameInput}', has following Actual Score: {actualValue}");
            }
            catch (AssertFailedException ex)
            {
                throw ex;
            }
            catch (ArgumentNullException)
            {
                Assert.IsTrue(causesException);
            }
        }
Esempio n. 2
0
        public void TestsGameWithSpareOnTheFinalFrameAndOneBonusThrows()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            string      gameInput     = "X|7/|9-|x|-8|8/|-6|x|X|2/||8";
            int         expectedScore = 150;

            //-- Act
            int actualScore = game.ShowScore(gameInput);

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
Esempio n. 3
0
        public void TestsGameWithoutAnyBonuses()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            string      gameInput     = "X|7/|9-|x|-8|8/|-6|x|X|2-||";
            int         expectedScore = 126;

            //-- Act
            int actualScore = game.ShowScore(gameInput);

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
Esempio n. 4
0
        public void TestsGameWhenEveryFrameHasOneMiss()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            string      gameInput     = "9-|9-|9-|9-|9-|9-|9-|9-|9-|9-||";
            int         expectedScore = 90;

            //-- Act
            int actualScore = game.ShowScore(gameInput);

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
Esempio n. 5
0
        public void TestsGameInputWithWhiteSpaceBeforeFinalFrameDivider()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            string      gameInput     = "X|7/|9-|x|-8|8/|-6|x|X|X ||81";
            int         expectedScore = 167;

            //-- Act
            int actualScore = game.ShowScore(gameInput);

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
Esempio n. 6
0
        public void TestsGameInputWithLeadingAndTrailingWhiteSpaces()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            string      gameInput     = " X|7/|9-|x|-8|8/|-6|x|X|X||81 ";
            int         expectedScore = 167;

            //-- Act
            int actualScore = game.ShowScore(gameInput);

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
Esempio n. 7
0
        public void TestsGameZeroInsteadOfMissChar()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            string      gameInput     = "90|9-|9-|9-|9-|9-|9-|9-|9-|90||";
            int         expectedScore = 90;

            //-- Act
            int actualScore = game.ShowScore(gameInput);

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
Esempio n. 8
0
        public void TestsGameWhenEveryFrameHasSpare()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            string      gameInput     = "5/|5/|5/|5/|5/|5/|5/|5/|5/|5/||5";
            int         expectedScore = 150;

            //-- Act
            int actualScore = game.ShowScore(gameInput);

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
Esempio n. 9
0
        public void TestsGameWhenEveryThrowIsStrike()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            string      gameInput     = "X|X|x|x|x|x|x|x|X|X||xx";
            int         expectedScore = 300;

            //-- Act
            int actualScore = game.ShowScore(gameInput);

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
Esempio n. 10
0
 public static void ScoreCommand(string gameInput)
 {
     try
     {
         TenPinsGame game = new TenPinsGame();
         Console.WriteLine("Game: {0}", gameInput);
         Console.WriteLine("Score: " + game.ShowScore(gameInput));
         Console.WriteLine("#=====#");
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return;
     }
 }
Esempio n. 11
0
        public void TestsFailedToShowScoreWhenInputIsEmpty()
        {
            //-- Arrange
            TenPinsGame game      = new TenPinsGame();
            string      gameInput = string.Empty;

            try
            {
                game.ShowScore(gameInput);
            }
            catch (ArgumentNullException)
            {
                return;
            }
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 12
0
        public void TestsFailedOnGameWithSpareOnTheFirstThrowOfTheFrame()
        {
            //-- Arrange
            TenPinsGame game      = new TenPinsGame();
            string      gameInput = "X|//|9-|x|-8|8/|-6|x|X|X||81";

            try
            {
                game.ShowScore(gameInput);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                return;
            }
            Assert.Fail("Call did NOT throw the ArgumentOutOfRangeException");
        }
Esempio n. 13
0
        public void TestsFailedOnGameWithTooManyFrames()
        {
            //-- Arrange
            TenPinsGame game      = new TenPinsGame();
            string      gameInput = "X|71|3-|9-|x|-8|8/|-6|x|X|X||81";

            try
            {
                game.ShowScore(gameInput);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("You specified 11 frames, which is more than allowed # of 10. Please check your input.", ex.Message);
                return;
            }
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 14
0
        public void TestsFailedWithSpareOnTheFinalFrameAndTwoBonuses()
        {
            //-- Arrange
            TenPinsGame game      = new TenPinsGame();
            string      gameInput = "X|7/|9-|x|-8|8/|-6|x|X|9/||81";

            try
            {
                game.ShowScore(gameInput);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("The number of bonus throws 2, is over allowed for the Last Spare. Please check.", ex.Message);
                return;
            }
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 15
0
        public void TestsFailedOnGameWhenSpareSetOnBonusThrow()
        {
            //-- Arrange
            TenPinsGame game      = new TenPinsGame();
            string      gameInput = "X|7/|9-|x|-8|8/|-6|x|X|X||8/";

            try
            {
                game.ShowScore(gameInput);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("The 'Spare' cannot be set on the Bonus Throws, please check.", ex.Message);
                return;
            }
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 16
0
        public void TestsFailedOnGameWithNoFrameDividersAtAll()
        {
            //-- Arrange
            TenPinsGame game      = new TenPinsGame();
            string      gameInput = "X;7/;9-;x;-8;8/;-6;x;X;X||81";

            try
            {
                game.ShowScore(gameInput);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("Your input does not have any frames devider '|'. Pls check.", ex.Message);
                return;
            }
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 17
0
        public void TestsFailedWithSpareOnTheFinalFrameAndNoBonuses()
        {
            //-- Arrange
            TenPinsGame game      = new TenPinsGame();
            string      gameInput = "X|7/|9-|x|-8|8/|-6|x|X|9/||";

            try
            {
                game.ShowScore(gameInput);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("You're missing the bonus points. Pls check.", ex.Message);
                return;
            }
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 18
0
        public void TestsFailedOnGameWithAnEmptyFrame()
        {
            //-- Arrange
            TenPinsGame game      = new TenPinsGame();
            string      gameInput = "X|7/|9-||-8|8/|-6|x|X|X||81";

            try
            {
                game.ShowScore(gameInput);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("The '||' divider can be only one per the input. Please check.", ex.Message);
                return;
            }
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 19
0
        public void TestsFailedOnGameWithFrameDividerInsteadOfFinalFrameDividerWithBonus()
        {
            //-- Arrange
            TenPinsGame game      = new TenPinsGame();
            string      gameInput = "X|7/|9-|x|-8|8/|-6|x|X|X|81";

            try
            {
                game.ShowScore(gameInput);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("The frames data has to end with '||' (divider between frames and bonus throws). Please check.", ex.Message);
                return;
            }
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 20
0
        public void TestsFailedOnGameWithKnowckedDownPinsHigherThanStartingPins()
        {
            //-- Arrange
            TenPinsGame game      = new TenPinsGame();
            string      gameInput = "X|7/|92|x|-8|8/|-6|x|X|X||81";

            try
            {
                game.ShowScore(gameInput);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("Your Knocked down Pins count of 11 is out of range for StartingPinsNumber of '10'. Please check.", ex.Message);
                return;
            }
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 21
0
        public void TestsFailedWithoutStrikeOrSpareOnTheFinalFrameButWithBonuses()
        {
            //-- Arrange
            TenPinsGame game      = new TenPinsGame();
            string      gameInput = "X|7/|9-|x|-8|8/|-6|x|X|9-||8";

            try
            {
                game.ShowScore(gameInput);
            }
            catch (InvalidOperationException ex)
            {
                Assert.AreEqual("You're trying to add a Bonus, while it's not allowed based on your last throw. Pls. check.", ex.Message);
                return;
            }
            Assert.Fail("Call did NOT throw the InvalidOperationException");
        }
Esempio n. 22
0
        public void TestsFailedOnGameWithTooLittleFrames()
        {
            //-- Arrange
            TenPinsGame game      = new TenPinsGame();
            string      gameInput = "X|7/|9-|x|-8|8/|-6|xX|X||81";

            try
            {
                game.ShowScore(gameInput);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("You played 9 turns, which is less than required # of 10. Please check your input.", ex.Message);
                return;
            }
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 23
0
        public void TestsFailedOnGameWithTooLittleTrowsOnTheFrameAndFollowedByStrike()
        {
            //-- Arrange
            TenPinsGame game      = new TenPinsGame();
            string      gameInput = "X|7/|9|x|-8|8/|-6|x|X|X||81";

            try
            {
                game.ShowScore(gameInput);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("It looks you're missing a throw for the frame.", ex.Message);
                return;
            }
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 24
0
        public void TestsFailedOnGameWithTooManyThrowsForTheFrame()
        {
            //-- Arrange
            TenPinsGame game      = new TenPinsGame();
            string      gameInput = "X|713|9-|x|-8|8/|-6|x|X|X||81";

            try
            {
                game.ShowScore(gameInput);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("You have too many throws (3) for one (non-final) Frame. Pls check.", ex.Message);
                return;
            }
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 25
0
        public void TestsFailedOnGameWithSpecialCharForTheThrow()
        {
            //-- Arrange
            TenPinsGame game      = new TenPinsGame();
            string      gameInput = "X|7/|9-|x|-8|8/|-6|x|X|X||8!";

            try
            {
                game.ShowScore(gameInput);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("Invalid character '!' was detected in the provided input, please check.", ex.Message);
                return;
            }
            Assert.Fail("Call did NOT throw the Argument Exception");
        }
Esempio n. 26
0
        public void TestsFailedWhenStartingPinsNumberIsZero()
        {
            //-- Arrange
            TenPinsGame    game      = new TenPinsGame();
            string         gameInput = "X|7/|9-|x|-8|8/|-6|x|X|X||81";
            CommonGameData data;

            try
            {
                data = new CommonGameData(10, 0);
                game.ShowScore(gameInput);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("MaxFrameNumber and StartingPinsNumber has to be higher than 0.", ex.Message);
                return;
            }
            Assert.Fail("Call did NOT throw the Argument Exception");
        }