mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
test(camera): compare recorded camera traces within platform roundoff
The camera golden test compared the recorded traces byte for byte, so it failed on arm64, where trigonometry differs from the committed traces in the last bits (at most 2.1e-9 m on a height, 33 of 1,530 numbers). Compare structure, keys, array lengths, counters and the viewport exactly, and other numbers within 1e-8 m for positions and heights and 1e-14 otherwise; a self-test rejects larger errors, NaN, null, strings and missing or extra keys. The pose test compares pitch by its sine within 1e-12, as the conformance suite does, and checks the canonical range. The golden file and production camera code are unchanged.
This commit is contained in:
1 parent
a8ac8eeb9b
commit
0a8899d439
2 files changed
+75
-9
No files matched your search
@@ -2,15 +2,72 @@ import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { recordCameraGoldens } from './cameraGoldens.js';
|
||||
import { near } from '../conformance/expect.js';
|
||||
|
||||
// The recorder is deterministic, but platforms can differ in the last bits
|
||||
// of trigonometric arithmetic. Keep structure and discrete values exact.
|
||||
function compareTrace(actual, expected, path = []) {
|
||||
const label = path.join('.');
|
||||
if (typeof expected === 'number') {
|
||||
const key = path.at(-1);
|
||||
if (['step', 'frames', 'count'].includes(key) || path[0] === 'viewport') {
|
||||
assert.equal(actual, expected, label);
|
||||
return;
|
||||
}
|
||||
const metres =
|
||||
path.at(-2) === 'position' ||
|
||||
key === 'height' ||
|
||||
(path.at(-2) === 'view' && Number(key) >= 12 && Number(key) <= 14);
|
||||
near(actual, expected, metres ? 1e-8 : 1e-14, label);
|
||||
return;
|
||||
}
|
||||
if (expected !== null && typeof expected === 'object') {
|
||||
assert.ok(actual !== null && typeof actual === 'object', label);
|
||||
assert.equal(Array.isArray(actual), Array.isArray(expected), label);
|
||||
assert.deepEqual(Object.keys(actual), Object.keys(expected), label);
|
||||
if (Array.isArray(expected))
|
||||
assert.equal(actual.length, expected.length, label);
|
||||
for (const key of Object.keys(expected))
|
||||
compareTrace(actual[key], expected[key], [...path, key]);
|
||||
return;
|
||||
}
|
||||
assert.equal(actual, expected, label);
|
||||
}
|
||||
|
||||
test('the committed camera traces are what the installed Cesium records', async () => {
|
||||
const committed = readFileSync(
|
||||
new URL('../conformance/goldens/camera.json', import.meta.url),
|
||||
'utf8',
|
||||
);
|
||||
const recorded = `${JSON.stringify(await recordCameraGoldens(), null, 2)}\n`;
|
||||
assert.ok(
|
||||
recorded === committed,
|
||||
'goldens/camera.json is out of date: run node scripts/record-camera-goldens.mjs and review the diff',
|
||||
const committed = JSON.parse(
|
||||
readFileSync(
|
||||
new URL('../conformance/goldens/camera.json', import.meta.url),
|
||||
'utf8',
|
||||
),
|
||||
);
|
||||
compareTrace(await recordCameraGoldens(), committed);
|
||||
});
|
||||
|
||||
test('trace comparison tolerates only numeric roundoff, preserving structure and counters', () => {
|
||||
const expected = {
|
||||
position: { x: 1000 },
|
||||
pitch: 0.3,
|
||||
frames: 2,
|
||||
values: [1],
|
||||
label: 'pose',
|
||||
};
|
||||
compareTrace(
|
||||
{ ...expected, position: { x: 1000 + 2e-9 }, pitch: 0.3 + 1e-16 },
|
||||
expected,
|
||||
);
|
||||
for (const actual of [
|
||||
{ ...expected, extra: true },
|
||||
{ ...expected, values: [] },
|
||||
{ ...expected, position: { x: 1000 + 2e-8 } },
|
||||
{ ...expected, pitch: 0.3 + 2e-14 },
|
||||
{ ...expected, frames: 2 + 1e-15 },
|
||||
{ ...expected, pitch: NaN },
|
||||
{ ...expected, pitch: null },
|
||||
{ ...expected, pitch: '0.3' },
|
||||
{ ...expected, label: 'other' },
|
||||
])
|
||||
assert.throws(() => compareTrace(actual, expected));
|
||||
const { label, ...missing } = expected;
|
||||
assert.throws(() => compareTrace(missing, expected));
|
||||
});
|
||||
Reference in new issue
Block a user