Skip to content

Commit

Permalink
adding .NET Core support using C# 7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
garora committed Dec 10, 2017
1 parent 9df35a1 commit d4d0925
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Src/CSharp/Net Core/Bowling Game/Game.cs
@@ -0,0 +1,51 @@
namespace TDD_Katas_NETCore.Bowling_Game
{
public class Game
{
private readonly int[] _rolls = new int[21];
private int _currentRoll;

public void Roll(int pins)
{
_rolls[_currentRoll++] = pins;
}

public int Score()
{
var score = 0;
var frameIndex = 0;
for (var frame = 0; frame < 10; frame++)
if (IsStrike(frameIndex))
{
score += StrikeBonus(frameIndex);
frameIndex++;
}
else if (IsSpare(frameIndex))
{
score += 10 + SpareBonus(frameIndex);
frameIndex += 2;
}

else
{
score += SumOfBallsInFrames(frameIndex);
frameIndex += 2;
}
return score;
}

private bool IsStrike(int frameIndex) => _rolls[frameIndex] == 10;



private int SumOfBallsInFrames(int frameIndex) => _rolls[frameIndex] + _rolls[frameIndex + 1];

private int SpareBonus(int frameIndex) => _rolls[frameIndex + 2];

private bool IsSpare(int frameIndex) => _rolls[frameIndex] + _rolls[frameIndex + 1] == 10;

private int StrikeBonus(int frameIndex) => 10 + _rolls[frameIndex + 1] + _rolls[frameIndex + 2];


}
}
89 changes: 89 additions & 0 deletions Src/CSharp/Net Core/Bowling Game/TestGame.cs
@@ -0,0 +1,89 @@
using System;
using NUnit.Framework;

namespace TDD_Katas_NETCore.Bowling_Game
{
[TestFixture]
[Category("TheBowlingGameKataNETCore")]
public class TestGame
{
[SetUp]
public void Setup()
{
_game = new Game();
_frames = 10;
}

[TearDown]
public void TearDown()
{
_game = null;
_frames = 0;
}

private Game _game;
private int _frames;

private void RollStrike()
{
_game.Roll(10);
}

private void FrameHits(int pin, int count)
{
for (var i = 0; i < count; i++)
_game.Roll(pin);
}

private void RollSpare()
{
_game.Roll(5);
_game.Roll(5);
}

[Test]
public void Can_Get_Calculate_Full_Game_Scores()
{
FrameHits(10, 12);
Console.WriteLine("Roll Total - {0}, Result - {1}", 300, _game.Score());
Assert.That(300, Is.EqualTo(_game.Score()));
}


[Test]
public void Can_Get_Calculate_Scores()
{
FrameHits(0, _frames);
Assert.That(0, Is.EqualTo(_game.Score()));
}

[Test]
public void Can_Get_Calculate_Single_Scores()
{
_game.Roll(0);
Console.WriteLine("Roll Total - {0}, Result - {1}", 0, _game.Score());
Assert.That(0, Is.EqualTo(_game.Score()));
}

[Test]
public void Can_Get_Calculate_Spare_Scores()
{
RollSpare();
_game.Roll(3);
FrameHits(0, 17);
Console.WriteLine("Roll Total - {0}, Result - {1}", 16, _game.Score());
Assert.That(16, Is.EqualTo(_game.Score()));
}

[Test]
public void Can_Get_Calculate_Strike_Scores()
{
RollStrike();
_game.Roll(3);
_game.Roll(4);
FrameHits(0, 16);
Console.WriteLine("Roll Total - {0}, Result - {1}", 24, _game.Score());
Assert.That(24, Is.EqualTo(_game.Score()));
}
}
}
17 changes: 17 additions & 0 deletions Src/CSharp/Net Core/TDD-Katas-NETCore.csproj
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RootNamespace>TDD_Katas_NETCore</RootNamespace>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<LangVersion>7</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions TDD-Katas-project.sln
Expand Up @@ -13,6 +13,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TDD-Katas-NET", "Src\CSharp\Net Framework\TDD-Katas-NET.csproj", "{BEDADFEE-66FB-41D8-8D09-3C6D9EFB1C90}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TDD-Katas-NETCore", "Src\CSharp\Net Core\TDD-Katas-NETCore.csproj", "{5E578FDA-24FC-4731-8E7A-3A4379FD898C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -23,12 +25,17 @@ Global
{BEDADFEE-66FB-41D8-8D09-3C6D9EFB1C90}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEDADFEE-66FB-41D8-8D09-3C6D9EFB1C90}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BEDADFEE-66FB-41D8-8D09-3C6D9EFB1C90}.Release|Any CPU.Build.0 = Release|Any CPU
{5E578FDA-24FC-4731-8E7A-3A4379FD898C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E578FDA-24FC-4731-8E7A-3A4379FD898C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E578FDA-24FC-4731-8E7A-3A4379FD898C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5E578FDA-24FC-4731-8E7A-3A4379FD898C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{BEDADFEE-66FB-41D8-8D09-3C6D9EFB1C90} = {FB2581EA-4AF6-4CF5-B74D-EA8F8ADA71A7}
{5E578FDA-24FC-4731-8E7A-3A4379FD898C} = {FB2581EA-4AF6-4CF5-B74D-EA8F8ADA71A7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {831FCE8B-919C-4742-B492-E67E260FB656}
Expand Down

0 comments on commit d4d0925

Please sign in to comment.