示例#1
0
        public void BadDataShouldThrowException()
        {
            var points = new int[] {
                1, 9,  // Round 1
                -1, 9, // Round 2 <- -1 in this place is bad data
                1, 9,  // Round 3
                1, 9,  // Round 4
                1, 9,  // Round 5
                1, 9,  // Round 6
                1, 9,  // Round 7
                1, 9,  // Round 8
                1, 9,  // Round 9
                1, 9,  // Round 10
                9,     // Addiontal throw
                -1     // No additional throw
            };

            BowlingScore score = new BowlingScore(name, points);

            IBowling bowling = new SimpleBowling();

            Assert.ThrowsException <ArgumentOutOfRangeException>(() =>
            {
                bowling.CountScore(ref score);
            });
        }
示例#2
0
        public void OnlySpareBonusScore()
        {
            var points = new int[] {
                1, 9, // Round 1
                1, 9, // Round 2
                1, 9, // Round 3
                1, 9, // Round 4
                1, 9, // Round 5
                1, 9, // Round 6
                1, 9, // Round 7
                1, 9, // Round 8
                1, 9, // Round 9
                1, 9, // Round 10
                9,    // Addiontal throw
                -1    // No additional throw
            };


            BowlingScore score = new BowlingScore(name, points);

            IBowling bowling = new SimpleBowling();

            bowling.CountScore(ref score);

            int finalScore = score.Score;

            Assert.AreEqual(118, finalScore);
        }
示例#3
0
        public void PerfectGameScore()
        {
            var points = new int[] {
                10,                                     // Round 1
                10,                                     // Round 2
                10,                                     // Round 3
                10,                                     // Round 4
                10,                                     // Round 5
                10,                                     // Round 6
                10,                                     // Round 7
                10,                                     // Round 8
                10,                                     // Round 9
                10,                                     // Round 10
                10, 10,                                 // Addiontal throws
                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // No additional throws
            };

            BowlingScore score = new BowlingScore(name, points);

            IBowling bowling = new SimpleBowling();

            bowling.CountScore(ref score);

            int finalScore = score.Score;

            Assert.AreEqual(300, finalScore);
        }
示例#4
0
        public void TooManyKnockDownedThePinsInOneRound()
        {
            var points = new int[] {
                1, 9, // Round 1
                9, 9, // Round 2 <- 18 the pins knock downed in one round
                1, 9, // Round 3
                1, 9, // Round 4
                1, 9, // Round 5
                1, 9, // Round 6
                1, 9, // Round 7
                1, 9, // Round 8
                1, 9, // Round 9
                1, 9, // Round 10
                9,    // Addiontal throw
                -1    // No additional throw
            };

            BowlingScore score = new BowlingScore(name, points);

            IBowling bowling = new SimpleBowling();

            Assert.ThrowsException <ArgumentOutOfRangeException>(() =>
            {
                bowling.CountScore(ref score);
            });
        }
示例#5
0
        public void OneStrikeBonusScore()
        {
            var points = new int[] {
                10,        // Round 1
                3, 5,      // Round 2
                7, 1,      // Round 3
                1, 1,      // Round 4
                2, 5,      // Round 5
                9, 0,      // Round 6
                2, 3,      // Round 7
                4, 4,      // Round 8
                3, 6,      // Round 9
                1, 4,      // Round 10
                -1, -1, -1 // No additional throws
            };


            BowlingScore score = new BowlingScore(name, points);

            IBowling bowling = new SimpleBowling();

            bowling.CountScore(ref score);

            int finalScore = score.Score;

            Assert.AreEqual(79, finalScore);
        }
        public void Strike()
        {
            var score = new BowlingScore();

            score.Roll(10);
            score.Roll(3);
            score.Roll(3);

            Assert.AreEqual(22, score.GetScore());
        }
        public void ResetScore()
        {
            var score = new BowlingScore();

            score.Roll(3);
            score.Roll(3);
            score.GetScore();

            Assert.AreEqual(6, score.GetScore());
        }
        public void Spares()
        {
            var score = new BowlingScore();

            score.Roll(4);
            score.Roll(6);
            score.Roll(3);

            Assert.AreEqual(16, score.GetScore());
        }
        public void LastStrike()
        {
            var score = new BowlingScore();

            for (int i = 0; i < 12; i++)
            {
                score.Roll(10);
            }

            Assert.AreEqual(300, score.GetScore());
        }
