예제 #1
0
        public void TestCanHandleErronous11thFrameIssue_strike()
        {
            // arrange
            TraditionalBowlingScoringCalculator traditionalBowlingScoringCalculator =
                new TraditionalBowlingScoringCalculator();
            TraditionalBowlingScoreCalculatorValidator traditionalBowlingScoreCalculatorValidator =
                new TraditionalBowlingScoreCalculatorValidator(traditionalBowlingScoringCalculator);

            TestGameDataDto testGameDataDto = new TestGameDataDto();

            int[][] testGamePoints = new int[11][];
            for (int i = 0; i <= 10; i++)
            {
                testGamePoints[i] = new int[] { 10, 0 }
            }
            ;
            testGamePoints[10]     = new int[] { 10, 10 }; // simulates the 11th frame issue
            testGameDataDto.points = testGamePoints;

            // act
            traditionalBowlingScoreCalculatorValidator.HandleErronous11thFrameIssue(testGameDataDto);

            //assert
            Assert.IsTrue(testGameDataDto.points.Length == 10);
            Assert.AreEqual(testGameDataDto.points[9].Length, 3);
            Assert.IsTrue(testGameDataDto.points[9].All(point => point == 10));
        }
예제 #2
0
        public void TestCanConstructCalculatedScoreObjectTest()
        {
            // arrange
            TraditionalBowlingScoringCalculator traditionalBowlingScoringCalculator =
                new TraditionalBowlingScoringCalculator();
            TraditionalBowlingScoreCalculatorValidator traditionalBowlingScoreCalculatorValidator =
                new TraditionalBowlingScoreCalculatorValidator(traditionalBowlingScoringCalculator);

            IList <BowlingFrame> playedFrames = new List <BowlingFrame>()
            {
                BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 3, 7 }),
                BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 10, 0 }),
                BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 8, 2 }),
                BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 8, 1 }),
                BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 10, 0 }),
                BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 3, 4 }),
                BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 7, 0 }),
                BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 5, 5 }),
                BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 3, 2 }),
                BowlingFrame.CreateAndValidateFrameFromPoints(new int[] { 2, 5 })
            };

            // act
            CalculatedBowlingScoresDto calculatedBowlingScoresDto = traditionalBowlingScoreCalculatorValidator.ConstructScoresToValidate(playedFrames, traditionalBowlingScoringCalculator);

            // assert
            Assert.AreEqual(calculatedBowlingScoresDto.points.Length, 10);
            Assert.AreEqual(calculatedBowlingScoresDto.points.First(), 20);
            Assert.AreEqual(calculatedBowlingScoresDto.points.Last(), 123);
        }
예제 #3
0
        public void TestCanConvertTestDataToBowlingFrames()
        {
            // arrange
            TraditionalBowlingScoringCalculator traditionalBowlingScoringCalculator =
                new TraditionalBowlingScoringCalculator();
            TraditionalBowlingScoreCalculatorValidator traditionalBowlingScoreCalculatorValidator =
                new TraditionalBowlingScoreCalculatorValidator(traditionalBowlingScoringCalculator);

            int[][] rawTestData =
            {
                new int[] { 1, 2 },
                new int[] { 6, 3 },
                new int[] { 4, 6 }
            };
            TraditionalBowlingScoreCalculatorValidator.TestGameDataDto testDataDto =
                new TraditionalBowlingScoreCalculatorValidator.TestGameDataDto
            {
                points = rawTestData
            };

            // act
            IList <BowlingFrame> bowlingFrames =
                traditionalBowlingScoreCalculatorValidator.ConvertTestDataToBowlingFrames(testDataDto);

            // assert
            Assert.AreEqual(bowlingFrames.Count, 3);
            Assert.AreEqual(bowlingFrames[0].Points.Length, 2);
            Assert.AreEqual(bowlingFrames[0].Points[0], 1);
            Assert.AreEqual(bowlingFrames[2].Points[1], 6);
        }
        public void TestCanGetBowlingTestDataFromRestApi()
        {
            // arrange
            TraditionalBowlingScoringCalculator traditionalBowlingScoringCalculator =
                new TraditionalBowlingScoringCalculator();
            TraditionalBowlingScoreCalculatorValidator traditionalBowlingScoreCalculatorValidator =
                new TraditionalBowlingScoreCalculatorValidator(traditionalBowlingScoringCalculator);

            // act
            string          retrievedApiToken;
            TestGameDataDto testData = traditionalBowlingScoreCalculatorValidator.GetPlayedTestFramesFromRestApi(out retrievedApiToken);

            // assert
            Assert.IsTrue(testData.points.Length > 0);
            Assert.IsNotNull(retrievedApiToken);
        }
        public void TestCanValidateBowlingScoreRules()
        {
            // arrange
            TraditionalBowlingScoringCalculator traditionalBowlingScoringCalculator =
                new TraditionalBowlingScoringCalculator();
            TraditionalBowlingScoreCalculatorValidator traditionalBowlingScoreCalculatorValidator =
                new TraditionalBowlingScoreCalculatorValidator(traditionalBowlingScoringCalculator);

            // act
            BowlingScoreValidatorResultEnum bowlingScoreValidatorResult = traditionalBowlingScoreCalculatorValidator.ValidateBowlingScoreRules();

            // assert
            if (bowlingScoreValidatorResult == BowlingScoreValidatorResultEnum.ScoreCalculatorValidationServiceInaccesible)
            {
                Assert.Inconclusive("The REST service that's used to validate the bowlingscore-rules is currently unavailable");
            }
            else
            {
                Assert.AreEqual(bowlingScoreValidatorResult, BowlingScoreValidatorResultEnum.ScoreCalculatorWorksFine);
            }
        }
예제 #6
0
        private static void Main(string[] args)
        {
            Console.WriteLine(@"GREETINGS PROFESSOR FALKEN.");
            Console.WriteLine(@"SHALL WE PLAY A GAME?");
            Console.WriteLine(@"SIMULATING INDIVIDUAL GAMES OF BOWLING.");

            TraditionalBowlingScoringCalculator        traditionalBowlingScoreCalculator = new TraditionalBowlingScoringCalculator();
            TraditionalBowlingScoreCalculatorValidator bowlingScoreValidator             = new TraditionalBowlingScoreCalculatorValidator(traditionalBowlingScoreCalculator);

            for (int i = 1; i <= 10; i++)
            {
                try
                {
                    BowlingScoreValidatorResultEnum calculatedScoresValidateCorrectly = bowlingScoreValidator.ValidateBowlingScoreRules();
                    switch (calculatedScoresValidateCorrectly)
                    {
                    case BowlingScoreValidatorResultEnum.ScoreCalculatorWorksFine:
                        Console.WriteLine($"Game {i} was scored and validated correctly.");
                        break;

                    case BowlingScoreValidatorResultEnum.ScoreCalculatorWorksNotSoMuch:
                        Console.WriteLine($"Could not validate scores for Game {i}.");
                        break;

                    case BowlingScoreValidatorResultEnum.ScoreCalculatorValidationServiceInaccesible:
                        Console.WriteLine($"Could not validate scores for Game {i} - validation-service could not be reached.");
                        break;
                    }

                    System.Threading.Thread.Sleep(5000);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Could not validate scores for Game {i} - some error '{ex.Message}' got in the way.");
                }
            }

            Console.WriteLine("PRESS ANY KEY TO EXIT.");
            Console.ReadKey();
        }