-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad461fc
commit 80bbae1
Showing
10 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
kata-solutions/lcd-digits-kata/lcd-digits-dotnet/LcdDigits.Tests/LcdDigits.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<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="..\LcdDigits\LcdDigits.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
58 changes: 58 additions & 0 deletions
58
kata-solutions/lcd-digits-kata/lcd-digits-dotnet/LcdDigits.Tests/LcdDigitsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using Xunit; | ||
using System; | ||
|
||
namespace Kata.Tests; | ||
|
||
public class LcdDigitsTest | ||
{ | ||
[Fact] | ||
public void Digit_the_number_0() | ||
{ | ||
string expect = " _ " + "\r\n" + | ||
"| |" + "\r\n" + | ||
"|_|" + "\r\n"; | ||
|
||
Assert.Equivalent(expect, LcdDigits.GetDigits(0)); | ||
} | ||
|
||
[Fact] | ||
public void Digit_the_number_1() | ||
{ | ||
string expect = " " + "\r\n" + | ||
" |" + "\r\n" + | ||
" |" + "\r\n"; | ||
|
||
Assert.Equivalent(expect, LcdDigits.GetDigits(1)); | ||
} | ||
|
||
[Fact] | ||
public void Digit_the_number_2() | ||
{ | ||
string expect = " _ " + "\r\n" + | ||
" _|" + "\r\n" + | ||
"|_ " + "\r\n"; | ||
|
||
Assert.Equivalent(expect, LcdDigits.GetDigits(2)); | ||
} | ||
|
||
[Fact] | ||
public void Digit_the_number_34() | ||
{ | ||
string expect = " _ " + "\r\n" + | ||
" _||_|" + "\r\n" + | ||
" _| |" + "\r\n"; | ||
|
||
Assert.Equivalent(expect, LcdDigits.GetDigits(34)); | ||
} | ||
|
||
|
||
[Fact] | ||
public void Digit_the_number_357() | ||
{ | ||
string expect = " _ _ _ " + "\r\n" + | ||
" _||_ |" + "\r\n" + | ||
" _| _| |" + "\r\n"; | ||
|
||
Assert.Equivalent(expect, LcdDigits.GetDigits(357)); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
kata-solutions/lcd-digits-kata/lcd-digits-dotnet/LcdDigits.Tests/Usings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
global using Xunit; |
41 changes: 41 additions & 0 deletions
41
kata-solutions/lcd-digits-kata/lcd-digits-dotnet/LcdDigits/LcdDigits.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
using System.Data; | ||
using System.Globalization; | ||
using System.Runtime.CompilerServices; | ||
using System.Security.Cryptography; | ||
|
||
namespace Kata; | ||
|
||
public class LcdDigits | ||
{ | ||
private static string _digits = | ||
" _ _ _ _ _ _ _ _ " + | ||
"| | | _| _||_||_ |_ ||_||_|" + | ||
"|_| ||_ _| | _||_| ||_| _|"; | ||
|
||
private static string[] ConvertToSingleDigitStringArray(int number) { | ||
return (from i in Enumerable.Range(0, 3) select _digits.Substring(i * 30 + number * 3, 3)).ToArray(); | ||
} | ||
|
||
private static string[] AddDigits(string[] digit_1, string[] digit_2) { | ||
return (from i in Enumerable.Range(0, 3) select digit_1[i] + digit_2[i]).ToArray(); | ||
} | ||
|
||
public static string[] NumberAsString(int number) | ||
{ | ||
int size = ("" + number).Length; | ||
int power = 1; | ||
for (int i = 1; i < size; i++) | ||
power *= 10; | ||
|
||
if (number < 10) | ||
return ConvertToSingleDigitStringArray(number / power); | ||
else | ||
return AddDigits(ConvertToSingleDigitStringArray(number / power), NumberAsString(number % power)); | ||
} | ||
|
||
public static string GetDigits(int number) { | ||
string[] numberAsString = NumberAsString(number); | ||
return numberAsString[0] + "\r\n" + numberAsString[1] + "\r\n" + numberAsString[2] + "\r\n"; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
kata-solutions/lcd-digits-kata/lcd-digits-dotnet/LcdDigits/LcdDigits.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
27 changes: 27 additions & 0 deletions
27
kata-solutions/lcd-digits-kata/lcd-digits-dotnet/lcddigits.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.0.31903.59 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LcdDigits", "LcdDigits\LcdDigits.csproj", "{966F6F47-23DB-459B-959F-3115EB010C0A}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LcdDigits.Tests", "LcdDigits.Tests\LcdDigits.Tests.csproj", "{BBE7EAF8-7CBB-4C49-81A2-D7D43663EFFB}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{966F6F47-23DB-459B-959F-3115EB010C0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{966F6F47-23DB-459B-959F-3115EB010C0A}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{966F6F47-23DB-459B-959F-3115EB010C0A}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{966F6F47-23DB-459B-959F-3115EB010C0A}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{BBE7EAF8-7CBB-4C49-81A2-D7D43663EFFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{BBE7EAF8-7CBB-4C49-81A2-D7D43663EFFB}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{BBE7EAF8-7CBB-4C49-81A2-D7D43663EFFB}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{BBE7EAF8-7CBB-4C49-81A2-D7D43663EFFB}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dotnet watch test --project lcddigits.sln |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# About the LCD Digits Kata | ||
|
||
The goal of this kata is to convert any arbitrary (integer) number | ||
into a string representation like so: | ||
|
||
``` | ||
_ _ _ _ _ _ _ _ | ||
| | | _| _||_||_ |_ ||_||_| | ||
|_| ||_ _| | _||_| ||_| _| | ||
``` | ||
|
||
For example, the number 318 must be rendered as | ||
|
||
``` | ||
_ _ | ||
_| ||_| | ||
_| ||_| | ||
``` |