import test from 'node:test'
import assert from 'node:assert/strict'
import { createFemAnalysis } from '../src/facade/fem'

test('FEM reference bar solve produces deterministic displacement/stress results', () => { const fem = createFemAnalysis(); fem.setMaterial({ id: 'steel', youngsModulus: 200000, poissonRatio: 0.3 }); fem.setMesh([{ id: 1, position: [0, 0, 0] }, { id: 2, position: [10, 0, 0] }]); fem.addNodeSet({ id: 'ends', nodeIds: [2, 1], role: 'result' }); fem.fixNode(1); fem.addLoad({ nodeId: 2, force: 100 }); const result = fem.solve({ length: 10, area: 5 }); assert.equal(result.status, 'solved'); assert.equal(result.solverStrategy, 'local-reference'); assert.equal(result.nodeSets[0]?.nodeIds.join(','), '1,2'); assert.equal(result.resultFields.length, 2); assert.equal(result.results[1]?.displacement, 0.001); assert.equal(result.results[1]?.stress, 20); assert.equal(fem.exportResultsCsv().trim().split('\n').length, 3) })
test('FEM rejects invalid material and reports unsolved analysis', () => { const fem = createFemAnalysis(); assert.throws(() => fem.setMaterial({ id: 'bad', youngsModulus: 0, poissonRatio: 0.3 }), /Young modulus/); assert.equal(fem.solve({ length: 1, area: 1 }).status, 'invalid') })
