From 0bf774e6b03c3bb9e667b369b738eedd2dfd300a Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Mon, 28 Nov 2022 10:00:18 -0500 Subject: [PATCH] testing started --- deno.json | 7 +++++ deno.lock | 9 ++++++ store.js | 81 ++++++++++++++++++++++++++++----------------------- store_test.js | 61 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 36 deletions(-) create mode 100644 deno.json create mode 100644 deno.lock create mode 100644 store_test.js diff --git a/deno.json b/deno.json new file mode 100644 index 0000000..2303ea3 --- /dev/null +++ b/deno.json @@ -0,0 +1,7 @@ +{ + "tasks": + { + "fs": "deno run -A https://deno.land/std@0.166.0/http/file_server.ts", + "test": "deno test *_test.js --watch" + } +} \ No newline at end of file diff --git a/deno.lock b/deno.lock new file mode 100644 index 0000000..0ecd71f --- /dev/null +++ b/deno.lock @@ -0,0 +1,9 @@ +{ + "version": "2", + "remote": { + "https://deno.land/std@0.166.0/fmt/colors.ts": "9e36a716611dcd2e4865adea9c4bec916b5c60caad4cdcdc630d4974e6bb8bd4", + "https://deno.land/std@0.166.0/testing/_diff.ts": "a23e7fc2b4d8daa3e158fa06856bedf5334ce2a2831e8bf9e509717f455adb2c", + "https://deno.land/std@0.166.0/testing/_format.ts": "cd11136e1797791045e639e9f0f4640d5b4166148796cad37e6ef75f7d7f3832", + "https://deno.land/std@0.166.0/testing/asserts.ts": "1e340c589853e82e0807629ba31a43c84ebdcdeca910c4a9705715dfdb0f5ce8" + } +} diff --git a/store.js b/store.js index a5d368e..e9b45db 100644 --- a/store.js +++ b/store.js @@ -58,52 +58,61 @@ export const Initial = /** @typedef {{Name:"Test", Data:number}} ActionTest*/ /** @typedef {ActionMark|ActionTest} Action */ /** @typedef {(inState:State, inAction:Action)=>State} Reducer */ +/** @typedef {(inState:State)=>boolean} SelectionUpdater */ +/** @type {Record} */ +const Update = { + Freq(inState) + { + const column = ColumnMapping[inState.Freq]; + if(column && inState.Selection.Test) + { + const hz = column[0]; + inState.Selection.Freq = undefined; + for(let i=0; i +{ + const state = Initial; + + await t.step("Selections are empty", ()=> + { + assertEquals(state.Selection.Test, undefined); + assertEquals(state.Selection.Freq, undefined); + assertEquals(state.Selection.Mark, undefined); + }); + + await t.step("Frequency index maps to 1k hz", ()=> + { + assertEquals(state.Freq, 3); + assertEquals(ColumnMapping[state.Freq][0], 1000); + }); + + await t.step("The first test has its 2nd plot at 1k hz, and no user marks", ()=> + { + const plot = state.Tests[0].Plot[1]; + assertEquals(plot.Hz, 1000); + assertEquals(plot.UserL, undefined); + assertEquals(plot.UserR, undefined); + }); +}) + +Deno.test("Select Test", async (t)=> +{ + let state; + await t.step("dispatch action", ()=> + { + state = Reducer(Initial, {Name:"Test", Data:0}); + }); + + await t.step("check selections: test and freq, but no mark", ()=> + { + assertEquals(state.Selection.Test, state.Tests[0]); + assertEquals(state.Selection.Freq, state.Tests[0].Plot[1]); + assertEquals(state.Selection.Mark, undefined); + }); + + + +})