Fix To Base radix validation
This commit is contained in:
parent
d735496641
commit
dc08dc582d
@ -43,7 +43,7 @@ class ToBase extends Operation {
|
|||||||
throw new OperationError("Error: Input must be a number");
|
throw new OperationError("Error: Input must be a number");
|
||||||
}
|
}
|
||||||
const radix = args[0];
|
const radix = args[0];
|
||||||
if (radix < 2 || radix > 36) {
|
if (!Number.isInteger(radix) || radix < 2 || radix > 36) {
|
||||||
throw new OperationError("Error: Radix argument must be between 2 and 36");
|
throw new OperationError("Error: Radix argument must be between 2 and 36");
|
||||||
}
|
}
|
||||||
return input.toString(radix);
|
return input.toString(radix);
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import "./tests/AnalyseUUID.mjs";
|
|||||||
import "./tests/AlternatingCaps.mjs";
|
import "./tests/AlternatingCaps.mjs";
|
||||||
import "./tests/AvroToJSON.mjs";
|
import "./tests/AvroToJSON.mjs";
|
||||||
import "./tests/BaconCipher.mjs";
|
import "./tests/BaconCipher.mjs";
|
||||||
|
import "./tests/Base.mjs";
|
||||||
import "./tests/Base32.mjs";
|
import "./tests/Base32.mjs";
|
||||||
import "./tests/Base45.mjs";
|
import "./tests/Base45.mjs";
|
||||||
import "./tests/Base58.mjs";
|
import "./tests/Base58.mjs";
|
||||||
|
|||||||
33
tests/operations/tests/Base.mjs
Normal file
33
tests/operations/tests/Base.mjs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* Base conversion tests
|
||||||
|
*
|
||||||
|
* @author marko1olo
|
||||||
|
* @copyright Crown Copyright 2026
|
||||||
|
* @license Apache-2.0
|
||||||
|
*/
|
||||||
|
import TestRegister from "../../lib/TestRegister.mjs";
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
{
|
||||||
|
name: "To Base: base 2",
|
||||||
|
input: "63",
|
||||||
|
expectedOutput: "111111",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "To Base",
|
||||||
|
"args": [2]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "To Base: fractional radix",
|
||||||
|
input: "63",
|
||||||
|
expectedOutput: "Error: Radix argument must be between 2 and 36",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
"op": "To Base",
|
||||||
|
"args": [2.2]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
]);
|
||||||
Loading…
x
Reference in New Issue
Block a user