コード例 #1
0
        public void TestNoFrames()
        {
            BowlingFrames bowlingFrames = new BowlingFrames(new List <BowlingFrame>());
            var           br            = new BowlingRepository(bowlingFrames);

            Assert.AreEqual(0, br.CountScore().Score, "Test No Frames");
        }
コード例 #2
0
        public void StrikeFrameCreation()
        {
            var roll1 = new Roll(10);

            IBowlingFrame frame = BowlingFrames.From(new Roll[] { roll1 });

            Assert.IsType <StrikeFrame>(frame);
        }
コード例 #3
0
        public void OpenFrameCreation()
        {
            var roll1 = new Roll(4);
            var roll2 = new Roll(2);

            IBowlingFrame frame = BowlingFrames.From(new Roll[] { roll1, roll2 });

            Assert.IsType <OpenFrame>(frame);
        }
コード例 #4
0
        public void LastFrameCreationWith_TwoRolls()
        {
            var roll1 = new Roll(1);
            var roll2 = new Roll(1);

            IBowlingFrame frame = BowlingFrames.From(new Roll[] { roll1, roll2 }, 10);

            Assert.IsType <LastFrame>(frame);
        }
コード例 #5
0
        public void SpareFrameCreation()
        {
            var roll1 = new Roll(5);
            var roll2 = new Roll(5);

            IBowlingFrame frame = BowlingFrames.From(new Roll[] { roll1, roll2 });

            Assert.IsType <SpareFrame>(frame);
        }
コード例 #6
0
        public void TestSpareFrame()
        {
            List <BowlingFrame> list = new List <BowlingFrame>();

            list.Add(new BowlingFrame(6, 4));
            BowlingFrames bowlingFrames = new BowlingFrames(list);
            var           br            = new BowlingRepository(bowlingFrames);

            Assert.AreEqual(10, br.CountScore().Score, "Test Spare Frame");
        }
コード例 #7
0
        public void TestTwoSparesInARow()
        {
            List <BowlingFrame> list = new List <BowlingFrame>();

            list.Add(new BowlingFrame(6, 4));
            list.Add(new BowlingFrame(5, 5));
            BowlingFrames bowlingFrames = new BowlingFrames(list);
            var           br            = new BowlingRepository(bowlingFrames);

            Assert.AreEqual(25, br.CountScore().Score, "Test Two Spares in a row");
        }
コード例 #8
0
        public void TestSpareFrameWithFollowingFrame()
        {
            List <BowlingFrame> list = new List <BowlingFrame>();

            list.Add(new BowlingFrame(6, 4));
            list.Add(new BowlingFrame(5, 3));
            BowlingFrames bowlingFrames = new BowlingFrames(list);
            var           br            = new BowlingRepository(bowlingFrames);

            Assert.AreEqual(23, br.CountScore().Score, "Test Spare Frame with a frame that follows");
        }
コード例 #9
0
        public void TestTenFrame()
        {
            List <BowlingFrame> list = new List <BowlingFrame>()
            {
                new BowlingFrame(1, 1), new BowlingFrame(1, 1), new BowlingFrame(1, 1), new BowlingFrame(1, 1), new BowlingFrame(1, 1), new BowlingFrame(1, 1), new BowlingFrame(1, 1), new BowlingFrame(1, 1), new BowlingFrame(1, 1), new BowlingFrame(1, 1)
            };
            BowlingFrames bowlingFrames = new BowlingFrames(list);
            var           br            = new BowlingRepository(bowlingFrames);

            Assert.AreEqual(20, br.CountScore().Score, "Test Ten Frames");
        }
コード例 #10
0
        public void TestZeroFrame()
        {
            List <BowlingFrame> list = new List <BowlingFrame>()
            {
                new BowlingFrame(0, 0)
            };
            BowlingFrames bowlingFrames = new BowlingFrames(list);
            var           br            = new BowlingRepository(bowlingFrames);

            Assert.AreEqual(0, br.CountScore().Score, "Test Zero-Frame");
        }
コード例 #11
0
        public void TestStrikeFrameWithFollowingFrame()
        {
            List <BowlingFrame> list = new List <BowlingFrame>();

            list.Add(new BowlingFrame(10, 0));
            list.Add(new BowlingFrame(5, 3));
            BowlingFrames bowlingFrames = new BowlingFrames(list);
            var           br            = new BowlingRepository(bowlingFrames);

            Assert.AreEqual(26, br.CountScore().Score, "Test Strike Frame with a regular following frame");
        }
コード例 #12
0
        public void TestThreeStrikesInARow()
        {
            List <BowlingFrame> list = new List <BowlingFrame>();

            list.Add(new BowlingFrame(10, 0));
            list.Add(new BowlingFrame(10, 0));
            list.Add(new BowlingFrame(10, 0));
            BowlingFrames bowlingFrames = new BowlingFrames(list);
            var           br            = new BowlingRepository(bowlingFrames);

            Assert.AreEqual(60, br.CountScore().Score, "Test three strikes in a row");
        }
コード例 #13
0
        public void TestPerfectGame()
        {
            List <BowlingFrame> list = new List <BowlingFrame>();

            list.Add(new BowlingFrame(10, 0));
            list.Add(new BowlingFrame(10, 0));
            list.Add(new BowlingFrame(10, 0));
            list.Add(new BowlingFrame(10, 0));
            list.Add(new BowlingFrame(10, 0));
            list.Add(new BowlingFrame(10, 0));
            list.Add(new BowlingFrame(10, 0));
            list.Add(new BowlingFrame(10, 0));
            list.Add(new BowlingFrame(10, 0));
            list.Add(new BowlingFrame(10, 10));
            BowlingFrames bowlingFrames = new BowlingFrames(list);
            var           br            = new BowlingRepository(bowlingFrames);

            Assert.AreEqual(300, br.CountScore().Score, "Test Perfect Game");
        }
コード例 #14
0
 public BowlingRepository(BowlingFrames bowlingFrames)
 {
     framesList = bowlingFrames.Frames;
     rollList   = new List <int>();
     foreach (var frame in framesList)
     {
         rollList.Add(frame.First);
         rollList.Add(frame.Second);
         if (frame.Third != 0)
         {
             rollList.Add(frame.Third);
         }
     }
     if (framesList.Count < 10)
     {
         for (var i = framesList.Count; i < 10; i++)
         {
             rollList.Add(0);
             rollList.Add(0);
             framesList.Add(new BowlingFrame(0, 0));
         }
     }
 }
コード例 #15
0
        public IHttpActionResult Post(BowlingFrames frames)
        {
            BowlingRepository br = new BowlingRepository(frames);

            return(Ok(br.CountScore()));
        }