Ejemplo n.º 1
0
        public void Simulate_FullGame_1_Test()
        {
            ScoreCard scoreCard = Game.GenerteEmptyScoreCards();

            // run as long as the game runs
            while (Game.IsEligibleForAnotherTry(scoreCard))
            {
                Tuple <int, int> tries = GenerateFrame(scoreCard);

                scoreCard = Game.RollNewFrame(scoreCard, tries.Item1, tries.Item2);
            }

            Trace.WriteLine($"score is {Game.GetScore(scoreCard)}");

            if (scoreCard.Length < BowlingGameExtenstions.NUM_OF_REGULAR_ROUNDS)
            {
                throw new IllegalBowlingActionException("invalid number of rounds");
            }

            bool isGameHasExtraRound = ((scoreCard.Length == BowlingGameExtenstions.NUM_OF_REGULAR_ROUNDS + BowlingGameExtenstions.EXTRA_ROUNDS));

            if (isGameHasExtraRound &&
                (scoreCard.GetFrameType(BowlingGameExtenstions.NUM_OF_REGULAR_ROUNDS - 1) == FrameTypeEnum.Normal ||
                 scoreCard.GetFrameType(BowlingGameExtenstions.NUM_OF_REGULAR_ROUNDS - 1) == FrameTypeEnum.Empty))
            {
                throw new IllegalBowlingActionException("Had an extra round but the last round was not Strike or Spare");
            }

            if (!isGameHasExtraRound)
            {
                Assert.IsTrue(scoreCard.Length == BowlingGameExtenstions.NUM_OF_REGULAR_ROUNDS);
            }
        }
Ejemplo n.º 2
0
        public void Simulate_FullGame_3_Test()
        {
            ScoreCard scoreCard = ScoreCard.GenerteEmptyScoreCards();

            // Run for 9 rounds, but leave the last round for a fixed input.
            for (int i = 0; i < BowlingGameExtenstions.NUM_OF_REGULAR_ROUNDS - 1; i++)
            {
                Tuple <int, int> tries = GenerateFrame(scoreCard);

                scoreCard = Game.RollNewFrame(scoreCard, tries.Item1, tries.Item2);
            }

            // Add the last round
            scoreCard = Game.RollNewFrame(scoreCard, BowlingGameExtenstions.NUM_OF_PINS, 0);

            Trace.WriteLine($"score is {Game.GetScore(scoreCard)}");

            if ((scoreCard.Length == BowlingGameExtenstions.NUM_OF_REGULAR_ROUNDS) &&
                (scoreCard.GetFrameType(scoreCard.Length - 1) == FrameTypeEnum.Spare ||
                 scoreCard.GetFrameType(scoreCard.Length - 1) == FrameTypeEnum.Strike))
            {
                throw new IllegalBowlingActionException("Should have another extra round");
            }
        }