SOURCE / PINNED RELEASE
Made of little things.
Find the Invisible Cow
- Release
- e48b3dced31c…
- Author-recorded commit
- cf79302f143d…
- License
- LICENSE
- Author’s source reference
- nostr://npub1p8rxwea4e0l4jml0q53n5mvh3n7pywq523jk3lm336v04r8ny9jqtq7ttf/wss%3A%2F%2Fgit.napplet.soy%2F/n-3b179f1d7df
Archive hash verified: f8e300eb672b5ee8…. The source-to-build association is the author’s claim; it has not been independently rebuilt.
import assert from 'node:assert/strict';
import { readFile } from 'node:fs/promises';
import { dirname, join } from 'node:path';
import test from 'node:test';
import { fileURLToPath } from 'node:url';
import { runInNewContext } from 'node:vm';
import ts from 'typescript';
const root = dirname(dirname(fileURLToPath(import.meta.url)));
// Transpile the pure rules module the same way tests/guidance.test.mjs does
// for domain-availability.ts, so no DOM or audio is needed.
const compiled = ts.transpileModule(await readFile(join(root, 'src/rules.ts'), 'utf8'), {
compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 },
}).outputText;
const module = { exports: {} };
runInNewContext(compiled, { module, exports: module.exports });
const { proximityFor, volumeFor, intervalFor, catchRadiusFor, formatTime, spotDescription } =
module.exports;
test('proximity clamps to 0..1 and hits 1 on the cow', () => {
assert.equal(proximityFor(0, 1000), 1);
assert.equal(proximityFor(1000, 1000), 0);
assert.equal(proximityFor(2000, 1000), 0);
assert.ok(proximityFor(250, 1000) > 0.7 && proximityFor(250, 1000) < 0.8);
assert.equal(proximityFor(Number.NaN, 1000), 0);
assert.equal(proximityFor(10, 0), 0);
});
test('moo volume grows with proximity and stays within safe bounds', () => {
let previous = -1;
for (let p = 0; p <= 1.0001; p += 0.1) {
const v = volumeFor(p);
assert.ok(v >= 0.05 && v <= 1, `volume ${v} out of range at p=${p}`);
assert.ok(v > previous, `volume must grow with proximity at p=${p}`);
previous = v;
}
assert.equal(volumeFor(0), 0.05);
assert.equal(volumeFor(1), 1);
});
test('moos come quicker as you close in', () => {
assert.equal(intervalFor(0), 1150);
assert.equal(intervalFor(1), 350);
assert.ok(intervalFor(0.9) < intervalFor(0.5));
});
test('catch radius scales with the frame and the assist setting', () => {
assert.equal(catchRadiusFor(900, 600, 'normal'), Math.min(72, 600 * 0.09));
assert.equal(catchRadiusFor(200, 160, 'normal'), 26); // clamped low end
assert.ok(catchRadiusFor(900, 600, 'large') > catchRadiusFor(900, 600, 'normal'));
});
test('timer formats as m:ss.t', () => {
assert.equal(formatTime(0), '0:00.0');
assert.equal(formatTime(9460), '0:09.4');
assert.equal(formatTime(61499), '1:01.4');
assert.equal(formatTime(-50), '0:00.0');
});
test('hiding-spot description covers the nine regions', () => {
assert.match(spotDescription(0.5, 0.5), /middle/);
assert.match(spotDescription(0.1, 0.1), /top-left corner/);
assert.match(spotDescription(0.9, 0.9), /bottom-right corner/);
assert.match(spotDescription(0.5, 0.9), /bottom edge/);
assert.match(spotDescription(0.9, 0.5), /right side/);
});
