Skip to content

Commit 42c2946

Browse files
authored
Merge pull request #46 from shinji-san/release-v1.0.1
Release v1.0.1 Fixed: - Fixed a bug in `Luhn.ComputeLuhnNumber` and `Luhn.ComputeLuhnCheckDigit` methods that sometimes returned an incorrect result. Resolves: #46
2 parents 2b905da + 7a4c924 commit 42c2946

7 files changed

+33
-16
lines changed

CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [1.0.1] - 2024-02-19
8+
### Fixed
9+
- Fixed a bug in `Luhn.ComputeLuhnNumber` and `Luhn.ComputeLuhnCheckDigit` methods that sometimes returned an incorrect result.
10+
711
## [1.0.0] - 2024-02-19
812
### Added
913
- Added .NET 8 support
@@ -38,6 +42,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3842
### Added
3943
- Added initial version of LuhnDotNet
4044

41-
[1.0.0]: https://github.com/shinji-san/LuhnDotNet/compare/v0.2.0...v1.0.0
45+
[1.0.1]: https://github.com/shinji-san/LuhnDotNet/compare/v1.0.0..v1.0.1
46+
[1.0.0]: https://github.com/shinji-san/LuhnDotNet/compare/v0.2.0..v1.0.0
4247
[0.2.0]: https://github.com/shinji-san/LuhnDotNet/compare/v0.1.0..v0.2.0
4348
[0.1.0]: https://github.com/shinji-san/LuhnDotNet/releases/tag/v0.1.0

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ An C# implementation of the Luhn algorithm.
6161
</thead>
6262
<tbody>
6363
<tr>
64-
<td rowspan=10><a href="https://github.com/shinji-san/LuhnDotNet/actions?query=workflow%3A%22LuhnDotNet+NuGet%22" target="_blank"><img src="https://github.com/shinji-san/LuhnDotNet/workflows/LuhnDotNet%20NuGet/badge.svg?branch=v1.0.0" alt="LuhnDotNet NuGet"/></a></td>
65-
<td rowspan=10><a href="https://badge.fury.io/nu/LuhnDotNet" target="_blank"><img src="https://badge.fury.io/nu/LuhnDotNet.svg" alt="NuGet Version 1.0.0"/></a></td>
66-
<td rowspan=10><a href="https://github.com/shinji-san/LuhnDotNet/tree/v1.0.0" target="_blank"><img src="https://img.shields.io/badge/LuhnDotNet-1.0.0-green.svg?logo=github&logoColor=959da5&color=2ebb4e&labelColor=2b3137" alt="Tag"/></a></td>
64+
<td rowspan=10><a href="https://github.com/shinji-san/LuhnDotNet/actions?query=workflow%3A%22LuhnDotNet+NuGet%22" target="_blank"><img src="https://github.com/shinji-san/LuhnDotNet/workflows/LuhnDotNet%20NuGet/badge.svg?branch=v1.0.1" alt="LuhnDotNet NuGet"/></a></td>
65+
<td rowspan=10><a href="https://badge.fury.io/nu/LuhnDotNet" target="_blank"><img src="https://badge.fury.io/nu/LuhnDotNet.svg" alt="NuGet Version 1.0.1"/></a></td>
66+
<td rowspan=10><a href="https://github.com/shinji-san/LuhnDotNet/tree/v1.0.1" target="_blank"><img src="https://img.shields.io/badge/LuhnDotNet-1.0.1-green.svg?logo=github&logoColor=959da5&color=2ebb4e&labelColor=2b3137" alt="Tag"/></a></td>
6767
<td>.NET 6</td>
6868
</tr>
6969
<tr>
@@ -100,19 +100,19 @@ An C# implementation of the Luhn algorithm.
100100

101101
1. Open a console and switch to the directory, containing your project file.
102102

103-
2. Use the following command to install version 1.0.0 of the LuhnDotNet package:
103+
2. Use the following command to install version 1.0.1 of the LuhnDotNet package:
104104

