cleanup
This commit is contained in:
parent
a602bfd295
commit
b8d373314a
@ -2,6 +2,6 @@
|
|||||||
"tasks":
|
"tasks":
|
||||||
{
|
{
|
||||||
"fs": "deno run -A --no-lock https://deno.land/std@0.166.0/http/file_server.ts",
|
"fs": "deno run -A --no-lock https://deno.land/std@0.166.0/http/file_server.ts",
|
||||||
"test": "deno test 'store_test.js' --no-lock"
|
"test": "deno test test/store_test.js --no-lock --watch"
|
||||||
}
|
}
|
||||||
}
|
}
|
110
store_test.js
110
store_test.js
@ -1,110 +0,0 @@
|
|||||||
import { assertEquals } from "https://deno.land/std@0.166.0/testing/asserts.ts";
|
|
||||||
import { Initial, Reducer, ColumnMapping } from "./store.js";
|
|
||||||
|
|
||||||
const States = {
|
|
||||||
list:[Initial],
|
|
||||||
get latest()
|
|
||||||
{
|
|
||||||
return this.list[this.list.length-1];
|
|
||||||
},
|
|
||||||
set latest(input)
|
|
||||||
{
|
|
||||||
this.list.push(input);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Deno.test("Initial State", async (t)=>
|
|
||||||
{
|
|
||||||
await t.step("Selections are empty", ()=>
|
|
||||||
{
|
|
||||||
assertEquals(States.latest.Live.Test, undefined);
|
|
||||||
assertEquals(States.latest.Live.Freq, undefined);
|
|
||||||
assertEquals(States.latest.Live.Mark, undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
await t.step("Frequency index maps to 1k hz", ()=>
|
|
||||||
{
|
|
||||||
assertEquals(States.latest.Freq, 3);
|
|
||||||
assertEquals(ColumnMapping[States.latest.Freq][0], 1000);
|
|
||||||
});
|
|
||||||
|
|
||||||
await t.step("The first test has its 2nd plot at 1k hz", ()=>
|
|
||||||
{
|
|
||||||
const plot = States.latest.Tests[0].Plot[1];
|
|
||||||
assertEquals(plot.Hz, 1000);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
|
|
||||||
Deno.test("Select First Test", async (t)=>
|
|
||||||
{
|
|
||||||
await t.step("dispatch action", ()=>
|
|
||||||
{
|
|
||||||
States.latest = Reducer(States.latest, {Name:"Test", Data:0});
|
|
||||||
});
|
|
||||||
|
|
||||||
await t.step("check selections: test and freq, but no mark", ()=>
|
|
||||||
{
|
|
||||||
const s = States.latest;
|
|
||||||
assertEquals(s.Live.Test, s.Tests[0]);
|
|
||||||
assertEquals(s.Live.Freq, s.Tests[0].Plot[1]);
|
|
||||||
assertEquals(s.Live.Mark, undefined);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
Deno.test("Make Marks", async (t)=>
|
|
||||||
{
|
|
||||||
let s;
|
|
||||||
await t.step("Left channel selected", ()=>
|
|
||||||
{
|
|
||||||
assertEquals(States.latest.Chan, 0);
|
|
||||||
});
|
|
||||||
await t.step("Dispatch Mark action", ()=>
|
|
||||||
{
|
|
||||||
States.latest = Reducer(States.latest, {Name:"Mark", Data:true});
|
|
||||||
});
|
|
||||||
s = States.latest;
|
|
||||||
|
|
||||||
await t.step("Check selections: test, freq, and mark", ()=>
|
|
||||||
{
|
|
||||||
assertEquals(s.Live.Test, s.Tests[0]);
|
|
||||||
assertEquals(s.Live.Freq, s.Tests[0].Plot[1]);
|
|
||||||
assertEquals(s.Live.Mark, s.Tests[0].Plot[1].UserL);
|
|
||||||
});
|
|
||||||
|
|
||||||
await t.step("Check marked value", ()=>
|
|
||||||
{
|
|
||||||
assertEquals(s.Live.Mark.Stim, s.Stim);
|
|
||||||
assertEquals(s.Live.Mark.Resp, true);
|
|
||||||
});
|
|
||||||
|
|
||||||
await t.step("Dispatch Mark delete action", ()=>
|
|
||||||
{
|
|
||||||
States.latest = Reducer(States.latest, {Name:"Mark", Data:null});
|
|
||||||
});
|
|
||||||
s = States.latest;
|
|
||||||
|
|
||||||
await t.step("Check marked value", ()=>
|
|
||||||
{
|
|
||||||
assertEquals(States.latest.Live.Mark, undefined);
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
Deno.test("Update Tone State", async(t)=>
|
|
||||||
{
|
|
||||||
await t.step("all three", ()=>
|
|
||||||
{
|
|
||||||
States.latest = Reducer(States.latest, {Name:"Freq", Data:2});
|
|
||||||
States.latest = Reducer(States.latest, {Name:"Stim", Data:25});
|
|
||||||
States.latest = Reducer(States.latest, {Name:"Chan", Data:1});
|
|
||||||
});
|
|
||||||
|
|
||||||
await t.step("check tone values", ()=>
|
|
||||||
{
|
|
||||||
|
|
||||||
assertEquals(States.latest.Stim, 25);
|
|
||||||
assertEquals(States.latest.Freq, 2);
|
|
||||||
assertEquals(States.latest.Chan, 1);
|
|
||||||
});
|
|
||||||
});
|
|
117
test/store_test.js
Normal file
117
test/store_test.js
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
import { assertEquals } from "https://deno.land/std@0.166.0/testing/asserts.ts";
|
||||||
|
import { Reducer, ColumnMapping } from "../src/store.js";
|
||||||
|
|
||||||
|
Deno.test("Store", async(t)=>
|
||||||
|
{
|
||||||
|
let state = {
|
||||||
|
Chan: 0,
|
||||||
|
Freq: 3,
|
||||||
|
Stim: 30,
|
||||||
|
Live:
|
||||||
|
{
|
||||||
|
Test: undefined,
|
||||||
|
Freq: undefined,
|
||||||
|
Mark: undefined
|
||||||
|
},
|
||||||
|
Tests: [
|
||||||
|
{
|
||||||
|
Name: "Patient A Asymmetric Notch",
|
||||||
|
Plot:
|
||||||
|
[
|
||||||
|
{ Hz: 500, TestL: { Stim: 30, Resp: true }, TestR: { Stim: 50, Resp: true } },
|
||||||
|
{ Hz: 1000, TestL: { Stim: 50, Resp: true }, TestR: { Stim: 55, Resp: true } }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
await t.step("Initialize", async(t)=>
|
||||||
|
{
|
||||||
|
await t.step("A test exists with 500 and 1k hz plots", ()=>
|
||||||
|
{
|
||||||
|
assertEquals(state.Tests.length > 0, true);
|
||||||
|
const test = state.Tests[0];
|
||||||
|
assertEquals(test.Plot.length > 1, true);
|
||||||
|
assertEquals(test.Plot[0].Hz, 500);
|
||||||
|
assertEquals(test.Plot[1].Hz, 1000);
|
||||||
|
});
|
||||||
|
|
||||||
|
await t.step("Dispatch Test, Freq, Stim, and Chan updates", ()=>
|
||||||
|
{
|
||||||
|
state = Reducer(state, {Name:"Test", Data:0});
|
||||||
|
state = Reducer(state, {Name:"Freq", Data:2});
|
||||||
|
state = Reducer(state, {Name:"Stim", Data:25});
|
||||||
|
state = Reducer(state, {Name:"Chan", Data:1});
|
||||||
|
});
|
||||||
|
|
||||||
|
await t.step("Freq, Stim, and Chan have the correct values", ()=>
|
||||||
|
{
|
||||||
|
assertEquals(state.Stim, 25);
|
||||||
|
assertEquals(state.Freq, 2);
|
||||||
|
assertEquals(state.Chan, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
await t.step("Live context values are correct", ()=>
|
||||||
|
{
|
||||||
|
assertEquals(state.Live.Test, state.Tests[0]);
|
||||||
|
assertEquals(state.Live.Freq.Hz, ColumnMapping[state.Freq][0]);
|
||||||
|
assertEquals(state.Live.Mark, undefined, "(User) Mark is undefined");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await t.step("Make Marks", async(t)=>
|
||||||
|
{
|
||||||
|
await t.step("Dispatch Mark create", ()=>
|
||||||
|
{
|
||||||
|
state = Reducer(state, {Name:"Mark", Data:true});
|
||||||
|
});
|
||||||
|
|
||||||
|
await t.step("Check marked value", ()=>
|
||||||
|
{
|
||||||
|
assertEquals(state.Live.Freq.UserR !== undefined, true, `there will be a user mark for the right channel`);
|
||||||
|
assertEquals(state.Live.Freq.UserL === undefined, true, `the left channel user mark will be undefined`);
|
||||||
|
assertEquals(state.Live.Mark.Stim, state.Stim);
|
||||||
|
assertEquals(state.Live.Mark.Resp, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
await t.step("Dispatch Mark delete", ()=>
|
||||||
|
{
|
||||||
|
state = Reducer(state, {Name:"Mark", Data:null});
|
||||||
|
});
|
||||||
|
|
||||||
|
await t.step("Check marked value", ()=>
|
||||||
|
{
|
||||||
|
assertEquals(state.Live.Freq.UserR === undefined, true);
|
||||||
|
assertEquals(state.Live.Freq.UserL === undefined, true);
|
||||||
|
assertEquals(state.Live.Mark, undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
await t.step("Dispatch Freq, Stim, and Chan updates", ()=>
|
||||||
|
{
|
||||||
|
state = Reducer(state, {Name:"Freq", Data:3});
|
||||||
|
state = Reducer(state, {Name:"Stim", Data:65});
|
||||||
|
state = Reducer(state, {Name:"Chan", Data:0});
|
||||||
|
});
|
||||||
|
|
||||||
|
await t.step("Live context values are correct", ()=>
|
||||||
|
{
|
||||||
|
assertEquals(state.Live.Test, state.Tests[0]);
|
||||||
|
assertEquals(state.Live.Freq.Hz, ColumnMapping[state.Freq][0]);
|
||||||
|
assertEquals(state.Live.Mark, undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
await t.step("Dispatch Mark create", ()=>
|
||||||
|
{
|
||||||
|
state = Reducer(state, {Name:"Mark", Data:false});
|
||||||
|
});
|
||||||
|
|
||||||
|
await t.step("Check marked value", ()=>
|
||||||
|
{
|
||||||
|
assertEquals(state.Live.Freq.UserR === undefined, true, `there will be a user mark for the right channel`);
|
||||||
|
assertEquals(state.Live.Freq.UserL !== undefined, true, `the left channel user mark will be undefined`);
|
||||||
|
assertEquals(state.Live.Mark.Stim, state.Stim);
|
||||||
|
assertEquals(state.Live.Mark.Resp, false);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user