From a4ab8a79dfd8288662bd16a2d1911964e23d57af Mon Sep 17 00:00:00 2001 From: Seth Trowbridge Date: Sat, 3 Dec 2022 21:40:23 -0500 Subject: [PATCH] use ranges for tone params --- .vscode/settings.json | 7 ++- src/app.js | 4 +- src/store.js | 119 ++++++++++++++++++------------------------ test/store_test.js | 107 ++++++++++++++++--------------------- 4 files changed, 103 insertions(+), 134 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 8675ad5..f393838 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,9 @@ { "deno.enable": true, - "deno.unstable": true + "deno.unstable": true, + "deno.codeLens.testArgs": [ + "--allow-all", + "--no-check", + "--no-lock" + ] } \ No newline at end of file diff --git a/src/app.js b/src/app.js index f7d87ee..be31cc0 100644 --- a/src/app.js +++ b/src/app.js @@ -90,8 +90,8 @@ const Deep =()=> { const [State, Dispatch] = React.useContext(StoreContext); return html` - <${UI.Button} onClick=${()=>Dispatch({Name:"Stim", Data:5})}> - ${State.Stim} + <${UI.Button} onClick=${()=>Dispatch({Name:"Stim", Data:1})} disabled=${State.Stim.Value == State.Stim.Max}> + ${State.Stim.Value} `; } diff --git a/src/store.js b/src/store.js index 8344317..96113fd 100644 --- a/src/store.js +++ b/src/store.js @@ -26,45 +26,24 @@ export const ColumnLookup =(inFrequency)=> }; - -/** @typedef {{Min:number, Max:number}} Limit */ -/** @typedef {(inValue:number, inLimit:Limit)=>number} LimitUse */ -/** @type {Record} */ -export const ToneLimit = -{ - Freq: { Min: 0, Max: ColumnMapping.length-1 }, - Stim: { Min: -10, Max: 120 }, - Chan: { Min: 0, Max: 1}, -}; -/** @type {LimitUse} */ -export const LimitCut =(inValue, inLimit)=> -{ - if(inValue < inLimit.Min){ return inLimit.Min; } - else if(inValue > inLimit.Max) { return inLimit.Max; } - else{ return inValue; } -}; -/** @type {LimitUse} */ -export const LimitMap =(inValue, inLimit)=>(inValue-inLimit.Min)/(inLimit.Max-inLimit.Min); - - /** @type {(freq:TestFrequency, chan:number, user:boolean)=>TestFrequencySample|undefined} */ export const MarkGet =(freq, chan, user)=> freq[/** @type {"UserL"|"UserR"|"TestL"|"TestR"} */ (`${user ? "User" : "Test"}${chan ? "R" : "L"}`)]; /** @type {(freq:TestFrequency, chan:number, mark:TestFrequencySample|undefined)=>TestFrequencySample|undefined} */ export const MarkSet =(freq, chan, mark)=> freq[ chan ? "UserR" : "UserL" ] = mark; - +/** @typedef {{Min:number, Max:number, Value:number, Step:number}} Range */ /** @typedef {{Stim:number, Resp:boolean}} TestFrequencySample */ /** @typedef {{Hz:number, TestL:TestFrequencySample, TestR:TestFrequencySample, UserL?:TestFrequencySample, UserR?:TestFrequencySample}} TestFrequency */ /** @typedef {{Name:string, Plot:Array}} Test */ /** @typedef {{Test?:Test, Freq?:TestFrequency, Mark?:TestFrequencySample}} Context */ -/** @typedef {{Chan:number, Freq:number, Stim:number, Live:Context, Draw:{UserL:DrawGroup, UserR:DrawGroup, TestL:DrawGroup, TestR:DrawGroup}, Tests:Array}} State */ +/** @typedef {{Chan:Range, Freq:Range, Stim:Range, Live:Context, Draw:{UserL:DrawGroup, UserR:DrawGroup, TestL:DrawGroup, TestR:DrawGroup}, Tests:Array}} State */ /** @type {State} */ export const Initial = { - Chan: 0, - Freq: 3, - Stim: 30, + Chan: { Min:0, Max:1, Value:0, Step:1 }, + Freq: { Min:2, Max:8, Value:2, Step:1 }, + Stim: { Min:-10, Max:120, Value:30, Step:5 }, Live: { Test: undefined, @@ -90,34 +69,6 @@ export const Initial = ] }; -/* -const minified = -[ - 1, - [ - [20, 30, 50, 40, 60, 80],[20, 30, 50, 40, 60, 80] - ] -]; -const Expand =(inMin)=> -{ - const outTests = []; - const inFreq = inMin[0]; - for(let i=1; i, Paths:Array>}} DrawGroup */ /** @typedef {{Left:DrawGroup, Right:DrawGroup}} DrawChart */ /** @typedef {{User?:DrawChart, Test?:DrawChart}} DrawTest */ -/** @type {(inTest:Test, inChannel:number, inIsUser:boolean)=>DrawGroup} */ -export function Congtiguous(inTest, inChannel, inIsUser) +/** @type {(inTest:Test, inChan:number, inStim:Range, inIsUser:boolean)=>DrawGroup} */ +export function Congtiguous(inTest, inChan, inStim, inIsUser) { /** @type {DrawGroup} */ const output = {Points:[], Paths:[]}; @@ -177,7 +128,7 @@ export function Congtiguous(inTest, inChannel, inIsUser) for(let i=0; i tone.Max){ tone.Value = tone.Max; } + clone[Name] = tone; if(Name != "Stim") { Update.Freq(clone); @@ -251,4 +206,32 @@ export function Reducer(inState, inAction) } return clone; -} \ No newline at end of file +} + +/* +const minified = +[ + 1, + [ + [20, 30, 50, 40, 60, 80],[20, 30, 50, 40, 60, 80] + ] +]; +const Expand =(inMin)=> +{ + const outTests = []; + const inFreq = inMin[0]; + for(let i=1; i { + + await t.step("Tone Parameters Initialized", ()=> + { + assertEquals(state.Chan.Value, 0); + assertEquals(state.Freq.Value, 2); + assertEquals(state.Stim.Value, 30); + }); + await t.step("A test exists with 500 and 1k hz plots", ()=> { assertEquals(state.Tests.length > 0, true); @@ -45,28 +25,38 @@ Deno.test("Initialize", async(t)=> await t.step("Dispatch Test, Freq, Stim, and Chan updates", ()=> { 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}); + state = Reducer(state, {Name:"Freq", Data:1}); + state = Reducer(state, {Name:"Stim", 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); + assertEquals(state.Chan.Value, 1); + assertEquals(state.Freq.Value, 3); + assertEquals(state.Stim.Value, 35); }); 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.Freq.Hz, ColumnMapping[state.Freq.Value][0]); assertEquals(state.Live.Mark, undefined, "(User) Mark is undefined"); }); }); Deno.test("Make Marks", async(t)=> { + let state = {...Initial}; + + await t.step("Tone Parameters Initialized", ()=> + { + assertEquals(state.Chan.Value, 0); + assertEquals(state.Freq.Value, 2); + assertEquals(state.Stim.Value, 30); + }); + await t.step("Dispatch Mark create", ()=> { state = Reducer(state, {Name:"Mark", Data:true}); @@ -74,36 +64,18 @@ Deno.test("Make Marks", async(t)=> 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.Freq.UserL !== undefined, true, `there will be a user mark for the left channel`); + assertEquals(state.Live.Freq.UserR === undefined, true, `but not the right`); + assertEquals(state.Live.Mark.Stim, state.Stim.Value); 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:"Test", Data:0}); 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); + state = Reducer(state, {Name:"Stim", Data:1}); + state = Reducer(state, {Name:"Chan", Data:1}); }); await t.step("Dispatch Mark create", ()=> @@ -114,10 +86,19 @@ Deno.test("Make Marks", async(t)=> 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.Freq.UserL !== undefined, true, `and the left`); + assertEquals(state.Live.Mark.Stim, state.Stim.Value); assertEquals(state.Live.Mark.Resp, false); }); + + await t.step("Live context values are correct", ()=> + { + assertEquals(state.Live.Test, state.Tests[0]); + assertEquals(state.Live.Freq.Hz, ColumnMapping[state.Freq.Value][0]); + assertEquals(state.Live.Mark.Stim, state.Stim.Value); + }); + + console.log(state.Draw); }); Deno.test("Contiguous Lines", ()=> @@ -135,7 +116,7 @@ Deno.test("Contiguous Lines", ()=> ] } - const {Points, Paths} = Congtiguous(model, 0, true); + const {Points, Paths} = Congtiguous(model, 0, Initial.Stim, true); assertEquals(Points.length, 6); assertEquals(Paths.length, 2); assertEquals(Paths[0].length, 2);