Exemplo n.º 1
0
 public void secondFrameIsNotAllowed()
 {
     Frame frame = new Frame(10,1);
     Frame secondFrame = new Frame(9);
     geometricBowling.AddFrame(frame);
     geometricBowling.AddFrame(secondFrame);
 }
Exemplo n.º 2
0
 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());
 }
Exemplo n.º 3
0
        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);
         }
     }
 }
Exemplo n.º 5
0
 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());
 }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 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);
        }
Exemplo n.º 9
0
 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());
 }
Exemplo n.º 10
0
 public void IfFirstFrameIsStrikeThenThereShouldBeAnotherRoll()
 {
     Frame frame = new Frame(10);
     geometricBowling.AddFrame(frame);
 }
Exemplo n.º 11
0
 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);
 }
Exemplo n.º 12
0
 public void FrameIsOverIfFirstIsStrikeAndTheSecondNotAndThereIsAnotherRoll()
 {
     Frame frame = new Frame(10, 9,1);
     geometricBowling.AddFrame(frame);
 }
Exemplo n.º 13
0
 public void SingleRollInFrameCannotExceedTenHits()
 {
     Frame frame = new Frame(11);
     terrestrialGame.AddFrame(frame);
 }
Exemplo n.º 14
0
 /// <exception cref="FormatException"></exception>
 public void AddFrame(Frame frame)
 {
     CheckConstraint(frame,frames.Count);
     frames.Add(frame);
 }
Exemplo n.º 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);
        }
Exemplo n.º 16
0
 public void WhileStrikeShoulDContinueNoException()
 {
     Frame frame = new Frame(10,10,10,10);
     geometricBowling.AddFrame(frame);
 }
Exemplo n.º 17
0
 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);
 }
Exemplo n.º 18
0
 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);
 }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 20
0
 public void ShouldAllowNStrikeAndALastFailure()
 {
     Frame frame = new Frame(10, 10, 10, 10,1);
     geometricBowling.AddFrame(frame);
 }
Exemplo n.º 21
0
 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());
 }
Exemplo n.º 22
0
        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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 24
0
 public void TestThereIsNoSecondRollInAStrike()
 {
     Frame frame = new Frame(10,0);
     terrestrialGame.AddFrame(frame);
 }
Exemplo n.º 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);
        }
Exemplo n.º 26
0
 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());
 }
Exemplo n.º 27
0
 public void FrameIsOverForNoTenAtFirstRoll()
 {
     Frame frame = new Frame(9,1);
     Assert.IsFalse(geoConstraint(frame));
 }
Exemplo n.º 28
0
 public void TestThereShouldbeASecondRollIfNotStrike()
 {
     Frame frame = new Frame(9);
     terrestrialGame.AddFrame(frame);
 }
Exemplo n.º 29
0
 public void FrameIsOverIfFirstIsNotSTrike()
 {
     Frame frame = new Frame(9);
     geometricBowling.AddFrame(frame);
     Assert.IsTrue(true);
 }
Exemplo n.º 30
0
 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());
 }