From 001f3f30cda22b1534d080cc2b2ebe8c7483bdb0 Mon Sep 17 00:00:00 2001 From: GCHQ 77703 Date: Sun, 26 Aug 2018 18:06:02 +0100 Subject: [PATCH] Remove multi-line operations --- src/core/operations/FromGeohash.mjs | 6 ++---- src/core/operations/ToGeohash.mjs | 8 +++---- test/tests/operations/FromGeohash.mjs | 30 +++++++++++++++++++++++---- test/tests/operations/ToGeohash.mjs | 30 +++++++++++++++++++++++---- 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/src/core/operations/FromGeohash.mjs b/src/core/operations/FromGeohash.mjs index 35967d85..ddf33257 100644 --- a/src/core/operations/FromGeohash.mjs +++ b/src/core/operations/FromGeohash.mjs @@ -34,10 +34,8 @@ class FromGeohash extends Operation { * @returns {string} */ run(input, args) { - return input.split("\n").map(line => { - const coords = geohash.decode(line); - return [coords.latitude, coords.longitude].join(","); - }).join("\n"); + const coords = geohash.decode(input); + return [coords.latitude, coords.longitude].join(","); } } diff --git a/src/core/operations/ToGeohash.mjs b/src/core/operations/ToGeohash.mjs index 682ad984..33ce0d91 100644 --- a/src/core/operations/ToGeohash.mjs +++ b/src/core/operations/ToGeohash.mjs @@ -41,11 +41,9 @@ class ToGeohash extends Operation { run(input, args) { const [precision] = args; - return input.split("\n").map(line => { - line = line.replace(/ /g, ""); - if (line === "") return ""; - return geohash.encode(...line.split(",").map(num => parseFloat(num)), precision); - }).join("\n"); + input = input.replace(/ /g, ""); + if (input === "") return ""; + return geohash.encode(...input.split(",").map(num => parseFloat(num)), precision); } } diff --git a/test/tests/operations/FromGeohash.mjs b/test/tests/operations/FromGeohash.mjs index bcaf4095..3dbe85ae 100644 --- a/test/tests/operations/FromGeohash.mjs +++ b/test/tests/operations/FromGeohash.mjs @@ -11,8 +11,8 @@ import TestRegister from "../../TestRegister"; TestRegister.addTests([ { name: "From Geohash", - input: "ww8p1r4t8\nww8p1r\nww8\nw", - expectedOutput: "37.83238649368286,112.55838632583618\n37.83416748046875,112.5604248046875\n37.265625,113.203125\n22.5,112.5", + input: "ww8p1r4t8", + expectedOutput: "37.83238649368286,112.55838632583618", recipeConfig: [ { op: "From Geohash", @@ -22,8 +22,30 @@ TestRegister.addTests([ }, { name: "From Geohash", - input: "w\n\nw\n\n\nw", - expectedOutput: "22.5,112.5\n0,0\n22.5,112.5\n0,0\n0,0\n22.5,112.5", + input: "ww8p1r", + expectedOutput: "37.83416748046875,112.5604248046875", + recipeConfig: [ + { + op: "From Geohash", + args: [], + }, + ], + }, + { + name: "From Geohash", + input: "ww8", + expectedOutput: "37.265625,113.203125", + recipeConfig: [ + { + op: "From Geohash", + args: [], + }, + ], + }, + { + name: "From Geohash", + input: "w", + expectedOutput: "22.5,112.5", recipeConfig: [ { op: "From Geohash", diff --git a/test/tests/operations/ToGeohash.mjs b/test/tests/operations/ToGeohash.mjs index a4dfa905..bf3e9858 100644 --- a/test/tests/operations/ToGeohash.mjs +++ b/test/tests/operations/ToGeohash.mjs @@ -11,8 +11,8 @@ import TestRegister from "../../TestRegister"; TestRegister.addTests([ { name: "To Geohash", - input: "37.8324,112.5584\n37.9324,-112.2584", - expectedOutput: "ww8p1r4t8\n9w8pv3ruj", + input: "37.8324,112.5584", + expectedOutput: "ww8p1r4t8", recipeConfig: [ { op: "To Geohash", @@ -22,8 +22,8 @@ TestRegister.addTests([ }, { name: "To Geohash", - input: "37.8324,112.5584\n\n\n", - expectedOutput: "ww8p1r4t8\n\n\n", + input: "37.9324,-112.2584", + expectedOutput: "9w8pv3ruj", recipeConfig: [ { op: "To Geohash", @@ -31,4 +31,26 @@ TestRegister.addTests([ }, ], }, + { + name: "To Geohash", + input: "37.8324,112.5584", + expectedOutput: "ww8", + recipeConfig: [ + { + op: "To Geohash", + args: [3], + }, + ], + }, + { + name: "To Geohash", + input: "37.9324,-112.2584", + expectedOutput: "9w8pv3rujxy5b99", + recipeConfig: [ + { + op: "To Geohash", + args: [15], + }, + ], + }, ]);