Added word count operation

This commit is contained in:
sw5678 2025-05-12 14:03:07 +01:00
parent 7ecf8dfdaa
commit d726f1e1df
4 changed files with 236 additions and 1 deletions

View file

@ -170,6 +170,7 @@ import "./tests/JA3Fingerprint.mjs";
import "./tests/JA3SFingerprint.mjs";
import "./tests/HASSH.mjs";
import "./tests/JSONtoYAML.mjs";
import "./tests/WordCount.mjs";
// Cannot test operations that use the File type yet
// import "./tests/SplitColourChannels.mjs";

View file

@ -0,0 +1,117 @@
/**
* @author sw5678
* @copyright Crown Copyright 2023
* @license Apache-2.0
*/
import TestRegister from "../../lib/TestRegister.mjs";
TestRegister.addTests([
{
"name": "Word Count: Empty test 1",
"input": "",
"expectedOutput": "WORD,COUNT\nTOTAL,0",
"recipeConfig": [
{
"op": "Word Count",
"args": ["Space", true, "Alphabetical"],
},
],
},
{
"name": "Word Count: Empty test 2",
"input": "",
"expectedOutput": "WORD,COUNT\nTOTAL,0",
"recipeConfig": [
{
"op": "Word Count",
"args": ["Space", true, "Count"],
},
],
},
{
"name": "Word Count: Empty test 3",
"input": "",
"expectedOutput": "WORD,COUNT\n",
"recipeConfig": [
{
"op": "Word Count",
"args": ["Space", false, "Alphabetical"],
},
],
},
{
"name": "Word Count: Empty test 4",
"input": "",
"expectedOutput": "WORD,COUNT\n",
"recipeConfig": [
{
"op": "Word Count",
"args": ["Space", false, "Count"],
},
],
},
{
"name": "Word Count: Count test 1",
"input": "Hello world. Hello. \n\n World, ''!@£$%^&*()_+=-[]{};'|:/.,<>? world",
"expectedOutput": "WORD,COUNT\nhello,2\nworld,3\nTOTAL,5",
"recipeConfig": [
{
"op": "Word Count",
"args": ["Space", true, "Alphabetical"],
},
],
},
{
"name": "Word Count: Count test 2",
"input": "Hello world. Hello. \n\n World, ''!@£$%^&*()_+=-[]{};'|:/.,<>? world",
"expectedOutput": "WORD,COUNT\nworld,3\nhello,2\nTOTAL,5",
"recipeConfig": [
{
"op": "Word Count",
"args": ["Space", true, "Count"],
},
],
},
{
"name": "Word Count: Count test 3",
"input": "Hello world. Hello. \n\n World, ''!@£$%^&*()_+=-[]{};'|:/.,<>? world",
"expectedOutput": "WORD,COUNT\nhello,2\nworld,3\n",
"recipeConfig": [
{
"op": "Word Count",
"args": ["Space", false, "Alphabetical"],
},
],
},
{
"name": "Word Count: Count test 4",
"input": "Hello world. Hello. \n\n World, ''!@£$%^&*()_+=-[]{};'|:/.,<>? world",
"expectedOutput": "WORD,COUNT\nworld,3\nhello,2\n",
"recipeConfig": [
{
"op": "Word Count",
"args": ["Space", false, "Count"],
},
],
},
{
"name": "Word Count: Different delimiter test",
"input": "Hello, World\nhello, world \n''!@£$%^&*()_+=-[]{};'|:/.,<>? world",
"expectedOutput": "WORD,COUNT\nworld,3\nhello,2\n",
"recipeConfig": [
{
"op": "Word Count",
"args": ["Comma", false, "Count"],
},
],
}
]);