public void secondFrameIsNotAllowed()
 {
     Frame frame = new Frame(10,1);
     Frame secondFrame = new Frame(9);
     geometricBowling.AddFrame(frame);
     geometricBowling.AddFrame(secondFrame);
 }
 public void tenthIsStrikeAndTheFollowingAlso()
 {
     Frame noPoints = new Frame(0,0);
     terrestrialGame.AddMany(noPoints,9);
     Frame Frame = new Frame(10,10,1);
     terrestrialGame.AddFrame(Frame);
     Assert.AreEqual(21, terrestrialGame.Score());
 }
        public void ALotOfFramesUntilLastNotStrike()
        {
            Frame frame = new Frame(10, 10, 10, 1);
            Frame furtherFrame = new Frame(9);
            geometricBowling.AddFrame(frame);
            geometricBowling.AddFrame(furtherFrame);
            geometricBowling.AddFrame(furtherFrame);

            geometricBowling.AddFrame(furtherFrame);
        }
 private void AddConstrains(int index, Frame frame, Dictionary<int, ConstraintAndDescription> indexConstraintForFrame)
 {
     if (index==0&&frame.Rolls.Count>1)
     {
         for (int i = 1; i < frame.Rolls.Count-1;i++)
         {
             indexConstraintForFrame.Add(i, _constToAdd);
         }
     }
 }
 public void BounsForAnyStrikeIsTheTotalOfLastFrame()
 {
     Frame frame = new Frame(10);
     Frame secondFrame = new Frame(1, 1, 1);
     Frame lastFrame = new Frame(2, 1, 1);
     martianGame.AddFrame(frame);
     martianGame.AddFrame(secondFrame);
     martianGame.AddFrame(lastFrame);
     Assert.AreEqual(10 + 3 + 4 + 4, martianGame.Score());
 }
 public void ShouldNotAcceptMoreFrameIfGameIsOver()
 {
     Frame frame = new Frame(10);
     Frame secondFrame = new Frame(1, 1, 1);
     Frame lastFrame = new Frame(2, 1, 1);
     Frame oneMoreFrame = new Frame(10);
     martianGame.AddFrame(frame);
     martianGame.AddFrame(secondFrame);
     martianGame.AddFrame(lastFrame);
     martianGame.AddFrame(oneMoreFrame);
 }
Beispiel #7
0
 public void Roll(int roll)
 {
     rollsNotInFrame.Add(roll);
     Frame newFrame = new Frame(rollsNotInFrame);
     try
     {
         this.AddFrame(newFrame);
         rollsNotInFrame=new List<int>();
     } catch (FormatException e)
     {
     }
 }
        public void CheckConstraint(Frame frame, int index, Dictionary<int, ConstraintAndDescription> indexConstraintForFrame)
        {
            AddConstrains(index, frame, indexConstraintForFrame);

            ConstraintAndDescription constrintAndDescription;
            if (indexConstraintForFrame.TryGetValue(index, out constrintAndDescription))
            {
                if (!constrintAndDescription.Matches(frame))
                {
                    throw new FormatException("violated constraint " + constrintAndDescription + " in frame " + frame.ToString());
                }
            }
            else
                throw new FormatException("rule error: there is no constraint for frame index " + index);
        }
 public void TestLastRollWithNoStrike()
 {
     Frame strike = new Frame(10);
     terrestrialGame.AddMany(strike,9);
     Frame lastStrike = new Frame(0);
     terrestrialGame.AddFrame(lastStrike);
     Assert.AreEqual(240, terrestrialGame.Score());
 }
 public void IfFirstFrameIsStrikeThenThereShouldBeAnotherRoll()
 {
     Frame frame = new Frame(10);
     geometricBowling.AddFrame(frame);
 }
 public bool geoConstraint(Frame frame)
 {
     if (frame.Rolls.Count == 1) {return frame.Rolls[0] != 10;}
     Frame innerFrame = new Frame(frame.Rolls.GetRange(1, frame.Rolls.Count - 1));
     return frame.Rolls[0]==10&&geoConstraint(innerFrame);
 }
 public void FrameIsOverIfFirstIsStrikeAndTheSecondNotAndThereIsAnotherRoll()
 {
     Frame frame = new Frame(10, 9,1);
     geometricBowling.AddFrame(frame);
 }
 public void SingleRollInFrameCannotExceedTenHits()
 {
     Frame frame = new Frame(11);
     terrestrialGame.AddFrame(frame);
 }
Beispiel #14
0
 /// <exception cref="FormatException"></exception>
 public void AddFrame(Frame frame)
 {
     CheckConstraint(frame,frames.Count);
     frames.Add(frame);
 }