105105
```dotnetcli
106-
dotnet add package LuhnDotNet -v 1.0.0 -f <FRAMEWORK>
106+
dotnet add package LuhnDotNet -v 1.0.1 -f <FRAMEWORK>
107107
```
108108
109-
3. After the completition of the command, look at the project file to make sure that the package is successfuly installed.
109+
3. After the completion of the command, look at the project file to make sure that the package is successfully installed.
110110
111111
You can open the `.csproj` file to see the added package reference:
112112
113113
```xml
114114
<ItemGroup>
115-
<PackageReference Include="LuhnDotNet" Version="1.0.0" />
115+
<PackageReference Include="LuhnDotNet" Version="1.0.1" />
116116
</ItemGroup>
117117
```
118118
## Remove LuhnDotNet package
@@ -125,7 +125,7 @@ An C# implementation of the Luhn algorithm.
125125
dotnet remove package LuhnDotNet
126126
```
127127
128-
3. After the completition of the command, look at the project file to make sure that the package is successfuly removed.
128+
3. After the completion of the command, look at the project file to make sure that the package is successfuly removed.
129129
130130
You can open the `.csproj` file to check the deleted package reference.
131131

src/Luhn.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static byte ComputeLuhnCheckDigit(ReadOnlySpan<char> number) =>
7373
#else
7474
public static byte ComputeLuhnCheckDigit(string number) =>
7575
#endif
76-
(byte)(Modulus - number.IsNumber().GetDigits().DoubleEverySecondDigit(false).SumDigits());
76+
(byte)((Modulus - number.IsNumber().GetDigits().DoubleEverySecondDigit(false).SumDigits()) % Modulus);
7777

7878
/// <summary>
7979
/// Computes the Luhn number which is a combination of the given number and the calculated check digit.
@@ -89,7 +89,7 @@ public static string ComputeLuhnNumber(ReadOnlySpan<char> number)
8989
public static string ComputeLuhnNumber(string number)
9090
#endif
9191
{
92-
byte checkDigit = (byte)(Modulus - number.IsNumber().GetDigits().DoubleEverySecondDigit(false).SumDigits());
92+
byte checkDigit = (byte)((Modulus - number.IsNumber().GetDigits().DoubleEverySecondDigit(false).SumDigits()) % Modulus);
9393
#if NET6_0_OR_GREATER
9494
return string.Concat(number.Trim(), checkDigit.ToString(CultureInfo.InvariantCulture));
9595
#else

src/LuhnDotNet.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
<Authors>Sebastian Walther</Authors>
1111
<PackageId>LuhnDotNet</PackageId>
1212
<PackageLicenseExpression>MIT</PackageLicenseExpression>
13-
<PackageReleaseNotes>Changelog: https://github.com/shinji-san/LuhnDotNet/blob/v1.0.0/CHANGELOG.md</PackageReleaseNotes>
13+
<PackageReleaseNotes>Changelog: https://github.com/shinji-san/LuhnDotNet/blob/v1.0.1/CHANGELOG.md</PackageReleaseNotes>
1414
<PackageDescription>An C# implementation of the Luhn algorithm</PackageDescription>
1515
<PackageReadmeFile>README.md</PackageReadmeFile>
1616
<PackageTags>luhn;luhn-algorithm</PackageTags>
1717
<PackageProjectUrl>https://github.com/shinji-san/LuhnDotNet</PackageProjectUrl>
1818
<RepositoryUrl>https://github.com/shinji-san/LuhnDotNet</RepositoryUrl>
1919
<RepositoryType>git</RepositoryType>
20-
<Version>1.0.0</Version>
20+
<Version>1.0.1</Version>
2121
<Authors>Sebastian Walther</Authors>
2222
<Company>Private Person</Company>
2323
<GenerateDocumentationFile>true</GenerateDocumentationFile>

src/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
[assembly: Guid("bba40d96-b58d-4a8f-b6fc-3699e0addf98")]
1717

18-
[assembly: AssemblyVersion("1.0.0")]
19-
[assembly: AssemblyFileVersion("1.0.0")]
18+
[assembly: AssemblyVersion("1.0.1")]
19+
[assembly: AssemblyFileVersion("1.0.1")]
2020
[assembly: NeutralResourcesLanguage("en")]
2121

2222
[assembly: System.CLSCompliant(true)]

tests/LuhnDotNetTest.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1515
<PrivateAssets>all</PrivateAssets>
1616
</PackageReference>
17-
<PackageReference Include="coverlet.collector" Version="6.0.0">
17+
<PackageReference Include="coverlet.collector" Version="6.0.2">
1818
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1919
<PrivateAssets>all</PrivateAssets>
2020
</PackageReference>

tests/LuhnTest.cs

+12
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ public class LuhnTest
1616
public static IEnumerable<object[]> LuhnCheckDigitComputeSet =>
1717
new List<object[]>
1818
{
19+
new object[] { 4, "1789372997" },
20+
new object[] { 0, "353011133330000" },
1921
new object[] { 3, "7992739871" },
2022
new object[] { 3, "07992739871" },
2123
new object[] { 3, "007992739871" },
2224
new object[] { 2, "110494" },
25+
new object[] { 7, "1893" },
2326
new object[] { 5, "37828224631000" },
2427
new object[] { 5, "637095000000000" },
2528
new object[] { 5, " 637095000000000" },
@@ -35,10 +38,13 @@ public class LuhnTest
3538
public static IEnumerable<object[]> LuhnNumberComputeSet =>
3639
new List<object[]>
3740
{
41+
new object[] { "17893729974", "1789372997" },
42+
new object[] { "3530111333300000", "353011133330000" },
3843
new object[] { "79927398713", "7992739871" },
3944
new object[] { "079927398713", "07992739871" },
4045
new object[] { "0079927398713", "007992739871" },
4146
new object[] { "1104942", "110494" },
47+
new object[] { "18937", "1893" },
4248
new object[] { "378282246310005", "37828224631000" },
4349
new object[] { "6370950000000005", "637095000000000" },
4450
new object[] { "6370950000000005", " 637095000000000" },
@@ -54,10 +60,13 @@ public class LuhnTest
5460
public static IEnumerable<object[]> LuhnNumberValidationSet =>
5561
new List<object[]>
5662
{
63+
new object[] { true, "17893729974" },
64+
new object[] { true, "3530111333300000" },
5765
new object[] { true, "79927398713" },
5866
new object[] { true, "0079927398713" },
5967
new object[] { true, "079927398713" },
6068
new object[] { true, "1104942" },
69+
new object[] { true, "18937" },
6170
new object[] { true, "01104942" },
6271
new object[] { true, "378282246310005" },
6372
new object[] { true, "6370950000000005" },
@@ -79,11 +88,14 @@ public class LuhnTest
7988
public static IEnumerable<object[]> LuhnCheckDigitValidationSet =>
8089
new List<object[]>
8190
{
91+
new object[] { true, "1789372997", 4 },
92+
new object[] { true, "353011133330000", 0 },
8293
new object[] { true, "7992739871", 3 },
8394
new object[] { true, "07992739871", 3 },
8495
new object[] { true, "007992739871", 3 },
8596
new object[] { true, "0007992739871", 3 },
8697
new object[] { true, "110494", 2 },
98+
new object[] { true, "1893", 7 },
8799
new object[] { true, "37828224631000", 5 },
88100
new object[] { true, "637095000000000", 5 },
89101
new object[] { true, " 637095000000000", 5 },

0 commit comments

Comments
 (0)