eleven / ocho Public

Clone
git clone https://amadan.net/eleven/ocho

Plain git — no account needed to clone.

Download

Download this file

1// Tests for the goes-to-eleven fader's pure math (no DOM — mountFader owns all
2// document references, so the module imports cleanly in Node).
3// node home/test/fader.test.mjs
4import assert from "node:assert/strict";
5import { faderLevel, faderValue } from "../web/static/fader.js";
6
7let failures = 0;
8async function test(name, fn) {
9 try {
10 await fn();
11 console.log("PASS " + name);
12 } catch (e) {
13 console.log("FAIL " + name + " — " + (e && e.message));
14 failures++;
15 }
16}
17
18await test("faderValue maps the slot run to 1..10 and clamps beyond it", () => {
19 assert.equal(faderValue(0), 1);
20 assert.equal(faderValue(0.86), 10, "the end of the run (RUN_END) is 10");
21 assert.equal(faderValue(1), 10, "past the run still clamps to 10 — eleven is not reachable by position");
22 assert.equal(faderValue(-0.5), 1, "before the slot clamps to 1");
23 assert.ok(faderValue(0.43) > 5 && faderValue(0.43) < 6.6, "mid-run lands mid-scale");
24});
25
26await test("faderLevel is silent below 5, hot by 10, and pressure adds strain", () => {
27 assert.equal(faderLevel("slide", 1, 0), 0);
28 assert.equal(faderLevel("slide", 5, 0), 0);
29 assert.ok(Math.abs(faderLevel("slide", 10, 0) - 5 / 6) < 1e-9);
30 assert.ok(faderLevel("slide", 10, 0.8) > faderLevel("slide", 10, 0), "the hold adds strain");
31});
32
33await test("faderLevel holds PAST 1.0 at the snap and through the whole build", () => {
34 assert.equal(faderLevel("snap", 10, 0), 1.2);
35 assert.equal(faderLevel("build", 10, 0), 1.2, "the volume stays AT eleven while building");
36});
37
38await test("faderLevel cuts to zero at done (silence before the confetti)", () => {
39 assert.equal(faderLevel("done", 10, 0), 0);
40});
41
42console.log(failures ? `\n${failures} FAILED` : "\nALL PASSED");
43process.exit(failures ? 1 : 0);
44