Beispiel #1
0
        static void Main(string[] args)
        {
            TestRoll[] testRolls =
            {
                new TestRoll("XXXXXXXXXXXX",                            300)
                ,                            new TestRoll("9-9-9-9-9-9-9-9-9-9-", 90)
                ,                            new TestRoll("5/5/5/5/5/5/5/5/5/5/5", 150)
            };


            BowlingCalculator calc = new BowlingCalculator();

            foreach (TestRoll testRoll in testRolls)
            {
                Line line = new Line(testRoll.Rolls);
                Console.WriteLine(string.Format("Test: {0}", testRoll.Rolls));
                Console.WriteLine(string.Format("Expected result: {0}", testRoll.Score));
                int calcScore1 = line.GetScore(testRoll.Rolls);
                int calcScore2 = calc.GetScore(testRoll.Rolls);
                Console.WriteLine(string.Format("Result Method 1: {0}", calcScore1));
                Console.WriteLine(string.Format("Test 1 Passed: {0}", testRoll.Test(calcScore1) ? "Yes" : "No"));
                Console.WriteLine(string.Format("Result Method 2: {0}", calcScore2));
                Console.WriteLine(string.Format("Test 2 Passed: {0}", testRoll.Test(calcScore2)?"Yes":"No"));
                Console.WriteLine("-------------");
            }

            Console.WriteLine("Test Ended. Press Enter to continue...");
            Console.Read();
        }
Beispiel #2
0
        public async Task Can_InVoke_Service()
        {
            var bowlingApi = new BowlingApiService(new ApiService());
            var calculator = new BowlingCalculator(new FrameLinker());

            var sut = new BowlingService(bowlingApi, calculator);

            var result = await sut.ValidateResults();

            Assert.IsTrue(result.Result);
        }
Beispiel #3
0
        public void Can_Calculate_Double_Strike()
        {
            IEnumerable <int[]> scores = new List <int[]>()
            {
                new[] { 10, 0 }, new[] { 10, 0 }, new[] { 4, 2 }
            };

            var calculator = new BowlingCalculator(new FrameLinker());

            var result = calculator.CalulatePoints(scores);

            var expected = new int[] { 24, 40, 46 };

            CollectionAssert.AreEqual(expected, result.ToList());
        }
Beispiel #4
0
        public void Can_Calculate_Correct_Scores()
        {
            IEnumerable <int[]> scores = new List <int[]>()
            {
                new[] { 3, 7 }, new[] { 10, 0 }, new[] { 8, 2 }, new[] { 8, 1 }, new[] { 10, 0 }, new[] { 3, 4 }, new[] { 7, 0 }, new[] { 5, 5 }, new[] { 3, 2 }, new[] { 2, 5 }
            };

            var calculator = new BowlingCalculator(new FrameLinker());

            var result = calculator.CalulatePoints(scores);

            var expected = new int[] { 20, 40, 58, 67, 84, 91, 98, 111, 116, 123 };

            CollectionAssert.AreEqual(expected, result.ToList());
        }
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Welcome to Bowling Score Calculator!");
                Console.WriteLine("Please insert your score below");

                var scoreInput = Console.ReadLine();

                var bowlingCalculator = new BowlingCalculator();
                var result            = bowlingCalculator.Calculate(scoreInput);

                Console.WriteLine($"Congratulations, your score final is {result}!");

                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadKey();
            }
        }
Beispiel #6
0
        public void CalculatorResultTest(string input, int result)
        {
            var bowlingCalculator = new BowlingCalculator();

            Assert.Equal(bowlingCalculator.Calculate(input), result);
        }