diff --git a/packages/timestep/test/index.ts b/packages/timestep/test/index.ts index 7d2d189391..ea69f19c2b 100644 --- a/packages/timestep/test/index.ts +++ b/packages/timestep/test/index.ts @@ -1,7 +1,39 @@ import { group } from "@thi.ng/testament"; -// import * as assert from "assert"; -// import { } from "../src/index.js"; +import { eqDelta } from "@thi.ng/math"; +import * as assert from "assert"; +import { + defNumeric, + defTimeStep, + defVector2, + defVector3, + defVector4, +} from "../src/index.js"; +import { eqDelta2, maddN2, maddN3, maddN4 } from "@thi.ng/vectors"; group("timestep", { + numeric: () => { + const sim = defTimeStep({ maxFrameTime: 10 }); + const states = [ + defNumeric(100, (x, dt) => x - 0.1 * dt), + defNumeric(0, (x, dt) => (100 - x) * 0.1 * dt), + ]; + sim.update(61 * (1000 / 60), states); + assert.ok(eqDelta(states[0].deref(), 99.9, 0.001)); + assert.ok(eqDelta(states[1].deref(), 0.166, 0.001)); + }, + vector: () => { + const sim = defTimeStep({ maxFrameTime: 10 }); + const states = [ + defVector2([0, 0], (v, dt) => maddN2(v, [-10, 20], dt, v)), + defVector3([0, 0, 0], (v, dt) => maddN3(v, [-10, 20, -30], dt, v)), + defVector4([0, 0, 0, 0], (v, dt) => + maddN4(v, [-10, 20, -30, 40], dt, v) + ), + ]; + sim.update(61 * (1000 / 60), states); + assert.ok(eqDelta2(states[0].deref(), [-10, 20], 0.001)); + assert.ok(eqDelta2(states[1].deref(), [-10, 20, -30], 0.001)); + assert.ok(eqDelta2(states[2].deref(), [-10, 20, -30, 40], 0.001)); + }, });