import assert from "node:assert/strict"; import test from "node:test"; import { CRITICAL_IMPACT, HORIZON, deflection, traceImpact, traceRay } from "../src/lib/blackhole/geodesic.ts"; test("a ray inside the critical impact parameter is captured and one outside escapes", () => { assert.equal(traceImpact(CRITICAL_IMPACT * 0.94).outcome, "captured"); assert.equal(traceImpact(CRITICAL_IMPACT * 1.06).outcome, "escaped"); }); test("the shadow edge sits at the analytic 3√3 within the step error", () => { let captured = 0; let escaped = 10; for (let i = 0; i < 24; i++) { const mid = (captured + escaped) / 2; const { outcome } = traceImpact(mid, 48, { maxSteps: 900 }); if (outcome === "escaped") escaped = mid; else captured = mid; } assert.ok(Math.abs(escaped - CRITICAL_IMPACT) / CRITICAL_IMPACT < 0.03, `edge at ${escaped}`); }); test("weak-field deflection follows 4M/b plus the second-order term", () => { const b = 20; const expected = 4 / b + (15 * Math.PI) / 4 / (b * b); const angle = deflection(traceImpact(b, 400, { maxSteps: 600 })); assert.ok(Math.abs(angle - expected) / expected < 0.1, `${angle} vs ${expected}`); }); test("a ray that falls radially is captured at the horizon", () => { const trace = traceRay([0, 0, 30], [0, 0, -1]); assert.equal(trace.outcome, "captured"); assert.ok(trace.minRadius < HORIZON); }); test("a ray in the disk plane never crosses it and a skewed ray crosses it once", () => { assert.equal(traceImpact(9).crossings.length, 0); const skew = traceRay([9, 14, 40], [0, -0.3, -0.95]); assert.equal(skew.crossings.length, 1); assert.equal(skew.crossings[0].point[1], 0); });