2022-11-29 23:15:44 -05:00
|
|
|
import { assertEquals } from "https://deno.land/std@0.166.0/testing/asserts.ts";
|
2022-12-03 09:51:36 -05:00
|
|
|
import { Reducer, ColumnMapping, Congtiguous } from "../src/store.js";
|
2022-11-29 23:15:44 -05:00
|
|
|
|
2022-12-03 19:05:26 -05:00
|
|
|
let state = {
|
|
|
|
Chan: 0,
|
|
|
|
Freq: 1,
|
|
|
|
Stim: 20,
|
|
|
|
Live:
|
|
|
|
{
|
|
|
|
Test: undefined,
|
|
|
|
Freq: undefined,
|
|
|
|
Mark: undefined
|
|
|
|
},
|
|
|
|
Draw:
|
|
|
|
{
|
|
|
|
UserL:{Points:[], Paths:[]},
|
|
|
|
UserR:{Points:[], Paths:[]},
|
|
|
|
TestL:{Points:[], Paths:[]},
|
|
|
|
TestR:{Points:[], Paths:[]}
|
|
|
|
},
|
|
|
|
Tests: [
|
2022-11-29 23:15:44 -05:00
|
|
|
{
|
2022-12-03 19:05:26 -05:00
|
|
|
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 } }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2022-11-29 23:15:44 -05:00
|
|
|
|
2022-12-03 19:05:26 -05:00
|
|
|
|
|
|
|
Deno.test("Initialize", async(t)=>
|
|
|
|
{
|
|
|
|
await t.step("A test exists with 500 and 1k hz plots", ()=>
|
2022-11-29 23:15:44 -05:00
|
|
|
{
|
2022-12-03 19:05:26 -05:00
|
|
|
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);
|
2022-11-29 23:15:44 -05:00
|
|
|
});
|
|
|
|
|
2022-12-03 19:05:26 -05:00
|
|
|
await t.step("Dispatch Test, Freq, Stim, and Chan updates", ()=>
|
2022-11-29 23:15:44 -05:00
|
|
|
{
|
2022-12-03 19:05:26 -05:00
|
|
|
state = Reducer(state, {Name:"Test", Data:0});
|
|
|
|
state = Reducer(state, {Name:"Freq", Data:1});
|
|
|
|
state = Reducer(state, {Name:"Stim", Data:5});
|
|
|
|
state = Reducer(state, {Name:"Chan", Data:1});
|
|
|
|
});
|
2022-11-29 23:15:44 -05:00
|
|
|
|
2022-12-03 19:05:26 -05:00
|
|
|
await t.step("Freq, Stim, and Chan have the correct values", ()=>
|
|
|
|
{
|
|
|
|
assertEquals(state.Stim, 25);
|
|
|
|
assertEquals(state.Freq, 2);
|
|
|
|
assertEquals(state.Chan, 1);
|
|
|
|
});
|
2022-11-29 23:15:44 -05:00
|
|
|
|
2022-12-03 19:05:26 -05:00
|
|
|
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");
|
|
|
|
});
|
|
|
|
});
|
2022-11-29 23:15:44 -05:00
|
|
|
|
2022-12-03 19:05:26 -05:00
|
|
|
Deno.test("Make Marks", async(t)=>
|
|
|
|
{
|
|
|
|
await t.step("Dispatch Mark create", ()=>
|
|
|
|
{
|
|
|
|
state = Reducer(state, {Name:"Mark", Data:true});
|
|
|
|
});
|
2022-11-29 23:15:44 -05:00
|
|
|
|
2022-12-03 19:05:26 -05:00
|
|
|
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);
|
|
|
|
});
|
2022-11-29 23:15:44 -05:00
|
|
|
|
2022-12-03 19:05:26 -05:00
|
|
|
await t.step("Dispatch Mark delete", ()=>
|
|
|
|
{
|
|
|
|
state = Reducer(state, {Name:"Mark", Data:null});
|
|
|
|
});
|
2022-11-29 23:15:44 -05:00
|
|
|
|
2022-12-03 19:05:26 -05:00
|
|
|
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);
|
|
|
|
});
|
2022-11-29 23:15:44 -05:00
|
|
|
|
2022-12-03 19:05:26 -05:00
|
|
|
await t.step("Dispatch Freq, Stim, and Chan updates", ()=>
|
2022-12-03 09:51:36 -05:00
|
|
|
{
|
2022-12-03 19:05:26 -05:00
|
|
|
state = Reducer(state, {Name:"Freq", Data:1});
|
|
|
|
state = Reducer(state, {Name:"Stim", Data:5});
|
|
|
|
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);
|
|
|
|
});
|
2022-12-03 09:51:36 -05:00
|
|
|
|
2022-12-03 19:05:26 -05:00
|
|
|
await t.step("Dispatch Mark create", ()=>
|
|
|
|
{
|
|
|
|
state = Reducer(state, {Name:"Mark", Data:false});
|
2022-12-03 09:51:36 -05:00
|
|
|
});
|
|
|
|
|
2022-12-03 19:05:26 -05:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test("Contiguous Lines", ()=>
|
|
|
|
{
|
|
|
|
/** @type {import("../src/store.js").Test} */
|
|
|
|
const model = {
|
|
|
|
Name:"",
|
|
|
|
Plot:[
|
|
|
|
{Hz: 500, TestL: {Stim:30, Resp:true}, TestR: {Stim:35, Resp:true}, UserL:{Stim:20, Resp:true}},
|
|
|
|
{Hz: 1000, TestL: {Stim:40, Resp:true}, TestR: {Stim:45, Resp:true}, UserL:{Stim:30, Resp:true}},
|
|
|
|
{Hz: 2000, TestL: {Stim:40, Resp:true}, TestR: {Stim:45, Resp:true}, UserL:{Stim:30, Resp:false}},
|
|
|
|
{Hz: 3000, TestL: {Stim:30, Resp:true}, TestR: {Stim:35, Resp:true}, UserL:{Stim:20, Resp:true}},
|
|
|
|
{Hz: 4000, TestL: {Stim:40, Resp:true}, TestR: {Stim:45, Resp:true}, UserL:{Stim:30, Resp:true}},
|
|
|
|
{Hz: 4000, TestL: {Stim:50, Resp:true}, TestR: {Stim:55, Resp:true}, UserL:{Stim:40, Resp:true}}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
const {Points, Paths} = Congtiguous(model, 0, true);
|
|
|
|
assertEquals(Points.length, 6);
|
|
|
|
assertEquals(Paths.length, 2);
|
|
|
|
assertEquals(Paths[0].length, 2);
|
|
|
|
assertEquals(Paths[1].length, 3);
|
2022-11-29 23:15:44 -05:00
|
|
|
});
|