Esempio n. 1
0
 public void ScoreWithoutStrickesAndSpares()
 {
     var game = new Game();
     for (int i = 0; i < 20; i++)
     {
         game.Roll(4);
     }
     Assert.AreEqual(80, game.Score());
 }
Esempio n. 2
0
 public void NoScore()
 {
     var game = new Game();
     for (int i = 0; i < 20; i++)
     {
         game.Roll(0);
     }
     Assert.AreEqual(0, game.Score());
 }
Esempio n. 3
0
 public void ScoreWithSpare()
 {
     var game = new Game();
     for (int i = 0; i < 10; i++)
     {
         game.Roll(2);
     }
     game.Roll(1);
     game.Roll(9);
     for (int i = 12; i < 20; i++)
     {
         game.Roll(2);
     }
     Assert.AreEqual(48, game.Score());
 }
Esempio n. 4
0
 public void The_Score_Of_Game_With_No_Spares_And_Strikes_Is_The_Sum_OF_Rols()
 {
     var game = new Game();
     game.AddFrame(new Frame()
                       {
                           FirstRoll = 1,
                           SecondRoll = 2
                       });
      game.AddFrame(new Frame()
                       {
                           FirstRoll = 2,
                           SecondRoll = 3
                       });
     var bowling = new BowlingScoreCalculator();
     var score = bowling.GetScore(game);
     Assert.AreEqual(8, score);
 }
Esempio n. 5
0
 public void ScoreWithMultipleNotConsecutiveSpares()
 {
     var game = new Game();
     game.Roll(1);
     game.Roll(9);
     for (int i = 2; i < 10; i++)
     {
         game.Roll(2);
     }
     game.Roll(1);
     game.Roll(9);
     for (int i = 12; i < 20; i++)
     {
         game.Roll(2);
     }
     Assert.AreEqual(56, game.Score());
 }
        public int GetScore(Game game)
        {
            var frames = game.Frames;

            int result = 0;
            bool lastWasStrike = false;
            int nextRolsToAdd = 0;

            foreach (var frame in frames)
            {
                result += AddFrameRolls(frame);
                switch (nextRolsToAdd)
                {
                    case 1:
                        result += frame.FirstRoll;
                        nextRolsToAdd = 0;
                        break;
                    case 2:
                        result += frame.FirstRoll;
                        if (frame.SecondRoll > 0)
                        {
                            result += frame.SecondRoll;
                            nextRolsToAdd = 0;

                        }
                        else // second role in next frame
                        {
                            nextRolsToAdd = 1;
                        }
                        break;
                }

                lastWasStrike = frame.FirstRoll == 10;
                if (frame.FirstRoll==10)
                {
                    nextRolsToAdd += 2;
                }
            }
            return result;
        }
Esempio n. 7
0
 public void When_First_Frame_Was_Strike_And_Second_Wasnt_Then_Third_Frame_Is_Counted_Only_Once()
 {
     var game = new Game();
     game.AddFrame(new Frame()
     {
         FirstRoll = 10,
         SecondRoll = 0
     });
     game.AddFrame(new Frame()
     {
         FirstRoll = 3,
         SecondRoll = 5
     });
     game.AddFrame(new Frame()
     {
         FirstRoll = 1,
         SecondRoll = 0
     });
     var bowling = new BowlingScoreCalculator();
     var score = bowling.GetScore(game);
     Assert.AreEqual(27, score);
 }
Esempio n. 8
0
 public void When_First_Roll_Of_First_Frame_Equals_10_Then_The_Score_Of_The_Second_Frame_is_added_Twice()
 {
     var game = new Game();
     game.AddFrame(new Frame()
     {
         FirstRoll = 10,
         SecondRoll = 0
     });
     game.AddFrame(new Frame()
     {
         FirstRoll = 2,
         SecondRoll = 3
     });
     var bowling = new BowlingScoreCalculator();
     var score = bowling.GetScore(game);
     Assert.AreEqual(20, score);
 }
Esempio n. 9
0
 public void When_Two_Frames_In_Row_Are_Strike_Then_Third_Frame_Is_Counted_For_Second_Frame()
 {
     var game = new Game();
     game.AddFrame(new Frame() // == 10+10+1 (?)
     {
         FirstRoll = 10,
         SecondRoll = 0
     });
     game.AddFrame(new Frame() // == 10 + 1+1
     {
         FirstRoll = 10,
         SecondRoll = 0
     });
     game.AddFrame(new Frame() // == 1+1
     {
         FirstRoll = 1,
         SecondRoll = 1
     });
     var bowling = new BowlingScoreCalculator();
     var score = bowling.GetScore(game);
     Assert.AreEqual(35, score);
 }
Esempio n. 10
0
        public void ScoreWithStrike()
        {
            var game = new Game();

            for (int i = 0; i < 10; i++)
            {
                game.Roll(2);
            }

            game.Roll(10);

            for (int i = 11; i < 19; i++)
            {
                game.Roll(2);
            }
            Assert.AreEqual(50, game.Score());
        }
Esempio n. 11
0
        public void ScoreWithTwoConsecutiveStrikes()
        {
            var game = new Game();

            for (int i = 0; i < 10; i++)
            {
                game.Roll(2);
            }

            game.Roll(10);
            game.Roll(10);

            for (int i = 12; i < 18; i++)
            {
                game.Roll(2);
            }
            Assert.AreEqual(66, game.Score());
        }