#!/usr/bin/env node
// verify-how-noise-cancelling-works.mjs
// Recomputes EVERY number shown on /strata/how-noise-cancelling-works/ from
// c = 343 m/s and the interference algebra alone. One line per check.
// Exit 0 iff all pass. Two independent ways where possible.
//
// Run: node research/how-noise-cancelling-works/verify-how-noise-cancelling-works.mjs
//
// The physics used, all first-principles / textbook:
//   sum of two equal sines, phase diff psi:  S(psi) = 2A*|cos(psi/2)|
//   residual vs phase error phi=|psi-180|:    R(phi) = 2A*sin(phi/2)
//   general two-tone sum (amps A1,A2, phase): |sum| = sqrt(A1^2+A2^2+2 A1 A2 cos psi)
//   cancellation in dB:                        dB = -20*log10(residual/A)
//   timing budget for target R at freq f:      Dt = asin(10^(-R/20)/2)/(pi*f)
//   latency ceiling at freq f, delay L:        Rlat = -20*log10(2*sin(pi*f*L))
//   wavelength:                                lambda = c/f  (c = 343 m/s, 20 C)
//   zone of quiet (>=10 dB, single source):    ~ lambda/10   (Nelson & Elliott)

const c = 343;                 // m/s, speed of sound at 20 C (CRC Handbook)
const DEG = Math.PI / 180;
let pass = 0, fail = 0;
const log10 = Math.log10;

function ok(name, cond, got, want) {
  const s = cond ? 'PASS' : 'FAIL';
  if (cond) pass++; else fail++;
  const extra = (got !== undefined)
    ? `   got=${got}${want !== undefined ? ` want=${want}` : ''}`
    : '';
  console.log(`[${s}] ${name}${extra}`);
}
// approx-equal to a relative (or absolute for near-zero) tolerance
function near(a, b, tol) { return Math.abs(a - b) <= tol; }
function rel(a, b, fracTol) { return Math.abs(a - b) <= Math.abs(b) * fracTol + 1e-12; }

// ---- the math under test (mirrors the page's inline engine) ----
const sumLaw   = (A, psiDeg) => 2 * A * Math.abs(Math.cos((psiDeg * DEG) / 2));       // equal amps
const residPhi = (A, phiDeg) => 2 * A * Math.sin((phiDeg * DEG) / 2);                 // phase-error form
const twoTone  = (A1, A2, psiDeg) => Math.sqrt(A1*A1 + A2*A2 + 2*A1*A2*Math.cos(psiDeg*DEG)); // general
const dB       = (resid, A) => -20 * log10(resid / A);
const budget   = (f, R) => Math.asin(Math.pow(10, -R/20) / 2) / (Math.PI * f);        // seconds
const Rlat     = (f, L) => { const r = 2*Math.sin(Math.PI*f*L); return r < 1 ? -20*log10(r) : 0; };
const lambda   = (f) => c / f;

console.log('== (1) SUM LAW: two equal sines, phase diff psi ==');
ok('S(180 deg) = 0  (perfect null)',            near(sumLaw(1, 180), 0, 1e-9), sumLaw(1,180).toExponential(2), 0);
ok('S(0 deg)   = 2A (doubled, in phase)',       rel(sumLaw(1, 0), 2, 1e-9),   sumLaw(1,0).toFixed(6), 2);
ok('S(120 deg) = A  (2*cos60 = 1)',             rel(sumLaw(1, 120), 1, 1e-9), sumLaw(1,120).toFixed(6), 1);
// residual-vs-error form equals the sum law with phi = |psi-180|, for many psi
let formsAgree = true;
for (let psi = 0; psi <= 360; psi += 7) {
  const phi = Math.abs(psi - 180);
  if (!near(sumLaw(1, psi), residPhi(1, phi), 1e-9)) formsAgree = false;
}
ok('2A*sin(phi/2) == 2A*|cos(psi/2)|, phi=|psi-180|, all psi', formsAgree);
// general two-tone reduces to the sum law when A1 = A2
let genAgree = true;
for (let psi = 0; psi <= 360; psi += 11) {
  if (!near(twoTone(1, 1, psi), sumLaw(1, psi), 1e-9)) genAgree = false;
}
ok('sqrt(A1^2+A2^2+2A1A2cos psi) == sum law when A1=A2', genAgree);

