Skip to content

Commit 8dc187c

Browse files
committed
Remove obsolete Luhn.IsValid methods
Deprecated `Luhn.IsValid` methods have been removed from the codebase, including tests and spanning overloads. Users should now migrate to the updated `IsValidLuhnNumber` and `IsValidLuhnCheckDigit` methods for validation tasks. Updates are reflected in the changelog for clarity. Resolves: No entry
1 parent 0b42eeb commit 8dc187c

File tree

3 files changed

+4
-75
lines changed

3 files changed

+4
-75
lines changed

CHANGELOG.md

+4
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+
## [Unreleased]
8+
### Removed
9+
- Removed `Luhn.IsValid` methods
10+
711
## [1.3.0] - 2024-12-27
812
### Added
913
- Add project icon

src/Luhn.cs

-63
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,6 @@ public static string ComputeLuhnNumber(this string number)
123123
}
124124

125125
#if NET8_0_OR_GREATER
126-
/// <summary>
127-
/// Checks whether the Luhn Number is valid
128-
/// </summary>
129-
/// <param name="luhnNumber">An identification number w/ check digit (Luhn Number).</param>
130-
/// <returns><see langword="true" /> if the <paramref name="luhnNumber"/> is valid;
131-
/// otherwise <see langword="false" /></returns>
132-
/// <exception cref="ArgumentException"><paramref name="luhnNumber"/> is not valid.
133-
/// It contains none-numeric characters.</exception>
134-
/// <remarks>The check digit must be at the end of the <paramref name="luhnNumber"/>
135-
/// (on the right side).</remarks>
136-
[SuppressMessage("ReSharper", "UnusedMember.Global")]
137-
[SuppressMessage("ReSharper", "HeapView.ObjectAllocation")]
138-
[Obsolete("Use the IsValidLuhnNumber method instead.", false)]
139-
public static bool IsValid(this ReadOnlySpan<char> luhnNumber) => luhnNumber.IsValidLuhnNumber();
140-
141126
/// <summary>
142127
/// Checks whether the Luhn Number is valid
143128
/// </summary>
@@ -154,21 +139,6 @@ public static bool IsValidLuhnNumber(this ReadOnlySpan<char> luhnNumber) =>
154139
luhnNumber.IsNumber().GetDigits().DoubleEverySecondDigit(true).SumDigits() == 0;
155140
#endif
156141

157-
/// <summary>
158-
/// Checks whether the Luhn Number is valid
159-
/// </summary>
160-
/// <param name="luhnNumber">An identification number w/ check digit (Luhn Number).</param>
161-
/// <returns><see langword="true" /> if the <paramref name="luhnNumber"/> is valid;
162-
/// otherwise <see langword="false" /></returns>
163-
/// <exception cref="ArgumentException"><paramref name="luhnNumber"/> is not valid.
164-
/// It contains none-numeric characters.</exception>
165-
/// <remarks>The check digit must be at the end of the <paramref name="luhnNumber"/>
166-
/// (on the right side).</remarks>
167-
[SuppressMessage("ReSharper", "UnusedMember.Global")]
168-
[SuppressMessage("ReSharper", "HeapView.ObjectAllocation")]
169-
[Obsolete("Use the IsValidLuhnNumber method instead.", false)]
170-
public static bool IsValid(this string luhnNumber) => luhnNumber.IsValidLuhnNumber();
171-
172142
/// <summary>
173143
/// Checks whether the Luhn Number is valid
174144
/// </summary>
@@ -189,23 +159,6 @@ public static bool IsValidLuhnNumber(this string luhnNumber) =>
189159
#endif
190160

191161
#if NET8_0_OR_GREATER
192-
/// <summary>
193-
/// Checks whether the concatenation of number and corresponding Luhn check digit is valid
194-
/// </summary>
195-
/// <param name="number">Identification number w/o Luhn check digit</param>
196-
/// <param name="checkDigit">The Luhn check digit</param>
197-
/// <returns><see langword="true" /> if the <paramref name="number"/> is valid;
198-
/// otherwise <see langword="false" /></returns>
199-
/// <exception cref="ArgumentException"><paramref name="number"/> is not valid.
200-
/// It contains none-numeric characters.</exception>
201-
/// <exception cref="ArgumentOutOfRangeException">The <paramref name="checkDigit"/> value is greater than 9.
202-
/// The <paramref name="checkDigit"/> value must be between 0 and 9.</exception>
203-
[SuppressMessage("ReSharper", "UnusedMember.Global")]
204-
[SuppressMessage("ReSharper", "HeapView.ObjectAllocation")]
205-
[Obsolete("Use the IsValidLuhnCheckDigit method instead.", false)]
206-
public static bool IsValid(this ReadOnlySpan<char> number, byte checkDigit) =>
207-
checkDigit.IsValidLuhnCheckDigit(number);
208-
209162
/// <summary>
210163
/// Checks whether the concatenation of number and corresponding Luhn check digit is valid
211164
/// </summary>
@@ -238,22 +191,6 @@ public static bool IsValidLuhnCheckDigit(this byte checkDigit, ReadOnlySpan<char
238191
}
239192
#endif
240193

