Merge da11800cac8e5396dd0b9826c01cdf617b961f04 into 4290ea753912378913b1f3f54e0fc5720afeda5d

This commit is contained in:
Suleyman Arif Uzun 2026-08-06 19:26:46 -07:00 committed by GitHub
commit e8f9ea31c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View File

@ -81,8 +81,15 @@ class LuhnChecksum extends Operation {
throw new OperationError("Error: Radix argument must be divisible by 2");
}
const checkSum = this.checksum(input, radix).toString(radix);
let checkDigit = this.checksum(input + "0", radix);
let checkSum, checkDigit;
try {
checkSum = this.checksum(input, radix).toString(radix);
checkDigit = this.checksum(input + "0", radix);
} catch (err) {
throw new OperationError(err.message);
}
checkDigit = checkDigit === 0 ? 0 : (radix - checkDigit);
checkDigit = checkDigit.toString(radix);

View File

@ -433,4 +433,15 @@ TestRegister.addTests([
},
],
},
{
name: "Luhn Checksum on invalid radix character",
input: "o",
expectedOutput: "Character: o is not valid in radix 4.",
recipeConfig: [
{
op: "Luhn Checksum",
args: [4]
},
],
},
]);