From af51090ebba6c6481d79d3bda78b29b6fe1f8420 Mon Sep 17 00:00:00 2001 From: Matt C Date: Tue, 3 Apr 2018 23:29:47 +0100 Subject: [PATCH] Added rotate ESM tests --- test/index.mjs | 1 + test/tests/operations/Rotate.mjs | 214 +++++++++++++++++++++++++++++++ 2 files changed, 215 insertions(+) create mode 100644 test/tests/operations/Rotate.mjs diff --git a/test/index.mjs b/test/index.mjs index bd3f27ba3b..82b3c08161 100644 --- a/test/index.mjs +++ b/test/index.mjs @@ -45,6 +45,7 @@ import "./tests/operations/Base64"; // import "./tests/operations/NetBIOS.js"; // import "./tests/operations/OTP.js"; // import "./tests/operations/Regex.js"; +import "./tests/operations/Rotate.mjs"; // import "./tests/operations/StrUtils.js"; // import "./tests/operations/SeqUtils.js"; diff --git a/test/tests/operations/Rotate.mjs b/test/tests/operations/Rotate.mjs new file mode 100644 index 0000000000..e48373d4ef --- /dev/null +++ b/test/tests/operations/Rotate.mjs @@ -0,0 +1,214 @@ +/** + * Base64 tests. + * + * @author Matt C [matt@artemisbot.uk] + * + * @copyright Crown Copyright 2018 + * @license Apache-2.0 + */ +import TestRegister from "../../TestRegister"; + +TestRegister.addTests([ + { + name: "Rotate left: nothing", + input: "", + expectedOutput: "", + recipeConfig: [ + { + op: "From Hex", + args: ["Space"] + }, + { + op: "Rotate left", + args: [1, false], + }, + { + op: "To Hex", + args: ["Space"] + } + ], + }, + { + name: "Rotate left: normal", + input: "61 62 63 31 32 33", + expectedOutput: "c2 c4 c6 62 64 66", + recipeConfig: [ + { + op: "From Hex", + args: ["Space"] + }, + { + op: "Rotate left", + args: [1, false], + }, + { + op: "To Hex", + args: ["Space"] + } + ], + }, + { + name: "Rotate left: carry", + input: "61 62 63 31 32 33", + expectedOutput: "85 89 8c c4 c8 cd", + recipeConfig: [ + { + op: "From Hex", + args: ["Space"] + }, + { + op: "Rotate left", + args: [2, true], + }, + { + op: "To Hex", + args: ["Space"] + } + ], + }, + { + name: "Rotate right: nothing", + input: "", + expectedOutput: "", + recipeConfig: [ + { + op: "From Hex", + args: ["Space"] + }, + { + op: "Rotate right", + args: [1, false], + }, + { + op: "To Hex", + args: ["Space"] + } + ], + }, + { + name: "Rotate right: normal", + input: "61 62 63 31 32 33", + expectedOutput: "b0 31 b1 98 19 99", + recipeConfig: [ + { + op: "From Hex", + args: ["Space"] + }, + { + op: "Rotate right", + args: [1, false], + }, + { + op: "To Hex", + args: ["Space"] + } + ], + }, + { + name: "Rotate right: carry", + input: "61 62 63 31 32 33", + expectedOutput: "d8 58 98 cc 4c 8c", + recipeConfig: [ + { + op: "From Hex", + args: ["Space"] + }, + { + op: "Rotate right", + args: [2, true], + }, + { + op: "To Hex", + args: ["Space"] + } + ], + }, + { + name: "ROT13: nothing", + input: "", + expectedOutput: "", + recipeConfig: [ + { + op: "ROT13", + args: [true, true, 13] + }, + ], + }, + { + name: "ROT13: normal", + input: "The Quick Brown Fox Jumped Over The Lazy Dog.", + expectedOutput: "Gur Dhvpx Oebja Sbk Whzcrq Bire Gur Ynml Qbt.", + recipeConfig: [ + { + op: "ROT13", + args: [true, true, 13] + }, + ], + }, + { + name: "ROT13: full loop", + input: "The Quick Brown Fox Jumped Over The Lazy Dog.", + expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog.", + recipeConfig: [ + { + op: "ROT13", + args: [true, true, 26] + }, + ], + }, + { + name: "ROT13: lowercase only", + input: "The Quick Brown Fox Jumped Over The Lazy Dog.", + expectedOutput: "Tur Qhvpx Bebja Fbk Jhzcrq Oire Tur Lnml Dbt.", + recipeConfig: [ + { + op: "ROT13", + args: [true, false, 13] + }, + ], + }, + { + name: "ROT13: uppercase only", + input: "The Quick Brown Fox Jumped Over The Lazy Dog.", + expectedOutput: "Ghe Duick Orown Sox Wumped Bver Ghe Yazy Qog.", + recipeConfig: [ + { + op: "ROT13", + args: [false, true, 13] + }, + ], + }, + { + name: "ROT47: nothing", + input: "", + expectedOutput: "", + recipeConfig: [ + { + op: "ROT47", + args: [47] + }, + ], + }, + { + name: "ROT47: normal", + input: "The Quick Brown Fox Jumped Over The Lazy Dog.", + expectedOutput: "%96 \"F:4< qC@H? u@I yF>A65 ~G6C %96 {2KJ s@8]", + recipeConfig: [ + { + op: "ROT47", + args: [47] + }, + ], + }, + { + name: "ROT47: full loop", + input: "The Quick Brown Fox Jumped Over The Lazy Dog.", + expectedOutput: "The Quick Brown Fox Jumped Over The Lazy Dog.", + recipeConfig: [ + { + op: "ROT47", + args: [94] + }, + ], + }, +]);