Skip to content
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 @@
.vs/
bin/
obj/
31 changes: 31 additions & 0 deletions String2IntTest/String2IntTest.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 16
VisualStudioVersion = 16.0.31624.102
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "String2IntTest", "String2IntTest\String2IntTest.csproj", "{BEEFA1D5-8FBF-491E-849C-AC7FEA2754C3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "String2IntTestTests", "String2IntTestTests\String2IntTestTests.csproj", "{B1E79B52-D62C-4AF6-ADA0-A6793A052EC1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BEEFA1D5-8FBF-491E-849C-AC7FEA2754C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BEEFA1D5-8FBF-491E-849C-AC7FEA2754C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEEFA1D5-8FBF-491E-849C-AC7FEA2754C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BEEFA1D5-8FBF-491E-849C-AC7FEA2754C3}.Release|Any CPU.Build.0 = Release|Any CPU
{B1E79B52-D62C-4AF6-ADA0-A6793A052EC1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1E79B52-D62C-4AF6-ADA0-A6793A052EC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1E79B52-D62C-4AF6-ADA0-A6793A052EC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1E79B52-D62C-4AF6-ADA0-A6793A052EC1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D540A343-1C23-43F6-B22A-0C0F457FE0BC}
EndGlobalSection
EndGlobal
50 changes: 50 additions & 0 deletions String2IntTest/String2IntTest/String2Int.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
/**
* Fillter all integers in given string, build whole integer and return it
*
* Note: The reason it doesn't have Main function is, it is supposed to be a
* converter and used as utility function.
*
* **/
namespace String2IntTest
{
public class String2Int
{
int _Integer;
public int GetInteger
{
get { return _Integer; }
}
public void FillterInteger(string strinput)
{
int output = 0 ;
bool IsHasDigit = false;

if (strinput.Length == 0)
{
throw new ArgumentException("No input data");
}

foreach (char i in strinput)
{
if (IsDigit(i))
{
IsHasDigit = true;
output = (output * 10) + ((int)i - 48);
}
}

if (!IsHasDigit && output == 0)
{
throw new ArgumentException("Output is null");
}

_Integer = output;
}
private bool IsDigit(char c)
{
return (int)c >= 48 && (int)c <= 57 ;
}
}

}
10 changes: 10 additions & 0 deletions String2IntTest/String2IntTest/String2IntTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<ApplicationIcon />
<StartupObject />
</PropertyGroup>

</Project>
20 changes: 20 additions & 0 deletions String2IntTest/String2IntTestTests/String2IntTestTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>.NETCoreApp,Version=v3.1</TargetFramework>

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

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="coverlet.collector" Version="3.0.2" />
</ItemGroup>

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

</Project>
72 changes: 72 additions & 0 deletions String2IntTest/String2IntTestTests/String2IntTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using String2IntTest;
using System;
using System.Collections.Generic;
using System.Text;

namespace String2IntTest.Tests
{
[TestClass()]
public class String2IntTests
{
[TestMethod()]
public void TestNoInputData()
{
try
{
String2Int strinput = new String2Int();
strinput.FillterInteger("");
}
catch (ArgumentException e)
{
StringAssert.Contains(e.Message, "No input data");
}

}

[TestMethod()]
public void TestSpecialCharactersOnly()
{
try
{
String2Int strinput = new String2Int();
strinput.FillterInteger(" *,");
}
catch (ArgumentException e)
{
StringAssert.Contains(e.Message, "Output is null");
}

}


[TestMethod()]
public void TestIntegerOnly()
{

String2Int strinput = new String2Int();
strinput.FillterInteger("034599");
Assert.AreEqual(034599, strinput.GetInteger);


}
[TestMethod()]
public void TestSampleInputA()
{
String2Int strinput = new String2Int();
strinput.FillterInteger("abc573");
Assert.AreEqual(573, strinput.GetInteger);

}

[TestMethod()]
public void TestSampleInputB()
{
String2Int strinput = new String2Int();
strinput.FillterInteger("a5b7c3");
Assert.AreEqual(573, strinput.GetInteger);

}

}
}