Skip to content

Commit

Permalink
test(timestep): add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jun 19, 2023
1 parent 65ace1e commit fe99fce
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions packages/timestep/test/index.ts
Original file line number Diff line number Diff line change
@@ -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));
},
});

0 comments on commit fe99fce

Please sign in to comment.