Skip to content

Commit eafd58f

Browse files
committed
Rename ConvertAlphaNumericToNumeric to AlphaNumericToNumeric
Updated method name for clarity and consistency across the codebase. Adjusted all references in the code, tests, README, and CHANGELOG to reflect the new method name. Resolves: No entry
1 parent 5e42882 commit eafd58f

File tree

4 files changed

+26
-23
lines changed

4 files changed

+26
-23
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ 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

77
## [Unreleased]
8+
### Changed
9+
- Renamed `Luhn.ConvertAlphaNumericToNumeric` to `Luhn.AlphaNumericToNumeric`
10+
811
### Removed
912
- Removed `Luhn.IsValid` methods
1013

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ namespace Example4
212212
}
213213
```
214214

215-
## Validate ISIN with LuhnDotNet and ConvertAlphaNumericToNumeric
215+
## Validate ISIN with LuhnDotNet and AlphaNumericToNumeric
216216

217-
The `LuhnDotNet` library can be used in combination with the `ConvertAlphaNumericToNumeric` method to validate an International Securities Identification Number (ISIN). An ISIN uniquely identifies a security, such as stocks, bonds or derivatives. It is a 12-character alphanumeric code.
217+
The `LuhnDotNet` library can be used in combination with the `AlphaNumericToNumeric` method to validate an International Securities Identification Number (ISIN). An ISIN uniquely identifies a security, such as stocks, bonds or derivatives. It is a 12-character alphanumeric code.
218218

219-
The `ConvertAlphaNumericToNumeric` method is used to convert the alphanumeric ISIN to a numeric string, where each letter in the input string is replaced by its decimal ASCII value minus 55. This numeric string can then be validated using the `Luhn.IsValid` method.
219+
The `AlphaNumericToNumeric` method is used to convert the alphanumeric ISIN to a numeric string, where each letter in the input string is replaced by its decimal ASCII value minus 55. This numeric string can then be validated using the `Luhn.IsValid` method.
220220

221221
Here is an example of how to use these methods to validate an ISIN:
222222

@@ -231,15 +231,15 @@ namespace Example5
231231
public static void Main(string[] args)
232232
{
233233
string isin = "US0378331005";
234-
bool isValid = isin.ConvertAlphaNumericToNumeric().IsValidLuhnNumber();
234+
bool isValid = isin.AlphaNumericToNumeric().IsValidLuhnNumber();
235235
Console.WriteLine($"The ISIN {isin} is valid: {isValid}");
236236
}
237237
}
238238
}
239239
```
240-
## Compute ISIN Check Digit with LuhnDotNet and ConvertAlphaNumericToNumeric
240+
## Compute ISIN Check Digit with LuhnDotNet and AlphaNumericToNumeric
241241

242-
The `LuhnDotNet` library provides the `ComputeLuhnCheckDigit` method which can be used to compute the check digit of a numeric string according to the Luhn algorithm. When dealing with an International Securities Identification Number (ISIN), which is a 12-character alphanumeric code, we first need to convert the alphanumeric ISIN to a numeric string. This can be achieved using the `ConvertAlphaNumericToNumeric` method.
242+
The `LuhnDotNet` library provides the `ComputeLuhnCheckDigit` method which can be used to compute the check digit of a numeric string according to the Luhn algorithm. When dealing with an International Securities Identification Number (ISIN), which is a 12-character alphanumeric code, we first need to convert the alphanumeric ISIN to a numeric string. This can be achieved using the `AlphaNumericToNumeric` method.
243243

244244
Here is an example of how to compute the check digit of an ISIN:
245245

@@ -254,7 +254,7 @@ namespace Example6
254254
public static void Main(string[] args)
255255
{
256256
string isinWithoutCheckDigit = "US037833100";
257-
byte checkDigit = isinWithoutCheckDigit.ConvertAlphaNumericToNumeric().ComputeLuhnCheckDigit();
257+
byte checkDigit = isinWithoutCheckDigit.AlphaNumericToNumeric().ComputeLuhnCheckDigit();
258258
Console.WriteLine($"The check digit for ISIN {isinWithoutCheckDigit} is: {checkDigit}");
259259
}
260260
}

