public void Calculate_CorrectlyWithSpareAndStrike()
        {
            var calculator = new ScoreCalculator();
            var scoreArray = new List <ScoreInfo>();

            var spare = new ScoreInfo(1);

            spare.AddScore(4);
            spare.AddScore(6);
            scoreArray.Add(spare);

            var strike = new ScoreInfo(2);

            strike.AddScore(10);
            scoreArray.Add(strike);

            var lastFrame = new ScoreInfo(3);

            lastFrame.AddScore(3);
            lastFrame.AddScore(2);
            scoreArray.Add(lastFrame);

            // 1 = 10 + 10
            // 2 = 10 + 3 + 2
            // 3 = 3 + 2

            var total = calculator.Calculate(scoreArray);

            Assert.True(total == 40);
        }
        public void Calculate_Returns145()
        {
            var calculator = new ScoreCalculator();
            var scoreArray = new List <ScoreInfo>();

            for (int i = 1; i < 10; i++)
            {
                var frame = new ScoreInfo(i);
                frame.AddScore(5);
                frame.AddScore(5);
                scoreArray.Add(frame);
            }

            // last frame
            var lastFrame = new ScoreInfo(10);

            lastFrame.AddScore(5);
            lastFrame.AddScore(5);
            lastFrame.AddScore(5);
            scoreArray.Add(lastFrame);

            var totalScore = calculator.Calculate(scoreArray);

            Assert.Equal(150, totalScore);
        }
        public void Calculate_CorrectlyWith1StrikeAnd1Spare()
        {
            var calculator = new ScoreCalculator();
            var scoreArray = new List <ScoreInfo>();

            var strike = new ScoreInfo(1);

            strike.AddScore(10);
            scoreArray.Add(strike);

            var spare = new ScoreInfo(2);

            spare.AddScore(4);
            spare.AddScore(6);
            scoreArray.Add(spare);

            var lastFrame = new ScoreInfo(3);

            lastFrame.AddScore(3);
            lastFrame.AddScore(2);
            scoreArray.Add(lastFrame);

            // 1 = 10 + 4 + 6 = 20
            // 2 = 4 + 6 + 3 = 13
            // 3 = 3 + 2 = 5

            var total = calculator.Calculate(scoreArray);

            Assert.Equal(38, total);
        }
        public void AddScore_SetsIsSpareToTrue_WhenFrame1Totals10In2Attempts()
        {
            var frame1 = new ScoreInfo(1);

            frame1.AddScore(5);
            frame1.AddScore(5);

            Assert.True(frame1.IsSpare);
        }
        public void AddScore_SetsIsSpareAndIsStrike_WhenFrame1TotalsLessThan10In2Attempts()
        {
            var frame1 = new ScoreInfo(1);

            frame1.AddScore(3);
            frame1.AddScore(4);

            Assert.False(frame1.IsSpare);
            Assert.False(frame1.IsStrike);
        }
        public void AddScore_ThrowsArgumentException_WhenAdding3ScoresToFrame1()
        {
            var calculator = new ScoreCalculator();
            var scoreArray = new List <ScoreInfo>();

            var frame = new ScoreInfo(1);

            frame.AddScore(4);
            frame.AddScore(6);

            Assert.Throws <ArgumentException>(() => frame.AddScore(1));
        }
        public void AddScore_SetsIsStrikeToTrue_WhenFrame1Totals10()
        {
            var frame1 = new ScoreInfo(1);

            frame1.AddScore(10);
            Assert.True(frame1.IsStrike);
        }
        public void AddScore_ThrowsArgumentException_WhenScoreIsGreaterThanTen()
        {
            var calculator = new ScoreCalculator();
            var scoreArray = new List <ScoreInfo>();

            var frame = new ScoreInfo();

            Assert.Throws <ArgumentException>(() => frame.AddScore(11));
        }
        public void Calculate_CorrectTotalScoreWhenIsSpare14()
        {
            var calculator = new ScoreCalculator();
            var scoreArray = new List <ScoreInfo>();

            for (int i = 1; i < 3; i++)
            {
                var frame = new ScoreInfo(i);
                frame.AddScore(4);
                frame.AddScore(6);
                scoreArray.Add(frame);
            }

            // 1 = 10 + 4
            // 2 = 10

            var total = calculator.Calculate(scoreArray);

            Assert.True(total == 24);
        }
        public void Calculate_CorrectTotalScoreWhenIsSpare()
        {
            var calculator = new ScoreCalculator();
            var scoreArray = new List <ScoreInfo>();

            var frame1 = new ScoreInfo(1);

            frame1.AddScore(9);
            frame1.AddScore(1);

            var frame2 = new ScoreInfo(2);

            frame2.AddScore(2);

            scoreArray.Add(frame1);
            scoreArray.Add(frame2);

            var total = calculator.Calculate(scoreArray);

            Assert.True(total == 14);
        }
        public void Calculate_Returns300_InPerfectGame()
        {
            var calculator = new ScoreCalculator();
            var scoreArray = new List <ScoreInfo>();

            for (int i = 1; i < 10; i++)
            {
                var frame = new ScoreInfo(i);
                frame.AddScore(10);
                scoreArray.Add(frame);
            }

            var lastframe = new ScoreInfo(10);

            lastframe.AddScore(10);
            lastframe.AddScore(10);
            lastframe.AddScore(10);
            scoreArray.Add(lastframe);

            var score = calculator.Calculate(scoreArray);

            Assert.Equal(300, score);
        }