示例#10
0
        public void AllTwos()
        {
            var score = new BowlingScore();

            for (var i = 0; i < 20; i++)
            {
                score.Roll(2);
            }

            Assert.AreEqual(40, score.GetScore());
        }
示例#11
0
        public void ZeroScore()
        {
            var score = new BowlingScore();

            for (var i = 0; i < 20; i++)
            {
                score.Roll(0);
            }

            Assert.AreEqual(0, score.GetScore());
        }
示例#12
0
 /// <summary>
 /// Count final score for every one BowlingScore in collection
 /// </summary>
 /// <param name="bowling">Bowling</param>
 /// <param name="scores">Collection of BowlingScore</param>
 protected void CountFinalScore(ref IBowling bowling, ref ICollection <BowlingScore> scores)
 {
     try
     {
         var it = scores.GetEnumerator();
         it.MoveNext();
         while (it.Current != null)
         {
             BowlingScore score = it.Current;
             bowling.CountScore(ref score);
             it.MoveNext();
         }
     }
     catch (Exception ex)
     {
         ExecuteErrorCommand("Can not count final score. Please check file");
         ExitFailed();
     }
 }
示例#13
0
        /// <summary>
        /// Generate BowlingScore without any bonus.
        /// </summary>
        /// <returns>New instance of BowlingScore</returns>
        private BowlingScore GetBowlingScore()
        {
            var names = new string[] { "Pyoneru", "Peter", "Batman", "Cezary" };

            var points = new int[22];

            var rnd = new Random();

            for (int i = 0; i < 20; i++)
            {
                points[i] = rnd.Next(5); // generate numbers lower then 5(no bonus)
            }
            // Last two fields are empty.
            points[20] = -1;
            points[21] = -1;

            var score = new BowlingScore(names[rnd.Next(4)], points);

            score.Score = rnd.Next(50, 250);

            return(score);
        }
 public void Teardown()
 {
     this._score = null;
     this._game  = null;
 }
 public void Setup()
 {
     this._game  = new BowlingGame();
     this._score = new BowlingScore();
 }
示例#16
0
        public void Score_Test_5_Five_Pin()
        {
            var input = "---|X|X|X|X|X|X|X|X|XXX";

            Assert.AreEqual(405, BowlingScore.ScoreGame(input, BowlingScores.Games.GamesEnum.FivePin));
        }
示例#17
0
        public void Score_Test_4()
        {
            var input = "X|7/|9-|X|-8|8/|-6|X|X|X||81";

            Assert.AreEqual(167, BowlingScore.ScoreGame(input, BowlingScores.Games.GamesEnum.TenPin));
        }
示例#18
0
        public void Score_Test_3()
        {
            var input = "5/|5/|5/|5/|5/|5/|5/|5/|5/|5/||5";

            Assert.AreEqual(150, BowlingScore.ScoreGame(input, BowlingScores.Games.GamesEnum.TenPin));
        }
示例#19
0
        public void Score_Test_2()
        {
            var input = "9-|9-|9-|9-|9-|9-|9-|9-|9-|9-||";

            Assert.AreEqual(90, BowlingScore.ScoreGame(input, BowlingScores.Games.GamesEnum.TenPin));
        }
示例#20
0
        public void Score_Test_1()
        {
            var input = "X|X|X|X|X|X|X|X|X|X||XX";

            Assert.AreEqual(300, BowlingScore.ScoreGame(input));
        }