test_deduplicatePaths_01.js (2154B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Test the behavior of the deduplicatePaths utility function. 6 7 function edge(from, to, name) { 8 return { from, to, name }; 9 } 10 11 function run_test() { 12 const a = 1; 13 const b = 2; 14 const c = 3; 15 const d = 4; 16 const e = 5; 17 const f = 6; 18 const g = 7; 19 20 dumpn("Single long path"); 21 assertDeduplicatedPaths({ 22 target: g, 23 paths: [ 24 [ 25 pathEntry(a, "e1"), 26 pathEntry(b, "e2"), 27 pathEntry(c, "e3"), 28 pathEntry(d, "e4"), 29 pathEntry(e, "e5"), 30 pathEntry(f, "e6"), 31 ], 32 ], 33 expectedNodes: [a, b, c, d, e, f, g], 34 expectedEdges: [ 35 edge(a, b, "e1"), 36 edge(b, c, "e2"), 37 edge(c, d, "e3"), 38 edge(d, e, "e4"), 39 edge(e, f, "e5"), 40 edge(f, g, "e6"), 41 ], 42 }); 43 44 dumpn("Multiple edges from and to the same nodes"); 45 assertDeduplicatedPaths({ 46 target: a, 47 paths: [[pathEntry(b, "x")], [pathEntry(b, "y")], [pathEntry(b, "z")]], 48 expectedNodes: [a, b], 49 expectedEdges: [edge(b, a, "x"), edge(b, a, "y"), edge(b, a, "z")], 50 }); 51 52 dumpn("Multiple paths sharing some nodes and edges"); 53 assertDeduplicatedPaths({ 54 target: g, 55 paths: [ 56 [pathEntry(a, "a->b"), pathEntry(b, "b->c"), pathEntry(c, "foo")], 57 [pathEntry(a, "a->b"), pathEntry(b, "b->d"), pathEntry(d, "bar")], 58 [pathEntry(a, "a->b"), pathEntry(b, "b->e"), pathEntry(e, "baz")], 59 ], 60 expectedNodes: [a, b, c, d, e, g], 61 expectedEdges: [ 62 edge(a, b, "a->b"), 63 edge(b, c, "b->c"), 64 edge(b, d, "b->d"), 65 edge(b, e, "b->e"), 66 edge(c, g, "foo"), 67 edge(d, g, "bar"), 68 edge(e, g, "baz"), 69 ], 70 }); 71 72 dumpn("Second shortest path contains target itself"); 73 assertDeduplicatedPaths({ 74 target: g, 75 paths: [ 76 [pathEntry(a, "a->b"), pathEntry(b, "b->g")], 77 [ 78 pathEntry(a, "a->b"), 79 pathEntry(b, "b->g"), 80 pathEntry(g, "g->f"), 81 pathEntry(f, "f->g"), 82 ], 83 ], 84 expectedNodes: [a, b, g], 85 expectedEdges: [edge(a, b, "a->b"), edge(b, g, "b->g")], 86 }); 87 }