Merge da11800cac8e5396dd0b9826c01cdf617b961f04 into 4290ea753912378913b1f3f54e0fc5720afeda5d
This commit is contained in:
commit
e8f9ea31c1
@ -81,8 +81,15 @@ class LuhnChecksum extends Operation {
|
|||||||
throw new OperationError("Error: Radix argument must be divisible by 2");
|
throw new OperationError("Error: Radix argument must be divisible by 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkSum = this.checksum(input, radix).toString(radix);
|
let checkSum, checkDigit;
|
||||||
let checkDigit = this.checksum(input + "0", radix);
|
|
||||||
|
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 === 0 ? 0 : (radix - checkDigit);
|
||||||
checkDigit = checkDigit.toString(radix);
|
checkDigit = checkDigit.toString(radix);
|
||||||
|
|
||||||
|
|||||||
@ -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]
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user