Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/core/operations/FromBCD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class FromBCD extends Operation {
let output = "",
byteArray;

if (encoding === undefined)
throw new OperationError("Invalid encoding scheme");

// Normalise the input
switch (inputFormat) {
case "Nibbles":
Expand Down
3 changes: 3 additions & 0 deletions src/core/operations/ToBCD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class ToBCD extends Operation {
signed = args[2],
outputFormat = args[3];

if (encoding === undefined)
throw new OperationError("Invalid encoding scheme");

// Split input number up into separate digits
const digits = input.toFixed().split("");

Expand Down
22 changes: 22 additions & 0 deletions tests/operations/tests/BCD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,26 @@ TestRegister.addTests([
}
]
},
{
name: "To BCD: invalid (empty) encoding scheme",
input: "43",
expectedOutput: "Invalid encoding scheme",
recipeConfig: [
{
"op": "To BCD",
"args": ["", true, false, "Nibbles"]
}
]
},
{
name: "From BCD: invalid (empty) encoding scheme",
input: "0100 0011",
expectedOutput: "Invalid encoding scheme",
recipeConfig: [
{
"op": "From BCD",
"args": ["", true, false, "Nibbles"]
}
]
},
]);