d3-force/test/simulation-test.js
Philippe Rivière 8aed9d462f
Adopt type=module (#192)
* Adopt type=module

follow changes in d3-format:
* type=module
* add exports
* remove zip
* license: ISC
* update dependencies

* es6 rather than no-undef

* remove Sublime project

* add eslint.json

* related d3/d3#3502; extract copyrights from LICENSE

* update dependencies

* stricter eslint

* cleaner imports

* Update README

Co-authored-by: Mike Bostock <mbostock@gmail.com>
2021-06-05 12:09:51 -07:00

19 lines
885 B
JavaScript

import assert from "assert";
import {forceSimulation} from "../src/index.js";
import {assertNodeEqual} from "./asserts.js";
it("forceSimulation() returns a simulation", () => {
const f = forceSimulation().stop();
assert.deepStrictEqual(Object.keys(f).sort(), [ 'alpha', 'alphaDecay', 'alphaMin', 'alphaTarget', 'find', 'force', 'nodes', 'on', 'randomSource', 'restart', 'stop', 'tick', 'velocityDecay' ]);
});
it("simulation.nodes(nodes) initializes a simulation with indices & phyllotaxis positions, 0 speed", () => {
const f = forceSimulation().stop();
const a = {}, b = {}, c = {};
f.nodes([a, b, c]);
assertNodeEqual(a, {index: 0, x: 7.0710678118654755, y: 0, vy: 0, vx: 0});
assertNodeEqual(b, {index: 1, x: -9.03088751750192, y: 8.27303273571596, vy: 0, vx: 0});
assertNodeEqual(c, {index: 2, x: 1.3823220809823638, y: -15.750847141167634, vy: 0, vx: 0});
});