src/Luhn.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public static bool IsValidLuhnCheckDigit(this byte checkDigit, string number)
246246
/// This method iterates over each character in the input string. If the character is a letter, it is replaced
247247
/// by its decimal ASCII value minus 55. If the character is a digit, it is left unchanged.
248248
/// </remarks>
249-
public static string ConvertAlphaNumericToNumeric(this string alphaNumeric)
249+
public static string AlphaNumericToNumeric(this string alphaNumeric)
250250
#if NET8_0_OR_GREATER
251251
{
252252
Span<char> result = stackalloc char[alphaNumeric.Length * 2];

tests/LuhnTest.cs

+15-15
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public void LuhnCheckDigitValidationExceptionTest(string invalidNumber, byte che
268268
}
269269

270270
/// <summary>
271-
/// Test data for ConvertAlphaNumericToNumeric method.
271+
/// Test data for AlphaNumericToNumeric method.
272272
/// </summary>
273273
public static IEnumerable<object[]> ConvertAlphaNumericToNumericData =>
274274
new List<object[]>
@@ -282,33 +282,33 @@ public void LuhnCheckDigitValidationExceptionTest(string invalidNumber, byte che
282282
};
283283

284284
/// <summary>
285-
/// Tests the ConvertAlphaNumericToNumeric method.
285+
/// Tests the AlphaNumericToNumeric method.
286286
/// </summary>
287287
/// <param name="input">Input string</param>
288288
/// <param name="expected">Expected output</param>
289289
[Theory(DisplayName = "Converts an alphanumeric string to a numeric string")]
290290
[MemberData(nameof(ConvertAlphaNumericToNumericData), MemberType = typeof(LuhnTest))]
291291
public void ConvertAlphaNumericToNumeric_ShouldReturnExpectedResult(string input, string expected)
292292
{
293-
Assert.Equal(expected, input.ConvertAlphaNumericToNumeric());
293+
Assert.Equal(expected, input.AlphaNumericToNumeric());
294294
}
295295

296296
/// <summary>
297-
/// Tests the ConvertAlphaNumericToNumeric method with invalid input.
297+
/// Tests the AlphaNumericToNumeric method with invalid input.
298298
/// </summary>
299299
/// <remarks>
300-
/// This test checks if the ConvertAlphaNumericToNumeric method throws an ArgumentException when it is given an
300+
/// This test checks if the AlphaNumericToNumeric method throws an ArgumentException when it is given an
301301
/// invalid input string that contains non-alphanumeric characters. The test uses the Assert. Throws method from
302302
/// xUnit to check if the expected exception is thrown.
303303
/// </remarks>
304304
[Fact(DisplayName = "Converts an invalid alphanumeric string to a numeric string to throw an exception")]
305305
public void ConvertAlphaNumericToNumeric_InvalidInput_ThrowsArgumentException()
306306
{
307-
Assert.Throws<ArgumentException>(()=> "!@#$%^&*()".ConvertAlphaNumericToNumeric());
307+
Assert.Throws<ArgumentException>(()=> "!@#$%^&*()".AlphaNumericToNumeric());
308308
}
309309

310310
/// <summary>
311-
/// Test data for IsValid method in combination with ConvertAlphaNumericToNumeric.
311+
/// Test data for IsValid method in combination with AlphaNumericToNumeric.
312312
/// </summary>
313313
public static IEnumerable<object[]> IsValidWithConvertData =>
314314
new List<object[]>
@@ -322,20 +322,20 @@ public void ConvertAlphaNumericToNumeric_InvalidInput_ThrowsArgumentException()
322322
};
323323

324324
/// <summary>
325-
/// Tests the IsValid method in combination with ConvertAlphaNumericToNumeric.
325+
/// Tests the IsValid method in combination with AlphaNumericToNumeric.
326326
/// </summary>
327327
/// <param name="input">Input string</param>
328328
/// <param name="expected">Expected output</param>
329329
[Theory(DisplayName = "Validates a numeric string converted from an alphanumeric string")]
330330
[MemberData(nameof(IsValidWithConvertData), MemberType = typeof(LuhnTest))]
331331
public void IsValidWithConvertTest(string input, bool expected)
332332
{
333-
Assert.Equal(expected, input.ConvertAlphaNumericToNumeric().IsValidLuhnNumber());
334-
Assert.Equal(expected, input.ConvertAlphaNumericToNumeric().AsSpan().IsValidLuhnNumber());
333+
Assert.Equal(expected, input.AlphaNumericToNumeric().IsValidLuhnNumber());
334+
Assert.Equal(expected, input.AlphaNumericToNumeric().AsSpan().IsValidLuhnNumber());
335335
}
336336

337337
/// <summary>
338-
/// Provides test data for the ComputeLuhnCheckDigit method in combination with ConvertAlphaNumericToNumeric.
338+
/// Provides test data for the ComputeLuhnCheckDigit method in combination with AlphaNumericToNumeric.
339339
/// </summary>
340340
/// <remarks>
341341
/// This method returns a collection of object arrays, where each array contains an input string and the
@@ -353,14 +353,14 @@ public void IsValidWithConvertTest(string input, bool expected)
353353
};
354354

355355
/// <summary>
356-
/// Tests the ComputeLuhnCheckDigit method in combination with ConvertAlphaNumericToNumeric.
356+
/// Tests the ComputeLuhnCheckDigit method in combination with AlphaNumericToNumeric.
357357
/// </summary>
358358
/// <param name="input">Input string</param>
359359
/// <param name="expected">Expected output</param>
360360
/// <remarks>
361361
/// This test checks if the ComputeLuhnCheckDigit method returns the expected check digit when it is given an
362362
/// alphanumeric string that represents a part of an ISIN without the check digit. The input string is first
363-
/// converted to a numeric string using the ConvertAlphaNumericToNumeric method, and then the
363+
/// converted to a numeric string using the AlphaNumericToNumeric method, and then the
364364
/// ComputeLuhnCheckDigit method is called with this numeric string. The test uses the Assert. Equal method from
365365
/// xUnit to check if the actual check digit matches the expected check digit.
366366
/// </remarks>
@@ -370,8 +370,8 @@ public void ComputeLuhnCheckDigit_WithConvertAlphaNumericToNumeric_ReturnsExpect
370370
string input,
371371
byte expected)
372372
{
373-
Assert.Equal(expected, input.ConvertAlphaNumericToNumeric().ComputeLuhnCheckDigit());
374-
Assert.Equal(expected, input.ConvertAlphaNumericToNumeric().AsSpan().ComputeLuhnCheckDigit());
373+
Assert.Equal(expected, input.AlphaNumericToNumeric().ComputeLuhnCheckDigit());
374+
Assert.Equal(expected, input.AlphaNumericToNumeric().AsSpan().ComputeLuhnCheckDigit());
375375
}
376376
}
377377
}

0 commit comments

Comments
 (0)