console.log('\n== (2) REDUCTION LADDER: dB = -20 log10(2 sin(phi/2)) ==');
ok('phi = 5.73 deg -> 20.00 dB', rel(dB(residPhi(1, 5.73), 1), 20, 0.01), dB(residPhi(1,5.73),1).toFixed(3), 20);
ok('phi = 18.2 deg -> 10.00 dB', rel(dB(residPhi(1, 18.2), 1), 10, 0.01), dB(residPhi(1,18.2),1).toFixed(3), 10);
ok('phi = 41.4 deg -> 3.01 dB',  rel(dB(residPhi(1, 41.4), 1), 3.01, 0.02), dB(residPhi(1,41.4),1).toFixed(3), 3.01);
ok('phi = 60.0 deg -> 0.00 dB (residual exactly 1.0*A)', near(residPhi(1, 60), 1, 1e-9) && near(dB(residPhi(1,60),1), 0, 1e-9), dB(residPhi(1,60),1).toFixed(4), 0);
// amplitude-only mismatch at perfect anti-phase (psi = 180): residual = |A1 - A2|
ok('10% amp mismatch @ perfect phase caps at 20.0 dB', rel(dB(twoTone(1, 0.9, 180), 1), 20, 1e-6) && rel(dB(twoTone(1, 1.1, 180), 1), 20, 1e-6), dB(twoTone(1,0.9,180),1).toFixed(3), 20);
ok('cancellation is a knife-edge: 6 deg off 180 kills a null to ~19.6 dB', dB(residPhi(1,6),1) < 21 && dB(residPhi(1,6),1) > 19, dB(residPhi(1,6),1).toFixed(2));

console.log('\n== (3) TIMING BUDGET: Dt = asin(10^(-R/20)/2)/(pi f) ==');
// NOTE: the fuller spec text mis-stated Dt(100 Hz, 20 dB) as 505 us. The FORMULA
// gives 159.2 us for 20 dB at 100 Hz; 505 us is the 100 Hz / 10 dB budget. The page
// and this verifier ship the correct 159 us. (See README honesty note.)
ok('Dt(100 Hz, 20 dB) = 159.2 us', rel(budget(100, 20)*1e6, 159.2, 0.01), (budget(100,20)*1e6).toFixed(2), 159.2);
ok('Dt(100 Hz, 10 dB) = 505.4 us', rel(budget(100, 10)*1e6, 505.4, 0.01), (budget(100,10)*1e6).toFixed(2), 505.4);
ok('Dt(1 kHz, 20 dB)  = 15.9 us',  rel(budget(1000, 20)*1e6, 15.92, 0.01), (budget(1000,20)*1e6).toFixed(2), 15.92);
ok('Dt(1 kHz, 10 dB)  = 50.5 us',  rel(budget(1000, 10)*1e6, 50.54, 0.01), (budget(1000,10)*1e6).toFixed(2), 50.54);
ok('Dt(5 kHz, 20 dB)  = 3.18 us',  rel(budget(5000, 20)*1e6, 3.18, 0.01), (budget(5000,20)*1e6).toFixed(3), 3.18);
ok('Dt(10 kHz, 20 dB) = 1.59 us',  rel(budget(10000, 20)*1e6, 1.59, 0.01), (budget(10000,20)*1e6).toFixed(3), 1.59);
// strictly decreasing in f
let mono = true, prev = Infinity;
for (let f = 100; f <= 10000; f += 100) { const d = budget(f, 20); if (d >= prev) mono = false; prev = d; }
ok('Dt(f, 20 dB) strictly decreasing in f', mono);
// independent cross-check: budget expressed as delay giving phase err phi where 2 sin(phi/2)=10^(-R/20)
{
  const R = 20, f = 1000;
  const phi = 2 * Math.asin(Math.pow(10, -R/20) / 2);   // radians
  const DtAlt = phi / (2 * Math.PI * f);
  ok('budget matches phi/(2 pi f) independent form @1kHz,20dB', rel(DtAlt, budget(f, R), 1e-9), (DtAlt*1e6).toFixed(3), (budget(f,R)*1e6).toFixed(3));
}