241-
/// <summary>
242-
/// Checks whether the concatenation of number and corresponding Luhn check digit is valid
243-
/// </summary>
244-
/// <param name="number">Identification number w/o Luhn check digit</param>
245-
/// <param name="checkDigit">The Luhn check digit</param>
246-
/// <returns><see langword="true" /> if the <paramref name="number"/> is valid;
247-
/// otherwise <see langword="false" /></returns>
248-
/// <exception cref="ArgumentException"><paramref name="number"/> is not valid.
249-
/// It contains none-numeric characters.</exception>
250-
/// <exception cref="ArgumentOutOfRangeException">The <paramref name="checkDigit"/> value is greater than 9.
251-
/// The <paramref name="checkDigit"/> value must be between 0 and 9.</exception>
252-
[SuppressMessage("ReSharper", "UnusedMember.Global")]
253-
[SuppressMessage("ReSharper", "HeapView.ObjectAllocation")]
254-
[Obsolete("Use the IsValidLuhnCheckDigit method instead.", false)]
255-
public static bool IsValid(this string number, byte checkDigit) => checkDigit.IsValidLuhnCheckDigit(number);
256-
257194
/// <summary>
258195
/// Checks whether the concatenation of number and corresponding Luhn check digit is valid
259196
/// </summary>

tests/LuhnTest.cs

-12
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,7 @@ public void ComputeLuhnNumber_ValidRawNumber_ReturnsExpectedLuhnNumber(
187187
[MemberData(nameof(LuhnNumberValidationSet), MemberType = typeof(LuhnTest))]
188188
public void LuhnNumberValidationTest(bool expectedResult, string luhnNumber)
189189
{
190-
Assert.Equal(expectedResult, luhnNumber.IsValid());
191190
Assert.Equal(expectedResult, luhnNumber.IsValidLuhnNumber());
192-
Assert.Equal(expectedResult, luhnNumber.AsSpan().IsValid());
193191
Assert.Equal(expectedResult, luhnNumber.AsSpan().IsValidLuhnNumber());
194192
}
195193

@@ -203,9 +201,7 @@ public void LuhnNumberValidationTest(bool expectedResult, string luhnNumber)
203201
[MemberData(nameof(LuhnCheckDigitValidationSet), MemberType = typeof(LuhnTest))]
204202
public void LuhnCheckDigitValidationTest(bool expectedResult, string number, byte checkDigit)
205203
{
206-
Assert.Equal(expectedResult, number.IsValid(checkDigit));
207204
Assert.Equal(expectedResult, checkDigit.IsValidLuhnCheckDigit(number));
208-
Assert.Equal(expectedResult, number.AsSpan().IsValid(checkDigit));
209205
Assert.Equal(expectedResult, checkDigit.IsValidLuhnCheckDigit(number.AsSpan()));
210206
}
211207

@@ -243,9 +239,7 @@ public void ComputeLuhnNumber_InvalidRawNumber_ThrowsArgumentException(string in
243239
[MemberData(nameof(InvalidNumbers), MemberType = typeof(LuhnTest))]
244240
public void LuhnNumberValidationExceptionTest(string invalidNumber)
245241
{
246-
Assert.Throws<ArgumentException>(() => invalidNumber.IsValid());
247242
Assert.Throws<ArgumentException>(() => invalidNumber.IsValidLuhnNumber());
248-
Assert.Throws<ArgumentException>(() => invalidNumber.AsSpan().IsValid());
249243
Assert.Throws<ArgumentException>(() => invalidNumber.AsSpan().IsValidLuhnNumber());
250244
}
251245

@@ -257,9 +251,7 @@ public void LuhnNumberValidationExceptionTest(string invalidNumber)
257251
[MemberData(nameof(InvalidNumbersAndCheckDigits), MemberType = typeof(LuhnTest))]
258252
public void NumberValidationExceptionTest(string invalidNumber, byte checkDigit)
259253
{
260-
Assert.Throws<ArgumentException>(() => invalidNumber.IsValid(checkDigit));
261254
Assert.Throws<ArgumentException>(() => checkDigit.IsValidLuhnCheckDigit(invalidNumber));
262-
Assert.Throws<ArgumentException>(() => invalidNumber.AsSpan().IsValid(checkDigit));
263255
Assert.Throws<ArgumentException>(() => checkDigit.IsValidLuhnCheckDigit(invalidNumber.AsSpan()));
264256
}
265257

@@ -271,9 +263,7 @@ public void NumberValidationExceptionTest(string invalidNumber, byte checkDigit)
271263
[MemberData(nameof(NumbersWithInvalidCheckDigits), MemberType = typeof(LuhnTest))]
272264
public void LuhnCheckDigitValidationExceptionTest(string invalidNumber, byte checkDigit)
273265
{
274-
Assert.Throws<ArgumentOutOfRangeException>(() => invalidNumber.IsValid(checkDigit));
275266
Assert.Throws<ArgumentOutOfRangeException>(() => checkDigit.IsValidLuhnCheckDigit(invalidNumber));
276-
Assert.Throws<ArgumentOutOfRangeException>(() => invalidNumber.AsSpan().IsValid(checkDigit));
277267
Assert.Throws<ArgumentOutOfRangeException>(() => checkDigit.IsValidLuhnCheckDigit(invalidNumber.AsSpan()));
278268
}
279269

@@ -340,9 +330,7 @@ public void ConvertAlphaNumericToNumeric_InvalidInput_ThrowsArgumentException()
340330
[MemberData(nameof(IsValidWithConvertData), MemberType = typeof(LuhnTest))]
341331
public void IsValidWithConvertTest(string input, bool expected)
342332
{
343-
Assert.Equal(expected, input.ConvertAlphaNumericToNumeric().IsValid());
344333
Assert.Equal(expected, input.ConvertAlphaNumericToNumeric().IsValidLuhnNumber());
345-
Assert.Equal(expected, input.ConvertAlphaNumericToNumeric().AsSpan().IsValid());
346334
Assert.Equal(expected, input.ConvertAlphaNumericToNumeric().AsSpan().IsValidLuhnNumber());
347335
}
348336

0 commit comments

Comments
 (0)