From 6e97d3b686b2b0ef65757b483db64cb3e6a26359 Mon Sep 17 00:00:00 2001 From: Singh Date: Sun, 28 Jul 2019 10:07:27 +0530 Subject: [PATCH] Made necessary changes in assignment --- BowlingBall.Tests/GameFixture.cs | 47 ++++++++++++++++++++++++-- bowling-ball/Score.cs | 58 ++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 bowling-ball/Score.cs diff --git a/BowlingBall.Tests/GameFixture.cs b/BowlingBall.Tests/GameFixture.cs index ac8daf9..d1b86d6 100644 --- a/BowlingBall.Tests/GameFixture.cs +++ b/BowlingBall.Tests/GameFixture.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Xunit; namespace BowlingBall.Tests @@ -6,9 +7,51 @@ namespace BowlingBall.Tests public class GameFixture { [Fact] - public void DummyTest() + public void Score_when_NeitherSpareNorStrike_ocurs_() { - // This is a dummy test that will always pass. + //Given + List Frame = new List() { 7, 2 }; + var _Score = new Score(Frame); + //when + var TotalScore = _Score.GetTotalScore(7); + //then + Assert.Equal(9, TotalScore); } + + [Fact] + public void Score_when_Spare_ocurs_() + { + //Given + List Frame = new List() { 9, 1, 5 }; + var _Score = new Score(Frame); + //when + var TotalScore = _Score.GetTotalScore(9); + //then + Assert.Equal(15, TotalScore); + } + [Fact] + public void Score_when_RepeatedStrike_ocurs() + { + //Given + List Frame = new List() { 10, 10,10}; + var _Score = new Score(Frame); + //when + var TotalScore = _Score.GetTotalScore(10); + //then + Assert.Equal(30, TotalScore); + } + + [Fact] + public void Score_when_Strike_ocurs() + { + //Given + List Frame = new List() {10,9,1,5,5}; + var _Score = new Score(Frame); + //when + var TotalScore=_Score.GetTotalScore(10); + //then + Assert.Equal(20,TotalScore); + } + } } diff --git a/bowling-ball/Score.cs b/bowling-ball/Score.cs new file mode 100644 index 0000000..03006b6 --- /dev/null +++ b/bowling-ball/Score.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace BowlingBall +{ + public class Score + { + + + int Total = 0; + private List Frame; + + public Score(List Frame) + { + this.Frame = Frame; + } + + public int GetTotalScore(int PinsFalled) + { + for(int i=Frame.IndexOf(PinsFalled);i