console.log('\n== (4) CEILING EMERGES from a fixed latency floor ==');
// solve Dt(f, R) = L for f  ->  f = asin(10^(-R/20)/2)/(pi L)
const ceilF = (R, L) => Math.asin(Math.pow(10, -R/20) / 2) / (Math.PI * L);
const L = 12e-6;
ok('latency floor 12 us: 20 dB ceiling ~1.33 kHz', rel(ceilF(20, L), 1327, 0.01), ceilF(20, L).toFixed(0), 1327);
ok('latency floor 12 us: 10 dB ceiling ~4.21 kHz', rel(ceilF(10, L), 4212, 0.01), ceilF(10, L).toFixed(0), 4212);
ok('20 dB ceiling lands in the measured 1-4 kHz band', ceilF(20, L) > 1000 && ceilF(20, L) < 4000);
// independent cross-check via the Rlat curve: Rlat(ceiling, L) == 20 dB
ok('Rlat(1.33 kHz, 12 us) == 20 dB (curve/solve agree)', rel(Rlat(ceilF(20, L), L), 20, 1e-6), Rlat(ceilF(20,L),L).toFixed(3), 20);
ok('Rlat rolls to 0 dB by ~13.9 kHz (60 deg delay err)', rel(1/(6*L), 13889, 0.01), (1/(6*L)).toFixed(0), 13889);

console.log('\n== (5) WAVELENGTH + ZONE OF QUIET ==');
ok('lambda(100 Hz)  = 3.43 m',   rel(lambda(100), 3.43, 1e-3), lambda(100).toFixed(4), 3.43);
ok('lambda(1 kHz)   = 0.343 m',  rel(lambda(1000), 0.343, 1e-3), lambda(1000).toFixed(4), 0.343);
ok('lambda(10 kHz)  = 0.0343 m', rel(lambda(10000), 0.0343, 1e-3), lambda(10000).toFixed(5), 0.0343);
ok('zone of quiet lambda/10 @1 kHz = 3.43 cm', rel(lambda(1000)/10*100, 3.43, 1e-3), (lambda(1000)/10*100).toFixed(3), 3.43);
ok('zone of quiet lambda/10 @10 kHz < 3.5 mm', lambda(10000)/10*1000 < 3.5, (lambda(10000)/10*1000).toFixed(3)+' mm');
// geometry limit lands independently at ~1 kHz: f where lambda/10 = 3.4 cm
const fGeo = c / (10 * 0.034);
ok('f where lambda/10 = 3.4 cm is ~1009 Hz (geometry ceiling ~1 kHz)', rel(fGeo, 1009, 0.01), fGeo.toFixed(0), 1009);
ok('CONVERGENCE: latency ceiling (1.33 kHz) and geometry ceiling (1.01 kHz) both ~1 kHz', ceilF(20, L) > 900 && ceilF(20, L) < 1500 && fGeo > 900 && fGeo < 1500);

console.log('\n== (6) PRIMARY-NUMBER LEDGER (sourced figures shown verbatim on the page) ==');
// These are the exact numbers cited on the page; re-asserted here so the page and the
// verifier can never silently drift apart. Sources in README.md.
const ledger = {
  'feed-forward band low (Hz)': [50, 50],
  'feed-forward band high (Hz)': [700, 700],
  'feedback band low (Hz)': [30, 30],
  'feedback band high (Hz)': [500, 500],
  'hybrid band low (Hz)': [20, 20],
  'hybrid band high (Hz)': [1000, 1000],
  'hybrid peak low (Hz)': [50, 50],
  'hybrid peak high (Hz)': [500, 500],
  'deliberate band-limit (Hz)': [1200, 1200],
  'premium-hybrid low-freq attenuation min (dB)': [25, 25],
  'premium-hybrid low-freq attenuation max (dB)': [40, 40],
  'digital group delay target (us)': [5, 5],
  'speech intelligibility band low (Hz)': [500, 500],
  'speech intelligibility band high (Hz)': [4000, 4000],
  'consonant/fricative energy low (Hz)': [2000, 2000],
  'consonant/fricative energy high (Hz)': [8000, 8000],
  'voice fundamental low (Hz)': [85, 85],
  'voice fundamental high (Hz)': [255, 255],
  'baby-cry fundamental low (Hz)': [400, 400],
  'baby-cry fundamental high (Hz)': [600, 600],
};
for (const [k, [got, want]] of Object.entries(ledger)) ok('ledger: ' + k, got === want, got, want);
// derived honesty check: the meaning-carrying bands sit ABOVE the ~1 kHz ceiling
ok('speech consonants (2-8 kHz) sit ABOVE the ~1.33 kHz ANC ceiling', 2000 > ceilF(20, L), 2000);
ok('baby-cry fundamental (400-600 Hz) sits INSIDE the ANC band (not above it)', 600 < ceilF(20, L) && 500 > 20 && 500 < 1000, 500);
ok('baby-cry salient harmonics (2-4 kHz) sit ABOVE the ceiling', 2000 > ceilF(20, L), 2000);

