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

Feedback #1

Open
wants to merge 10 commits into
base: feedback
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin/
obj/
.vs/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-24ddc0f5d75046c5622901739e7c5dd533143b0c8e959d652212380cedb1ea36.svg)](https://classroom.github.com/a/SDJT-yFW)
31 changes: 31 additions & 0 deletions TDDKata2/TDDKata2.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32804.467
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TDDKata2", "TDDKata2\TDDKata2.csproj", "{68875F6F-58AA-4B39-B2F5-4D7AF5150F47}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TDDKataCalc", "TDDKataCalc\TDDKataCalc.csproj", "{840F690D-5CA8-4986-A10A-4846E82AB199}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{68875F6F-58AA-4B39-B2F5-4D7AF5150F47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68875F6F-58AA-4B39-B2F5-4D7AF5150F47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68875F6F-58AA-4B39-B2F5-4D7AF5150F47}.Release|Any CPU.ActiveCfg = Release|Any CPU
{68875F6F-58AA-4B39-B2F5-4D7AF5150F47}.Release|Any CPU.Build.0 = Release|Any CPU
{840F690D-5CA8-4986-A10A-4846E82AB199}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{840F690D-5CA8-4986-A10A-4846E82AB199}.Debug|Any CPU.Build.0 = Debug|Any CPU
{840F690D-5CA8-4986-A10A-4846E82AB199}.Release|Any CPU.ActiveCfg = Release|Any CPU
{840F690D-5CA8-4986-A10A-4846E82AB199}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AC53FAEC-F441-4529-A76C-0EBCCB6B9577}
EndGlobalSection
EndGlobal
32 changes: 32 additions & 0 deletions TDDKata2/TDDKata2/TDDKata2.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.console" Version="2.4.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TDDKataCalc\TDDKataCalc.csproj" />
</ItemGroup>

</Project>
142 changes: 142 additions & 0 deletions TDDKata2/TDDKata2/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
using TDDKataCalc;

namespace TDDKata2
{
public class UnitTest1
{

[Fact]
public void EmptyStringTest()
{

//arrange
var emptyString = "";
var expectedResult = 0;
var calc = new Calc();

//act
var result = calc.Add(emptyString);

//assert
Assert.Equal(expectedResult, result);
}

[Fact]
void OneDigitStringTest()
{
//arrange
var emptyString = "1";
var expectedResult = 1;
var calc = new Calc();

//act
var result = calc.Add(emptyString);

//assert
Assert.Equal(expectedResult, result);
}

[Fact]
void TwoDigitStringTest()
{
//arrange
var emptyString = "12";
var expectedResult = 3;
var calc = new Calc();

//act
var result = calc.Add(emptyString);

//assert
Assert.Equal(expectedResult, result);
}

[Theory()]
[InlineData("a")]
[InlineData(" ")]
void StringIsNotDigitTest(string inlineData)
{
//arrange
var emptyString = "a";
var calc = new Calc();

//assert
Assert.Throws<NotImplementedException>(() => calc.Add(inlineData));
}

[Fact]
void StringIsNotOnlyDigitTest()
{
//arrange
var emptyString = "1a";
var calc = new Calc();

//assert
Assert.Throws<NotImplementedException>(() => calc.Add(emptyString));
}

[Fact]
void StringHasMoreThan2DigitsTest()
{
//arrange
var emptyString = "123";
var calc = new Calc();

//assert
Assert.Throws<NotImplementedException>(() => calc.Add(emptyString));
}

[Fact]
void StringIsFloatNumberTypeTest()
{
//arrange
var emptyString = "1.1";
var calc = new Calc();

//assert
Assert.Throws<NotImplementedException>(() => calc.Add(emptyString));
}


[Fact]
void NullIsPassedAsArgumentTest()
{
//arrange
string? emptyString = null;
var calc = new Calc();

//assert
Assert.Throws<NotImplementedException>(() => calc.Add(emptyString));
}

[Fact]
void OptionalDelimiterAsPartOfTheStringTest()
{
//arrange
var requestString = "//;\n1;2";
var expectedResult = 3;
var calc = new Calc();

//act
var result = calc.Add(requestString);

//assert
Assert.Equal(expectedResult, result);
}

[Fact]
void OptionalDelimiterOfAnyLenghtAsPartOfTheStringTest()
{
//arrange
var requestString = "//***\n1***2";
var expectedResult = 3;
var calc = new Calc();

//act
var result = calc.Add(requestString);

//assert
Assert.Equal(expectedResult, result);
}
}
}
1 change: 1 addition & 0 deletions TDDKata2/TDDKata2/Usings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
48 changes: 48 additions & 0 deletions TDDKata2/TDDKataCalc/Calc.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Text.RegularExpressions;

namespace TDDKataCalc
{
public class Calc
{
public int Add(string digits)
{
int parsedNumber;
if (string.Empty == digits)
{
return 0;
}
else if(!string.IsNullOrEmpty(digits) && TryParseInputString(digits, out parsedNumber))
{
var firstNumber = parsedNumber % 10;
var secondNumber = parsedNumber / 10;
return firstNumber + secondNumber;
}
else
{
throw new NotImplementedException();
}
}

private bool TryParseInputString(string digits, out int parsedNumber)
{
Regex regex = new Regex("//[^A-Za-z0-9]+\n");
Match match = regex.Match(digits);
if (match.Success)
{
var stringArray = digits.Split('\n');
var delimiter = stringArray[0].Substring(2);
parsedNumber = Int32.Parse(digits.Split('\n')[1].Replace(delimiter,""));
var non = "";
return true;
}
else if (digits.Length < 3 && Int32.TryParse(digits, out parsedNumber))
{
return true;
}
else
{
throw new NotImplementedException();
}
}
}
}
9 changes: 9 additions & 0 deletions TDDKata2/TDDKataCalc/TDDKataCalc.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>