Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made necessary changes in assignment #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions BowlingBall.Tests/GameFixture.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,57 @@
using System;
using System.Collections.Generic;
using Xunit;

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<int> Frame = new List<int>() { 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<int> Frame = new List<int>() { 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<int> Frame = new List<int>() { 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<int> Frame = new List<int>() {10,9,1,5,5};
var _Score = new Score(Frame);
//when
var TotalScore=_Score.GetTotalScore(10);
//then
Assert.Equal(20,TotalScore);
}

}
}
58 changes: 58 additions & 0 deletions bowling-ball/Score.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace BowlingBall
{
public class Score
{


int Total = 0;
private List<int> Frame;

public Score(List<int> Frame)
{
this.Frame = Frame;
}

public int GetTotalScore(int PinsFalled)
{
for(int i=Frame.IndexOf(PinsFalled);i<i+1;i++)
{
//for strike
//..........
if(Frame[i]==10 &&Frame[i+1]==10 && Frame[i+2]==10)
{
Total += 30;
break;
}
else if(Frame[i] == 10 && Frame[i + 1] == 10 && (Frame[i+2]+Frame[i+3] ==10))
{
Total += 30;
break;
}
else if(Frame[i] == 10 &&( Frame[i + 1] + Frame[i + 2] == 10))
{
Total += 20;
break;
}
else if(Frame[i]+Frame[i+1]==10)
{
Total += 10 + Frame[i + 2];
break;
}
else
{
Total += Frame[i] + Frame[i + 1];
break;
}

}

return Total;
}


}
}