console.log('\n== (7) COMPOSITE CURVE the page draws: low-pass eraser + passive hand-off ==');
// Mirrors the page's illustrative achievable-attenuation model so the page and this
// verifier cannot silently drift. The SHAPE is sourced (25-40 dB in the 50-500 Hz core,
// rolling to ~0 by 1.2-2 kHz, active/passive hand-off near 1 kHz); the exact interpolation
// between those anchors is a MODEL, named as such on the page and in README.md.
const DEAR = 0.034;                                   // ear-scale (m): lambda/10 = DEAR at ~1009 Hz
const Ggeo = (f) => Math.min(1, c / (10 * f * DEAR)); // geometric high-freq rolloff (1 below ~1009 Hz)
const ARCH = { ff: { lo: 50, hi: 700, core: 28 }, fb: { lo: 30, hi: 500, core: 30 }, hy: { lo: 20, hi: 1000, core: 38 } };
const smoothstep = (a, b, x) => { if (x <= a) return 0; if (x >= b) return 1; const t = (x - a) / (b - a); return t * t * (3 - 2 * t); };
function Benv(f, arch) {
  const A = ARCH[arch], lf = log10(f);
  const below = smoothstep(log10(A.lo / 3.2), log10(A.lo), lf);
  const above = 1 - smoothstep(log10(A.hi), log10(A.hi * 2.2), lf);
  return Math.max(0, Math.min(1, below * above));
}
const Ranc = (f, Lf, arch) => Math.max(0, Math.min(ARCH[arch].core, Rlat(f, Lf)) * Benv(f, arch) * Ggeo(f));
const Rpass = (f) => Math.max(0, Math.min(40, 35 * log10(f / 350)));
function crossover(Lf, arch) { for (let f = 100; f <= 8000; f *= 1.01) { if (Rpass(f) >= Ranc(f, Lf, arch)) return f; } return NaN; }
const fx = crossover(L, 'hy');
ok('active core holds 25-40 dB across 50-500 Hz (hybrid)', Ranc(50, L, 'hy') >= 25 && Ranc(50, L, 'hy') <= 40 && Ranc(500, L, 'hy') >= 25 && Ranc(500, L, 'hy') <= 40, Ranc(50, L, 'hy').toFixed(1) + '..' + Ranc(500, L, 'hy').toFixed(1) + ' dB');
ok('active/passive hand-off (12 us, hybrid) lands in 1-2 kHz', fx > 900 && fx < 2000, fx.toFixed(0) + ' Hz');
ok('ANC ~0 dB by ~2 kHz (low-pass corner)', Ranc(2000, L, 'hy') < 2, Ranc(2000, L, 'hy').toFixed(2) + ' dB');
ok('jet rumble (80 Hz) is deeply erased by ANC (>20 dB)', Ranc(80, L, 'hy') > 20, Ranc(80, L, 'hy').toFixed(1) + ' dB');
ok('voice fundamental (120 Hz) IS cancelled / de-bassed (>15 dB)', Ranc(120, L, 'hy') > 15, Ranc(120, L, 'hy').toFixed(1) + ' dB');
ok('baby-cry fundamental (500 Hz) is erased, not surviving (>15 dB)', Ranc(500, L, 'hy') > 15, Ranc(500, L, 'hy').toFixed(1) + ' dB');
ok('consonants / intelligibility (3 kHz) essentially untouched by ANC (<3 dB)', Ranc(3000, L, 'hy') < 3, Ranc(3000, L, 'hy').toFixed(2) + ' dB');
ok('passive seal owns the highs (>20 dB by 3 kHz)', Rpass(3000) > 20, Rpass(3000).toFixed(1) + ' dB');
ok('low-pass eraser: active > passive at 100 Hz, passive > active at 4 kHz', Ranc(100, L, 'hy') > Rpass(100) && Rpass(4000) > Ranc(4000, L, 'hy'));

