Luhn checksum tests
This commit is contained in:
parent
0e40daecb6
commit
54cb2d268b
@ -64,9 +64,15 @@ class LuhnChecksum extends Operation {
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
|
||||
if (!(input)) return "0";
|
||||
|
||||
const checkSum = this.checksum(input).toString();
|
||||
|
||||
let checkDigit = this.checksum(input+"0");
|
||||
|
||||
checkDigit = (checkDigit === 0 ? 0 : (10-checkDigit)).toString();
|
||||
|
||||
return "Checksum: " + checkSum + "\n\nCheckdigit: " + checkDigit + "\n\nLuhn Validated String: "+ input + checkDigit;
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,29 @@ TestRegister.addTests([
|
||||
{
|
||||
name: "Luhn Checksum on standard data",
|
||||
input: "35641709012469",
|
||||
expectedOutput: "7",
|
||||
expectedOutput: "Checksum: 7\n\nCheckdigit: 0\n\nLuhn Validated String: 356417090124690",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Luhn Checksum",
|
||||
args: []
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Luhn Checksum on standard data 2",
|
||||
input: "896101950123440000",
|
||||
expectedOutput: "Checksum: 5\n\nCheckdigit: 1\n\nLuhn Validated String: 8961019501234400001",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Luhn Checksum",
|
||||
args: []
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Luhn Checksum on standard data 3",
|
||||
input: "35726908971331",
|
||||
expectedOutput: "Checksum: 6\n\nCheckdigit: 7\n\nLuhn Validated String: 357269089713317",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Luhn Checksum",
|
||||
|
Loading…
x
Reference in New Issue
Block a user