import { Box } from '../../classes/display/box.js'; import { Scene } from '../../classes/display/scene.js'; import { WeightedDirectedGraph } from '../../classes/supporting/wdg.js'; import { mochaRun } from '../../util/helpers.js'; const rootElement = document.getElementById('scene'); const rootBox = new Box('rootBox', rootElement).flex(); window.scene = new Scene('WDG test', rootBox); describe('Weighted Directed Acyclic Graph', function tests() { this.timeout(0); let graph; before(() => { graph = (window.graph = new WeightedDirectedGraph(window.scene)).withFlowchart(); graph.addVertex('v1', {}); graph.addVertex('v1', {}); graph.addVertex('v1', {}); graph.addVertex('v1', {}); graph.addVertex('v1', {}); graph.addEdge('e1', 0, 1, 1); graph.addEdge('e1', 2, 1, 0.5); graph.addEdge('e1', 3, 1, 0.25); graph.addEdge('e1', 1, 4, 0.125); }); it('can query for all e1 edges', () => { const edges = graph.getEdges('e1'); edges.should.have.length(4); }); it('can query for all e1 edges from a particular vertex', () => { const edges = graph.getEdges('e1', 2); edges.map(({ from, to, weight }) => [from.id, to.id, weight]).should.have.deep.members([[ '2', '1', 0.5, ]]); }); it('can query for all e1 edges to a particular vertex', () => { const edges = graph.getEdges('e1', null, 1); edges.map(({ from, to, weight }) => [from.id, to.id, weight]).should.have.deep.members([ ['0', '1', 1], ['2', '1', 0.5], ['3', '1', 0.25], ]); }); }); describe('editable', () => { let graph; it('should be editable', () => { graph = (window.graph2 = new WeightedDirectedGraph(window.scene, { editable: true })).withFlowchart(); graph.addVertex('v1', {}); graph.addVertex('v2', {}); graph.addVertex('v3', {}); graph.addEdge('e1', 2, 1, 1); graph.addEdge('e2', 1, 0, 0.5); graph.addEdge('e3', 2, 0, 0.25); }); }); mochaRun();