Exemple #1
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);
        }
Exemple #2
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);
            });
        }
Exemple #3
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);
            });
        }
Exemple #4
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);
        }
Exemple #5
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);
        }
Exemple #6
0
        /// <summary>
        /// If args contains only filename, use default options.
        /// </summary>
        /// <param name="scores">Collection of BowlingScore</param>
        protected void SimpleScoreCounterBranch(ref ICollection <BowlingScore> scores)
        {
            IBowling bowling = new SimpleBowling();

            CountFinalScore(ref bowling, ref scores);

            IOutput output = new HTMLOutput();

            CreateOutput(ref output, GetDefaultFilename(ref output), ref scores);
        }
Exemple #7
0
        /// <summary>
        /// Set custom or default Bowling
        /// </summary>
        /// <param name="bowling">Bowling</param>
        protected void TypeBowlingBranch(out IBowling bowling)
        {
            string arg;

            if ((arg = ArgsContainsFlag(Constants.BOWLING_TYPE_COMMAND_FULL_FLAG, Constants.BOWLING_TYPE_COMMAND_SHORT_FLAG)) != null)
            {
                try
                {
                    command = factory.CreateCommand(Constants.BOWLING_TYPE_COMMAND_FULL_FLAG);
                    command.SetData(arg);
                    command.Execute();

                    bowling = ((BowlingTypeCommand)command).Bowling;
                }catch (Exception ex)
                {
                    ExecuteErrorCommand("Can not found type of bowling.", "Use simple type.");
                    bowling = new SimpleBowling();
                }
            }
            else
            {
                bowling = new SimpleBowling();
            }
        }