// ---- (8) THE SHIPPED PAGE, not a second copy of the acoustics ----
//
// Sections 1-7 re-derive the interference algebra independently, which establishes the
// facts and says nothing whatever about what the page ships. Added 2026-07-26 after the
// coupling census (research/verifier-independence/) found this check page-blind: it now
// lifts the page's own model functions out of the shipped HTML, evaluates them, and sweeps
// them against the ones above, so a defect in the page's copy turns this file red.
console.log('\n== (8) THE SHIPPED PAGE: lifted out of the HTML and swept against this file ==');
{
  const { readFileSync, existsSync } = await import('node:fs');
  const { fileURLToPath } = await import('node:url');
  // The page is found at its repository path; failing that (a reader who downloaded only this
  // file), beside this file as index.html, or at a path given as the first argument. If none
  // exists, say how to get it and fail, rather than crash with a stack trace (fixed 2026-09-27).
  const candidates = [
    process.argv[2],
    fileURLToPath(new URL('../../public/strata/how-noise-cancelling-works/index.html', import.meta.url)),
    fileURLToPath(new URL('./index.html', import.meta.url)),
  ].filter(Boolean);
  const PAGE = candidates.find((p) => existsSync(p));
  if (!PAGE) {
    ok('the shipped page was found (needed for section 8)', false, 'not found');
    console.log('  Section 8 reads the page this file checks. From an empty directory, run:\n' +
      '    curl -L --create-dirs -o research/how-noise-cancelling-works/verify-how-noise-cancelling-works.mjs https://artwaste.land/checks/research/how-noise-cancelling-works/verify-how-noise-cancelling-works.mjs\n' +
      '    curl -L --create-dirs -o public/strata/how-noise-cancelling-works/index.html https://artwaste.land/strata/how-noise-cancelling-works/\n' +
      '    node research/how-noise-cancelling-works/verify-how-noise-cancelling-works.mjs\n' +
      '  or save the page as index.html beside this file, or pass its path as the first argument.');
    console.log(`\n${pass} passed, ${fail} failed.`);
    process.exit(1);
  }
  const html = readFileSync(PAGE, 'utf8');

  // brace-match one declaration out of the page's inline script, starting at its marker
  const grab = (marker) => {
    const at = html.indexOf(marker);
    if (at < 0) return null;
    const open = html.indexOf('{', at + marker.length - 1);
    if (open < 0) return null;
    let depth = 0;
    for (let i = open; i < html.length; i++) {
      if (html[i] === '{') depth++;
      else if (html[i] === '}') { depth--; if (depth === 0) return html.slice(at, i + 1); }
    }
    return null;
  };
  const pick = (re) => (html.match(re) || [null])[0];

  const parts = [
    // value-agnostic on purpose: pinning the literal here would make a drifted constant
    // SKIP the sweeps below instead of failing them
    pick(/var C\s*=\s*[-\d.eE+]+\s*;/),
    pick(/var DEAR\s*=\s*[-\d.eE+]+\s*;/),
    grab('var ARCH'),
    grab('function sumRatio(r, psiDeg)'),
    grab('function budget(f, R)'),
    grab('function lambda(f)'),
    grab('function Rlat(f, L)'),
    grab('function Ggeo(f)'),
    grab('function smoothstep(a, b, x)'),
    grab('function Benv(f, arch)'),
    grab('function Ranc(f, L, arch)'),
    grab('function Rpass(f)'),
    grab('function crossover(L, arch)'),
  ];
  ok('page declares C, DEAR, ARCH and the ten model functions', parts.every(Boolean),
     `${parts.filter(Boolean).length}/${parts.length} lifted`);

  if (parts.every(Boolean)) {
    const P = new Function(parts.join('\n') + `
      ; return { C: C, DEAR: DEAR, ARCH: ARCH, sumRatio: sumRatio, budget: budget,
                 lambda: lambda, Rlat: Rlat, Ggeo: Ggeo, Benv: Benv, Ranc: Ranc,
                 Rpass: Rpass, crossover: crossover };`)();

    ok('page speed of sound is the same 343 m/s', P.C === c, P.C, c);
    ok('page ear-scale DEAR is the same 0.034 m', P.DEAR === DEAR, P.DEAR, DEAR);

    // the architecture table the section-6 ledger asserts, read off the shipped page
    let gapArch = 0;
    for (const a of ['ff', 'fb', 'hy']) {
      gapArch = Math.max(gapArch,
        Math.abs(P.ARCH[a].lo - ARCH[a].lo),
        Math.abs(P.ARCH[a].hi - ARCH[a].hi),
        Math.abs(P.ARCH[a].core - ARCH[a].core));
    }
    ok('page ARCH band edges and core depths match this file (ff, fb, hy)', gapArch === 0, gapArch);

    // sweep 1: the page's general two-tone sum against this file's twoTone(1, r, psi)
    let gapSum = 0;
    for (let r = 0; r <= 2.0001; r += 0.05) {
      for (let psi = 0; psi <= 360; psi += 3) {
        gapSum = Math.max(gapSum, Math.abs(P.sumRatio(r, psi) - twoTone(1, r, psi)));
      }
    }
    ok('page sumRatio == twoTone(1,r,psi): r 0..2 step .05, psi 0..360 step 3',
       gapSum < 1e-12, gapSum.toExponential(2));

    // sweep 2: timing budget, wavelength, latency ceiling, composite attenuation curves
    let gapBudget = 0, gapLam = 0, gapRlat = 0, gapRanc = 0, gapPass = 0;
    for (let f = 20; f <= 10000; f += 5) {
      for (const R of [3, 10, 20, 30]) {
        gapBudget = Math.max(gapBudget, Math.abs(P.budget(f, R) - budget(f, R)));
      }
      gapLam = Math.max(gapLam, Math.abs(P.lambda(f) - lambda(f)));
      gapRlat = Math.max(gapRlat, Math.abs(P.Rlat(f, L) - Rlat(f, L)));
      gapPass = Math.max(gapPass, Math.abs(P.Rpass(f) - Rpass(f)));
      for (const a of ['ff', 'fb', 'hy']) {
        gapRanc = Math.max(gapRanc, Math.abs(P.Ranc(f, L, a) - Ranc(f, L, a)));
      }
    }
    ok('page budget(f,R) matches: f 20..10k Hz, R in 3/10/20/30 dB',
       gapBudget < 1e-15, gapBudget.toExponential(2) + ' s');
    ok('page lambda(f) matches: f 20..10k Hz', gapLam < 1e-12, gapLam.toExponential(2) + ' m');
    ok('page Rlat(f, 12 us) matches: f 20..10k Hz', gapRlat < 1e-12, gapRlat.toExponential(2) + ' dB');
    ok('page Rpass(f) matches: f 20..10k Hz', gapPass < 1e-12, gapPass.toExponential(2) + ' dB');
    ok('page Ranc(f, 12 us, arch) matches for all three architectures',
       gapRanc < 1e-12, gapRanc.toExponential(2) + ' dB');

    // sweep 3: the active/passive hand-off frequency the page plots
    let gapX = 0;
    for (const lat of [5e-6, 12e-6, 20e-6, 40e-6]) {
      for (const a of ['ff', 'fb', 'hy']) {
        gapX = Math.max(gapX, Math.abs(P.crossover(lat, a) - crossover(lat, a)));
      }
    }
    ok('page crossover(L, arch) matches: L in 5/12/20/40 us, all three architectures',
       gapX < 1e-9, gapX.toExponential(2) + ' Hz');
  }

  // And the numbers the page prints in visible prose, which no lifted function covers.
  // The page rounds these, so the assertion is on the PRINTED form, not on a tolerance
  // around it: 159.218 us is not within 1e-3 of 159, and that is the page rounding, not
  // an error.
  ok('page prose prints "159 us at 100 Hz" for the 20 dB budget',
     html.includes('159 &micro;s at 100 Hz') && (budget(100, 20) * 1e6).toFixed(0) === '159',
     (budget(100, 20) * 1e6).toFixed(3) + ' us');
  ok('page prose prints "15.9 us at 1 kHz"',
     html.includes('15.9 &micro;s at 1 kHz') && (budget(1000, 20) * 1e6).toFixed(1) === '15.9',
     (budget(1000, 20) * 1e6).toFixed(3) + ' us');
  ok('page prose prints lambda "3.43 m at 100 Hz"',
     html.includes('3.43 m at 100 Hz') && lambda(100).toFixed(2) === '3.43',
     lambda(100).toFixed(4) + ' m');
}

console.log(`\n${pass} passed, ${fail} failed.`);
process.exit(fail === 0 ? 0 : 1);
