import { Box } from '../../classes/box.js'; import { Scene } from '../../classes/scene.js'; import { WDAG } from '../../classes/wdag.js'; const rootElement = document.getElementById('scene'); const rootBox = new Box('rootBox', rootElement).flex(); window.scene = new Scene('WDAG test', rootBox); describe('Query the graph', () => { let graph; before(() => { graph = (window.graph = new WDAG()).withFlowchart(); graph.addVertex({}); graph.addVertex({}); graph.addVertex({}); graph.addVertex({}); graph.addVertex({}); 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], ]); }); });