test: add reproducible FreeCAD golden oracle
This commit is contained in:
32
tests/goldenReplay.test.mjs
Normal file
32
tests/goldenReplay.test.mjs
Normal file
@@ -0,0 +1,32 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { resolve } from 'node:path'
|
||||
import { compareGoldenResult, loadGoldenManifest, validateGoldenOperation } from '../scripts/freecad-golden-contract.mjs'
|
||||
|
||||
const manifestFile = resolve('fixtures/freecad-golden/manifest.json')
|
||||
|
||||
test('FreeCAD golden manifest loads unique validated scenarios', async () => {
|
||||
const manifest = await loadGoldenManifest(manifestFile)
|
||||
assert.equal(manifest.baselineId, 'freecad-1.1.1')
|
||||
assert.deepEqual(manifest.scenarios.map((entry) => entry.id), ['part-box', 'part-cylinder', 'part-sphere', 'part-cone', 'part-cut-through-hole'])
|
||||
assert.equal(manifest.scenarios.at(-1).scenario.expected.shapeType, 'Compound')
|
||||
assert.equal(manifest.scenarios.at(-1).scenario.expected.solids, 1)
|
||||
})
|
||||
|
||||
test('golden comparator applies linear and scalar tolerances only to declared oracle fields', async () => {
|
||||
const manifest = await loadGoldenManifest(manifestFile)
|
||||
const box = manifest.scenarios[0].scenario
|
||||
const actual = structuredClone(box.expected)
|
||||
actual.volume += box.tolerance.scalar / 2
|
||||
actual.boundingBox.max[0] += box.tolerance.linear / 2
|
||||
actual.untrackedRuntimeField = 'ignored'
|
||||
assert.deepEqual(compareGoldenResult(box, actual), [])
|
||||
actual.volume += box.tolerance.scalar * 2
|
||||
assert.match(compareGoldenResult(box, actual)[0], /volume/)
|
||||
})
|
||||
|
||||
test('golden operation validation rejects malformed dimensions, placements and unknown operations', () => {
|
||||
assert.throws(() => validateGoldenOperation({ type: 'box', length: 0, width: 2, height: 3 }), /positive/)
|
||||
assert.throws(() => validateGoldenOperation({ type: 'sphere', radius: 2, placement: { rotation: { axis: [0, 0, 0], angle: 10 } } }), /non-zero/)
|
||||
assert.throws(() => validateGoldenOperation({ type: 'loft' }), /unsupported/)
|
||||
})
|
||||
Reference in New Issue
Block a user