v1.1.0: pooled runtime, 959 tests, production hardening (0 squash)
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
// examples/solver-direct-test.js
|
||||
// Direct solver usage: evaluate layout assertions against a mock GeometryWorld.
|
||||
//
|
||||
// This bypasses the browser and tests the geometry logic engine directly.
|
||||
// Useful for unit testing layout invariants without a browser overhead.
|
||||
|
||||
import { evaluate, registerDefaultClauses } from 'imhotep-solver'
|
||||
|
||||
// Register the built-in clause evaluators
|
||||
registerDefaultClauses()
|
||||
|
||||
// Build a minimal GeometryWorld with two boxes
|
||||
const world = {
|
||||
boxes: {
|
||||
boxId: new Uint32Array([1, 2]),
|
||||
subjectId: new Uint32Array([1, 2]),
|
||||
frameId: new Uint32Array([0, 0]),
|
||||
borderLeft: new Float64Array([0, 110]),
|
||||
borderTop: new Float64Array([0, 0]),
|
||||
borderRight: new Float64Array([100, 210]),
|
||||
borderBottom: new Float64Array([50, 50]),
|
||||
paddingLeft: new Float64Array([0, 0]),
|
||||
paddingTop: new Float64Array([0, 0]),
|
||||
paddingRight: new Float64Array([0, 0]),
|
||||
paddingBottom: new Float64Array([0, 0]),
|
||||
contentLeft: new Float64Array([0, 110]),
|
||||
contentTop: new Float64Array([0, 0]),
|
||||
contentRight: new Float64Array([100, 210]),
|
||||
contentBottom: new Float64Array([50, 50]),
|
||||
},
|
||||
}
|
||||
|
||||
// Define a clause: subject 1 should be left of subject 2 with gap 8-16
|
||||
const clauses = [
|
||||
{
|
||||
clauseKind: 'relation.leftOf',
|
||||
version: 1,
|
||||
clauseId: 'clause_1',
|
||||
subjectRef: 1,
|
||||
referenceRef: 2,
|
||||
bounds: { minGap: 8, maxGap: 16 },
|
||||
},
|
||||
]
|
||||
|
||||
// Evaluate the clause
|
||||
const result = evaluate(world, clauses)
|
||||
|
||||
console.log('Solver direct evaluation:')
|
||||
console.log(` Passed: ${result.clauseResults.every((r) => r.status === 'pass')}`)
|
||||
|
||||
for (const clauseResult of result.clauseResults) {
|
||||
console.log(` Clause ${clauseResult.clauseId}: ${clauseResult.status}`)
|
||||
if (clauseResult.metrics) {
|
||||
console.log(` Observed gap: ${clauseResult.metrics.observedGap}px`)
|
||||
console.log(` Required: ${clauseResult.metrics.minGap}px to ${clauseResult.metrics.maxGap}px`)
|
||||
}
|
||||
}
|
||||
|
||||
// This will pass because the gap is 10px (110 - 100), which is within 8-16.
|
||||
Reference in New Issue
Block a user