-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdijkstra.test.ts
45 lines (43 loc) · 982 Bytes
/
dijkstra.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { dijkstra } from "./dijkstra";
describe("dijkstra", () => {
test("should return shortest paths from start node to all other nodes", () => {
const graph = new Map<string, Map<string, number>>([
[
"A",
new Map([
["B", 6],
["D", 1],
]),
],
[
"B",
new Map([
["C", 5],
["D", 2],
["E", 2],
]),
],
["C", new Map([["E", 5]])],
[
"D",
new Map([
["B", 2],
["E", 1],
]),
],
[
"E",
new Map([
["B", 2],
["C", 5],
]),
],
]);
const result = dijkstra(graph, "A");
expect(result.get("A")).toEqual(["A"]);
expect(result.get("B")).toEqual(["A", "D", "B"]);
expect(result.get("C")).toEqual(["A", "D", "E", "C"]);
expect(result.get("D")).toEqual(["A", "D"]);
expect(result.get("E")).toEqual(["A", "D", "E"]);
});
});