forked from grumdrig/jsfxr
-
Notifications
You must be signed in to change notification settings - Fork 26
/
tests.js
32 lines (31 loc) · 1.26 KB
/
tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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);
}
});