-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'artemisbot-feature-octal'
- Loading branch information
Showing
6 changed files
with
144 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,35 @@ const ByteRepr = { | |
}, | ||
|
||
|
||
/** | ||
* To Octal operation. | ||
* | ||
* @author Matt C [[email protected]] | ||
* @param {byteArray} input | ||
* @param {Object[]} args | ||
* @returns {string} | ||
*/ | ||
runToOct: function(input, args) { | ||
var delim = Utils.charRep[args[0] || "Space"]; | ||
return input.map(val => val.toString(8)).join(delim); | ||
}, | ||
|
||
|
||
/** | ||
* From Octal operation. | ||
* | ||
* @author Matt C [[email protected]] | ||
* @param {string} input | ||
* @param {Object[]} args | ||
* @returns {byteArray} | ||
*/ | ||
runFromOct: function(input, args) { | ||
var delim = Utils.charRep[args[0] || "Space"]; | ||
if (input.length === 0) return []; | ||
return input.split(delim).map(val => parseInt(val, 8)); | ||
}, | ||
|
||
|
||
/** | ||
* @constant | ||
* @default | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* ByteRepr tests. | ||
* | ||
* @author Matt C [[email protected]] | ||
* @copyright Crown Copyright 2017 | ||
* @license Apache-2.0 | ||
*/ | ||
import TestRegister from "../../TestRegister.js"; | ||
|
||
TestRegister.addTests([ | ||
{ | ||
name: "To Octal: nothing", | ||
input: "", | ||
expectedOutput: "", | ||
recipeConfig: [ | ||
{ | ||
"op": "To Octal", | ||
"args": ["Space"] | ||
} | ||
] | ||
}, | ||
{ | ||
name: "From Octal: nothing", | ||
input: "", | ||
expectedOutput: "", | ||
recipeConfig: [ | ||
{ | ||
"op": "From Octal", | ||
"args": ["Space"] | ||
} | ||
] | ||
}, | ||
{ | ||
name: "To Octal: hello world", | ||
input: "hello world", // [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100], | ||
expectedOutput: "150 145 154 154 157 40 167 157 162 154 144", | ||
recipeConfig: [ | ||
{ | ||
"op": "To Octal", | ||
"args": ["Space"] | ||
} | ||
] | ||
}, | ||
{ | ||
name: "From Octal: hello world", | ||
input: "150 145 154 154 157 40 167 157 162 154 144", | ||
expectedOutput: "hello world", | ||
recipeConfig: [ | ||
{ | ||
"op": "From Octal", | ||
"args": ["Space"] | ||
} | ||
] | ||
}, | ||
{ | ||
name: "To Octal: Γειά σου", | ||
input: "Γειά σου", //[206,147,206,181,206,185,206,172,32,207,131,206,191,207,133], | ||
expectedOutput: "316 223 316 265 316 271 316 254 40 317 203 316 277 317 205", | ||
recipeConfig: [ | ||
{ | ||
"op": "To Octal", | ||
"args": ["Space"] | ||
} | ||
] | ||
}, | ||
{ | ||
name: "From Octal: Γειά σου", | ||
input: "316 223 316 265 316 271 316 254 40 317 203 316 277 317 205", | ||
expectedOutput: "Γειά σου", | ||
recipeConfig: [ | ||
{ | ||
"op": "From Octal", | ||
"args": ["Space"] | ||
} | ||
] | ||
}, | ||
]); |