forked from grumdrig/jsfxr
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple tests to verify function tables.
- Loading branch information
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
var test = require("tape"); | ||
var j = require("./sfxr"); | ||
|
||
test('test converting values from sliders to domain and back again', async function (t) { | ||
const keys = Object.keys(j.convert.sliders); | ||
for (k in j.convert.sliders) { | ||
//for (k in {"p_lpf_freq": true}) { | ||
let tolerance = 0.0001; | ||
// if (["p_arp_speed", "p_repeat_speed"].indexOf(k) != -1) continue; | ||
// special case these because the rounding in the slider conversion destroys information | ||
if (["p_arp_speed", "p_repeat_speed"].indexOf(k) != -1) tolerance = 0.004; | ||
const start = j.parameters.signed.indexOf(k) == -1 ? 0 : -1; | ||
const table = []; | ||
for (i=start; i<=1; i+=0.01) { | ||
const r1 = j.convert.sliders[k](i); | ||
const r2 = j.convert.domain[k](r1); | ||
const r3 = j.convert.domain_inverse[k](r2); | ||
const r4 = j.convert.sliders_inverse[k](r3); | ||
table[i] = {"slider": r1, "slider_inv": j.convert.sliders_inverse[k](r1), "domain": r2, "domain_inv": r3, "round_trip": r4}; | ||
//console.log(i, r1, j.convert.sliders_inverse[k](r1), r2, r3, r4); | ||
var pass = Math.abs(i - r4) < tolerance; | ||
if (!pass) { | ||
console.table(table); | ||
} | ||
t.ok(pass, k + " at " + i + " =~ " + r4); | ||
if (!pass) { | ||
process.exit(); | ||
} | ||
} | ||
console.table(table); | ||
} | ||
}); |