Skip to content

Commit 1e4d5d2

Browse files
committed
Check the graph has not changed after shortestPaths call
1 parent d60eac8 commit 1e4d5d2

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

test.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,17 +436,21 @@ describe("Graph", function () {
436436
.addEdge("a", "e")
437437
.addEdge("e", "f")
438438
.addEdge("f", "c");
439+
const serializedGraph = graph.serialize();
439440
assert.deepEqual(graph.shortestPaths("a", "c"), [
440441
withWeight(["a", "b", "c"], 2),
441442
withWeight(["a", "d", "c"], 2),
442443
]);
443-
// need to check nodes are still present because we remove them to get all shortest paths
444-
const nodes = ["a", "b", "c", "d", "e", "f"];
445-
assert.equal(graph.nodes().length, nodes.length);
446-
nodes.forEach((node) => assert(contains(graph.nodes(), node)));
447-
// check edges are still there and no new have been added
448-
assert.deepEqual(graph.hasEdge("a", "b"), true);
449-
assert.deepEqual(graph.hasEdge("b", "a"), false);
444+
// check graph has not changed
445+
const postSerializedGraph = graph.serialize();
446+
assert.equal(
447+
postSerializedGraph.links.length,
448+
serializedGraph.links.length,
449+
);
450+
assert.equal(
451+
postSerializedGraph.nodes.length,
452+
serializedGraph.nodes.length,
453+
);
450454
});
451455
});
452456

0 commit comments

Comments
 (0)