testing started
This commit is contained in:
parent
1336ad6d63
commit
0bf774e6b0
7
deno.json
Normal file
7
deno.json
Normal file
@ -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"
|
||||
}
|
||||
}
|
9
deno.lock
Normal file
9
deno.lock
Normal file
@ -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"
|
||||
}
|
||||
}
|
81
store.js
81
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<string, SelectionUpdater>} */
|
||||
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<inState.Selection.Test.Plot.length; i++)
|
||||
{
|
||||
const plot = inState.Selection.Test.Plot[i];
|
||||
if(plot.Hz == hz)
|
||||
{
|
||||
inState.Selection.Freq = plot;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
Mark(inState)
|
||||
{
|
||||
const freq = inState.Selection.Freq;
|
||||
if(freq)
|
||||
{
|
||||
if(inState.Chan == "left" && freq.UserL)
|
||||
{
|
||||
inState.Selection.Mark = freq.UserL;
|
||||
return true;
|
||||
}
|
||||
else if(inState.Chan == "right" && freq.UserR)
|
||||
{
|
||||
inState.Selection.Mark = freq.UserR;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
/** @type {Reducer} */
|
||||
export function Reducer(inState, inAction)
|
||||
{
|
||||
const clone = {...inState};
|
||||
|
||||
switch(inAction.Name)
|
||||
{
|
||||
case "Test" :
|
||||
{
|
||||
|
||||
let selTest = clone.Tests[inAction.Data];
|
||||
let selFreq = undefined;
|
||||
let selMark = undefined;
|
||||
const column = ColumnLookup(clone.Freq);
|
||||
if(column)
|
||||
{
|
||||
let hz = column[0];
|
||||
let plot;
|
||||
for(let i=0; i<selTest.Plot.length; i++)
|
||||
{
|
||||
plot = selTest.Plot[i];
|
||||
if(plot.Hz == hz)
|
||||
{
|
||||
selFreq = plot;
|
||||
if(clone.Chan == "left" && selFreq.UserL)
|
||||
{
|
||||
selMark = selFreq.UserL;
|
||||
}
|
||||
else if(clone.Chan == "right" && selFreq.UserR)
|
||||
{
|
||||
selMark = selFreq.UserR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const freq = test.Plot[]
|
||||
//clone.Selection = {...clone.Selection, Test:clone.Tests[inAction.Data]}
|
||||
clone.Selection.Test = clone.Tests[inAction.Data];
|
||||
Update.Freq(clone);
|
||||
Update.Mark(clone);
|
||||
break;
|
||||
}
|
||||
case "Mark" :
|
||||
{
|
||||
if(clone.Test)
|
||||
{
|
||||
clone.Test.Plot
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return clone;
|
||||
}
|
61
store_test.js
Normal file
61
store_test.js
Normal file
@ -0,0 +1,61 @@
|
||||
import { assertEquals } from "https://deno.land/std@0.166.0/testing/asserts.ts";
|
||||
import { Initial, Reducer, ColumnMapping } from "./store.js";
|
||||
|
||||
const States = {
|
||||
list:[],
|
||||
get latest()
|
||||
{
|
||||
return this.list[this.list.length-1];
|
||||
},
|
||||
set latest(input)
|
||||
{
|
||||
this.list.push(input);
|
||||
}
|
||||
};
|
||||
|
||||
States.latest = Initial;
|
||||
|
||||
Deno.test("Initial State", async (t)=>
|
||||
{
|
||||
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);
|
||||
});
|
||||
|
||||
|
||||
|
||||
})
|
Loading…
Reference in New Issue
Block a user