Beispiel #15
0
        private int ComputeBonus(Frame[] frames, int i)
        {
            int toReturn = 0;

            List<DelBonusRuleForFrame> bonusRulesForFrames;
            if (this._indexBonusRuleForFrame.TryGetValue(i,out bonusRulesForFrames))
            {
                foreach(DelBonusRuleForFrame rule in bonusRulesForFrames)
                {
                    toReturn += rule.Invoke(frames, i);
                }
                return toReturn;
            }
            throw new FormatException("no bonus rules list for the index "+i);
        }
 public void WhileStrikeShoulDContinueNoException()
 {
     Frame frame = new Frame(10,10,10,10);
     geometricBowling.AddFrame(frame);
 }
 public void UntilStrikeExpectAnotherRoll()
 {
     Frame frame = new Frame(10,1);
     Frame further = new Frame(1);
     geometricBowling.AddFrame(frame);
     geometricBowling.AddFrame(further);
     geometricBowling.AddFrame(further);
     geometricBowling.AddFrame(further);
     geometricBowling.AddFrame(further);
 }
 public void TheLenOftheFirstFrameMinusOneIsTheTotalNumberOfAllowedFrames()
 {
     Frame frame = new Frame(10,10,10,1);
     Frame furtherFrame = new Frame(9);
     geometricBowling.AddFrame(frame);
     geometricBowling.AddFrame(furtherFrame);
     geometricBowling.AddFrame(furtherFrame);
 }
        public void ShouldNotAllowMoreFramesThanTheStrikesInTheFirstFrame()
        {
            Random random = new Random(DateTime.Now.Millisecond);
            int strikes = random.Next(0, 13);

            List<int> rolls = new List<int> { 10 };
            rolls.AddMany(10,strikes);
            rolls.Add(1);

            Frame firstFrame = new Frame(rolls);
            geometricBowling.AddFrame(firstFrame);
            Frame following = new Frame(0);
            geometricBowling.AddMany(following,strikes);

            // one more. too much, exception raises
            geometricBowling.AddFrame(following);
        }
 public void ShouldAllowNStrikeAndALastFailure()
 {
     Frame frame = new Frame(10, 10, 10, 10,1);
     geometricBowling.AddFrame(frame);
 }
 public void testPerfectStrike()
 {
     Frame strike = new Frame(10);
     terrestrialGame.AddMany(strike,9);
     Frame lastStrike = new Frame(10,10,10);
     terrestrialGame.AddFrame(lastStrike);
     Assert.AreEqual(300, terrestrialGame.Score());
 }
        public void ShouldAllowAsMuchFramesAsTheStrikesInTheFirstFrame()
        {
            Random random = new Random(DateTime.Now.Millisecond);
            int strikes = random.Next(0, 13);

            List<int> rolls = new List<int>{10};
            rolls.AddMany(10,strikes);
            rolls.Add(1);

            Frame firstFrame = new Frame(rolls);
            geometricBowling.AddFrame(firstFrame);
            Frame following = new Frame(0);
            geometricBowling.AddMany(following, strikes);

            Assert.IsTrue(true);
        }
Beispiel #23
0
        /// <exception cref="FormatException"></exception>
        private void CheckConstraint(Frame frame, int index)
        {
            this._constraintChecker.CheckConstraint(frame,index,indexConstraintForFrame);

            //
            //            ConstraintAndDescription constrintAndDescription;
            //            if (indexConstraintForFrame.TryGetValue(index,out constrintAndDescription))
            //            {
            //                if (!constrintAndDescription.Matches(frame))
            //                {
            //                    throw new FormatException("violated constraint " + constrintAndDescription + " in frame " + frame.ToString());
            //                }
            //            }
            //            else
            //                throw new FormatException("rule error: there is no constraint for frame index "+index);
        }
 public void TestThereIsNoSecondRollInAStrike()
 {
     Frame frame = new Frame(10,0);
     terrestrialGame.AddFrame(frame);
 }
Beispiel #25
0
        private int ComputeScore(Frame[] frames, int i)
        {
            int toReturn = 0;

            DelScoreRuleForFrame scoreScoreRuleForFrame;
            if (this.delBasedRuleForFrame.TryGetValue(i,out scoreScoreRuleForFrame))
            {
                return scoreScoreRuleForFrame.Invoke(frames[i]);
            }

            throw new FormatException("no score rule associated to frame index " + i);
        }
 public void testStrikeAllAndLast1()
 {
     Frame strike = new Frame(10);
     terrestrialGame.AddMany(strike,9);
     Frame lastStrike = new Frame(10,10,1);
     terrestrialGame.AddFrame(lastStrike);
     Assert.AreEqual(291, terrestrialGame.Score());
 }
 public void FrameIsOverForNoTenAtFirstRoll()
 {
     Frame frame = new Frame(9,1);
     Assert.IsFalse(geoConstraint(frame));
 }
 public void TestThereShouldbeASecondRollIfNotStrike()
 {
     Frame frame = new Frame(9);
     terrestrialGame.AddFrame(frame);
 }
 public void FrameIsOverIfFirstIsNotSTrike()
 {
     Frame frame = new Frame(9);
     geometricBowling.AddFrame(frame);
     Assert.IsTrue(true);
 }
 public void TestPlaingGameNoSpareOrStrikes()
 {
     Frame frame = new Frame(1,1);
     terrestrialGame.AddMany(frame,9);
     Frame Frame = new Frame(1);
     terrestrialGame.AddFrame(Frame);
     Assert.AreEqual(19, terrestrialGame.Score());
 }