data-structure-typed 1.12.21 → 1.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +278 -179
  2. package/dist/data-structures/binary-tree/binary-tree.d.ts +46 -1
  3. package/dist/data-structures/binary-tree/binary-tree.js +67 -0
  4. package/dist/data-structures/binary-tree/segment-tree.d.ts +29 -0
  5. package/dist/data-structures/binary-tree/segment-tree.js +45 -0
  6. package/dist/data-structures/graph/abstract-graph.d.ts +40 -5
  7. package/dist/data-structures/graph/abstract-graph.js +47 -7
  8. package/dist/data-structures/graph/directed-graph.d.ts +8 -0
  9. package/dist/data-structures/graph/directed-graph.js +14 -2
  10. package/dist/data-structures/graph/undirected-graph.d.ts +10 -0
  11. package/dist/data-structures/graph/undirected-graph.js +23 -1
  12. package/dist/data-structures/hash/coordinate-map.d.ts +7 -1
  13. package/dist/data-structures/hash/coordinate-map.js +16 -0
  14. package/dist/data-structures/hash/coordinate-set.d.ts +7 -1
  15. package/dist/data-structures/hash/coordinate-set.js +16 -0
  16. package/dist/data-structures/heap/heap.d.ts +16 -0
  17. package/dist/data-structures/heap/heap.js +38 -0
  18. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +30 -7
  19. package/dist/data-structures/linked-list/doubly-linked-list.js +71 -4
  20. package/dist/data-structures/linked-list/singly-linked-list.d.ts +262 -328
  21. package/dist/data-structures/linked-list/singly-linked-list.js +258 -273
  22. package/dist/data-structures/priority-queue/priority-queue.d.ts +7 -1
  23. package/dist/data-structures/priority-queue/priority-queue.js +18 -2
  24. package/dist/data-structures/queue/deque.d.ts +18 -7
  25. package/dist/data-structures/queue/deque.js +50 -3
  26. package/dist/data-structures/types/abstract-graph.d.ts +2 -2
  27. package/dist/utils/types/utils.d.ts +0 -49
  28. package/dist/utils/types/utils.js +14 -52
  29. package/dist/utils/utils.d.ts +1 -97
  30. package/dist/utils/utils.js +197 -546
  31. package/package.json +4 -3
  32. package/src/data-structures/binary-tree/aa-tree.ts +1 -1
  33. package/src/data-structures/binary-tree/binary-tree.ts +84 -14
  34. package/src/data-structures/binary-tree/segment-tree.ts +45 -13
  35. package/src/data-structures/graph/abstract-graph.ts +58 -15
  36. package/src/data-structures/graph/directed-graph.ts +14 -5
  37. package/src/data-structures/graph/undirected-graph.ts +23 -6
  38. package/src/data-structures/hash/coordinate-map.ts +13 -1
  39. package/src/data-structures/hash/coordinate-set.ts +13 -1
  40. package/src/data-structures/heap/heap.ts +31 -0
  41. package/src/data-structures/linked-list/doubly-linked-list.ts +68 -11
  42. package/src/data-structures/linked-list/singly-linked-list.ts +312 -334
  43. package/src/data-structures/priority-queue/priority-queue.ts +15 -2
  44. package/src/data-structures/queue/deque.ts +38 -8
  45. package/src/data-structures/types/abstract-graph.ts +3 -3
  46. package/src/utils/types/utils.ts +165 -167
  47. package/src/utils/utils.ts +209 -480
  48. package/tests/unit/data-structures/graph/directed-graph.test.ts +431 -8
@@ -1,13 +1,37 @@
1
- import { DirectedGraph, DirectedVertex, DirectedEdge } from '../../../../src';
1
+ import {DirectedEdge, DirectedGraph, DirectedVertex, VertexId} from '../../../../src';
2
2
 
3
- // TODO too few unit tests
4
- describe('DirectedGraph', () => {
3
+ class MyVertex extends DirectedVertex {
4
+ data: string;
5
+
6
+ constructor(id: VertexId, data: string) {
7
+ super(id);
8
+ this.data = data;
9
+ }
10
+ }
11
+
12
+ class MyEdge extends DirectedEdge {
13
+ data: string;
14
+
15
+ constructor(v1: VertexId, v2: VertexId, weight: number, data: string) {
16
+ super(v1, v2, weight);
17
+ this.data = data;
18
+ }
19
+ }
20
+
21
+ class MyGraph<V extends MyVertex, E extends MyEdge> extends DirectedGraph<V, E> {
22
+ constructor() {
23
+ super();
24
+ }
25
+ }
26
+
27
+ describe('DirectedGraph Test1', () => {
5
28
  let graph: DirectedGraph<DirectedVertex, DirectedEdge>;
6
29
 
7
30
  beforeEach(() => {
8
31
  graph = new DirectedGraph();
9
32
  });
10
33
 
34
+
11
35
  it('should add vertices', () => {
12
36
  const vertex1 = new DirectedVertex('A');
13
37
  const vertex2 = new DirectedVertex('B');
@@ -15,8 +39,8 @@ describe('DirectedGraph', () => {
15
39
  graph.addVertex(vertex1);
16
40
  graph.addVertex(vertex2);
17
41
 
18
- expect(graph.containsVertex(vertex1)).toBe(true);
19
- expect(graph.containsVertex(vertex2)).toBe(true);
42
+ expect(graph.hasVertex(vertex1)).toBe(true);
43
+ expect(graph.hasVertex(vertex2)).toBe(true);
20
44
  });
21
45
 
22
46
  it('should add edges', () => {
@@ -28,8 +52,8 @@ describe('DirectedGraph', () => {
28
52
  graph.addVertex(vertex2);
29
53
  graph.addEdge(edge);
30
54
 
31
- expect(graph.containsEdge('A', 'B')).toBe(true);
32
- expect(graph.containsEdge('B', 'A')).toBe(false);
55
+ expect(graph.hasEdge('A', 'B')).toBe(true);
56
+ expect(graph.hasEdge('B', 'A')).toBe(false);
33
57
  });
34
58
 
35
59
  it('should remove edges', () => {
@@ -42,7 +66,7 @@ describe('DirectedGraph', () => {
42
66
  graph.addEdge(edge);
43
67
 
44
68
  expect(graph.removeEdge(edge)).toBe(edge);
45
- expect(graph.containsEdge('A', 'B')).toBe(false);
69
+ expect(graph.hasEdge('A', 'B')).toBe(false);
46
70
  });
47
71
 
48
72
  // Add more test cases for other methods...
@@ -70,3 +94,402 @@ describe('DirectedGraph', () => {
70
94
 
71
95
  // Add more test cases for other methods...
72
96
  });
97
+
98
+
99
+ describe('DirectedGraph Test2 operations', () => {
100
+ const myGraph = new DirectedGraph<MyVertex, MyEdge>();
101
+
102
+ test('Add vertices', () => {
103
+ myGraph.addVertex(new MyVertex(1, 'data1'));
104
+ myGraph.addVertex(new MyVertex(2, 'data2'));
105
+ myGraph.addVertex(new MyVertex(3, 'data3'));
106
+ myGraph.addVertex(new MyVertex(4, 'data4'));
107
+ myGraph.addVertex(new MyVertex(5, 'data5'));
108
+ myGraph.addVertex(new MyVertex(6, 'data6'));
109
+ myGraph.addVertex(new MyVertex(7, 'data7'));
110
+ myGraph.addVertex(new MyVertex(8, 'data8'));
111
+ myGraph.addVertex(new MyVertex(9, 'data9'));
112
+
113
+ });
114
+
115
+ test('Add edges', () => {
116
+ myGraph.addVertex(new MyVertex(1, 'data1'));
117
+ myGraph.addVertex(new MyVertex(2, 'data2'));
118
+ myGraph.addEdge(new MyEdge(1, 2, 10, 'edge-data1-2'));
119
+ myGraph.addEdge(new MyEdge(2, 1, 20, 'edge-data2-1'));
120
+
121
+ expect(myGraph.edgeSet().length).toBe(2);
122
+ // TODO
123
+ expect(myGraph.getEdge(1, 2)).toBeInstanceOf(MyEdge);
124
+ expect(myGraph.getEdge(2, 1)).toBeInstanceOf(MyEdge);
125
+ });
126
+
127
+ test('Get edge', () => {
128
+
129
+ const edge1 = myGraph.getEdge(1, 2);
130
+ const edge2 = myGraph.getEdge(myGraph.getVertex(1), myGraph.getVertex(2));
131
+ const edge3 = myGraph.getEdge(1, '100');
132
+
133
+ expect(edge1).toBeInstanceOf(MyEdge);
134
+ edge1 && expect(edge1.src).toBe(1);
135
+ expect(edge1).toEqual(edge2);
136
+ expect(edge3).toBeNull();
137
+ });
138
+
139
+ test('Edge set and vertex set', () => {
140
+ const edges = myGraph.edgeSet();
141
+ const vertices = myGraph.vertexSet();
142
+
143
+ });
144
+
145
+ test('Remove edge between vertices', () => {
146
+ myGraph.addVertex(new MyVertex(1, 'data1'));
147
+ myGraph.addVertex(new MyVertex(2, 'data2'));
148
+ myGraph.addEdge(new MyEdge(1, 2, 10, 'edge-data1-2'));
149
+
150
+ const removedEdge = myGraph.removeEdgeBetween(1, 2);
151
+ const edgeAfterRemoval = myGraph.getEdge(1, 2);
152
+
153
+ expect(removedEdge).toBeInstanceOf(MyEdge);
154
+ if (removedEdge) {
155
+ removedEdge && expect(removedEdge.data).toBe('edge-data1-2');
156
+ removedEdge && expect(removedEdge.src).toBe(1)
157
+ }
158
+ expect(edgeAfterRemoval).toBeNull();
159
+ });
160
+
161
+ test('Topological sort', () => {
162
+
163
+ const sorted = myGraph.topologicalSort();
164
+
165
+ expect(sorted).toBeInstanceOf(Array);
166
+ if (sorted && sorted.length > 0) {
167
+ expect(sorted.length).toBe(9);
168
+ expect(sorted[0].data).toBe('data9');
169
+ expect(sorted[3].data).toBe('data6');
170
+ expect(sorted[8].id).toBe(1);
171
+ }
172
+
173
+ });
174
+
175
+ test('Minimum path between vertices', () => {
176
+ myGraph.addVertex(new MyVertex(1, 'data1'));
177
+ myGraph.addVertex(new MyVertex(2, 'data2'));
178
+ myGraph.addEdge(new MyEdge(1, 2, 10, 'edge-data1-2'));
179
+
180
+ const minPath = myGraph.getMinPathBetween(1, 2);
181
+ });
182
+
183
+ test('All paths between vertices', () => {
184
+ // Add vertices and edges as needed for this test
185
+ myGraph.addVertex(new MyVertex(1, 'data1'));
186
+ myGraph.addVertex(new MyVertex(2, 'data2'));
187
+ myGraph.addEdge(new MyEdge(1, 2, 10, 'edge-data1-2'));
188
+
189
+ const allPaths = myGraph.getAllPathsBetween(1, 2);
190
+
191
+ // Add expect statements here to verify the allPaths
192
+ });
193
+ });
194
+
195
+
196
+ describe('DirectedGraph Test3', () => {
197
+ const myGraph = new DirectedGraph<MyVertex, MyEdge>();
198
+
199
+ it('should test graph operations', () => {
200
+ const vertex1 = new MyVertex(1, 'data1');
201
+ const vertex2 = new MyVertex(2, 'data2');
202
+ const vertex3 = new MyVertex(3, 'data3');
203
+ const vertex4 = new MyVertex(4, 'data4');
204
+ const vertex5 = new MyVertex(5, 'data5');
205
+ const vertex6 = new MyVertex(6, 'data6');
206
+ const vertex7 = new MyVertex(7, 'data7');
207
+ const vertex8 = new MyVertex(8, 'data8');
208
+ const vertex9 = new MyVertex(9, 'data9');
209
+ myGraph.addVertex(vertex1);
210
+ myGraph.addVertex(vertex2);
211
+ myGraph.addVertex(vertex3);
212
+ myGraph.addVertex(vertex4);
213
+ myGraph.addVertex(vertex5);
214
+ myGraph.addVertex(vertex6);
215
+ myGraph.addVertex(vertex7);
216
+ myGraph.addVertex(vertex8);
217
+ myGraph.addVertex(vertex9);
218
+
219
+ myGraph.addEdge(new MyEdge(1, 2, 10, 'edge-data1-2'));
220
+ myGraph.addEdge(new MyEdge(2, 1, 20, 'edge-data2-1'));
221
+
222
+ expect(myGraph.getEdge(1, 2)).toBeTruthy();
223
+ expect(myGraph.getEdge(2, 1)).toBeTruthy();
224
+ expect(myGraph.getEdge(1, '100')).toBeFalsy();
225
+
226
+ // Add the rest of your assertions here...
227
+
228
+ myGraph.removeEdgeBetween(1, 2);
229
+ expect(myGraph.getEdge(1, 2)).toBeFalsy();
230
+
231
+ myGraph.addEdge(new MyEdge(3, 1, 3, 'edge-data-3-1'));
232
+
233
+ myGraph.addEdge(new MyEdge(1, 9, 19, 'edge-data1-9'));
234
+ myGraph.addEdge(new MyEdge(9, 7, 97, 'edge-data9-7'));
235
+
236
+ myGraph.addEdge(new MyEdge(7, 9, 79, 'edge-data7-9'));
237
+
238
+ myGraph.addEdge(new MyEdge(1, 4, 14, 'edge-data1-4'));
239
+
240
+ myGraph.addEdge(new MyEdge(4, 7, 47, 'edge-data4-7'));
241
+
242
+ myGraph.addEdge(new MyEdge(1, 2, 12, 'edge-data1-2'));
243
+
244
+ myGraph.addEdge(new MyEdge(2, 3, 23, 'edge-data2-3'));
245
+
246
+ myGraph.addEdge(new MyEdge(3, 5, 35, 'edge-data3-5'));
247
+
248
+ myGraph.addEdge(new MyEdge(5, 7, 57, 'edge-data5-7'));
249
+
250
+ myGraph.addEdge(new MyEdge(7, 3, 73, 'edge-data7-3'));
251
+ const topologicalSorted = myGraph.topologicalSort();
252
+ expect(topologicalSorted).toBeNull();
253
+
254
+ const minPath1to7 = myGraph.getMinPathBetween(1, 7);
255
+
256
+ expect(minPath1to7).toBeInstanceOf(Array);
257
+ if (minPath1to7 && minPath1to7.length > 0) {
258
+ expect(minPath1to7).toHaveLength(3);
259
+ expect(minPath1to7[0]).toBeInstanceOf(MyVertex);
260
+ expect(minPath1to7[0].id).toBe(1);
261
+ expect(minPath1to7[1].id).toBe(9);
262
+ expect(minPath1to7[2].id).toBe(7);
263
+ }
264
+
265
+ const fordResult1 = myGraph.bellmanFord(1);
266
+ expect(fordResult1).toBeTruthy();
267
+ expect(fordResult1.hasNegativeCycle).toBeUndefined();
268
+ const {distMap, preMap, paths, min, minPath} = fordResult1;
269
+ expect(distMap).toBeInstanceOf(Map);
270
+ expect(distMap.size).toBe(9);
271
+ expect(distMap.get(vertex1)).toBe(0);
272
+ expect(distMap.get(vertex2)).toBe(12);
273
+ expect(distMap.get(vertex3)).toBe(35);
274
+ expect(distMap.get(vertex4)).toBe(14);
275
+ expect(distMap.get(vertex5)).toBe(70);
276
+ expect(distMap.get(vertex6)).toBe(Infinity);
277
+ expect(distMap.get(vertex7)).toBe(61);
278
+ expect(distMap.get(vertex8)).toBe(Infinity);
279
+ expect(distMap.get(vertex9)).toBe(19);
280
+
281
+ expect(preMap).toBeInstanceOf(Map);
282
+ expect(preMap.size).toBe(0);
283
+
284
+ expect(paths).toBeInstanceOf(Array);
285
+ expect(paths.length).toBe(0);
286
+ expect(min).toBe(Infinity);
287
+ expect(minPath).toBeInstanceOf(Array);
288
+
289
+
290
+ const floydResult = myGraph.floyd();
291
+ expect(floydResult).toBeTruthy();
292
+ if (floydResult) {
293
+ const {costs, predecessor} = floydResult;
294
+ expect(costs).toBeInstanceOf(Array);
295
+ expect(costs.length).toBe(9);
296
+ expect(costs[0]).toEqual([32, 12, 35, 14, 70, Infinity, 61, Infinity, 19]);
297
+ expect(costs[1]).toEqual([20, 32, 23, 34, 58, Infinity, 81, Infinity, 39]);
298
+ expect(costs[2]).toEqual([3, 15, 38, 17, 35, Infinity, 64, Infinity, 22]);
299
+ expect(costs[3]).toEqual([123, 135, 120, 137, 155, Infinity, 47, Infinity, 126]);
300
+ expect(costs[4]).toEqual([133, 145, 130, 147, 165, Infinity, 57, Infinity, 136]);
301
+ expect(costs[5]).toEqual([Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity]);
302
+ expect(costs[6]).toEqual([76, 88, 73, 90, 108, Infinity, 137, Infinity, 79]);
303
+ expect(costs[7]).toEqual([Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity]);
304
+ expect(costs[8]).toEqual([173, 185, 170, 187, 205, Infinity, 97, Infinity, 176]);
305
+
306
+ expect(predecessor).toBeInstanceOf(Array);
307
+ expect(predecessor.length).toBe(9);
308
+ expect(predecessor[0]).toEqual([vertex2, null, vertex2, null, vertex3, null, vertex4, null, null]);
309
+ expect(predecessor[1]).toEqual([null, vertex1, null, vertex1, vertex3, null, vertex4, null, vertex1]);
310
+ expect(predecessor[5]).toEqual([null, null, null, null, null, null, null, null, null]);
311
+ expect(predecessor[7]).toEqual([null, null, null, null, null, null, null, null, null]);
312
+ expect(predecessor[8]).toEqual([vertex7, vertex7, vertex7, vertex7, vertex7, null, null, null, vertex7]);
313
+ }
314
+
315
+ const dijkstraRes12tt = myGraph.dijkstra(1, 2, true, true);
316
+
317
+ expect(dijkstraRes12tt).toBeTruthy();
318
+ if (dijkstraRes12tt) {
319
+ const {distMap, minDist, minPath, paths, preMap, seen} = dijkstraRes12tt;
320
+ expect(distMap).toBeInstanceOf(Map);
321
+ expect(distMap.size).toBe(9);
322
+ expect(distMap.get(vertex1)).toBe(0);
323
+ expect(distMap.get(vertex2)).toBe(12);
324
+ expect(distMap.get(vertex3)).toBe(Infinity);
325
+ expect(distMap.get(vertex4)).toBe(14);
326
+ expect(distMap.get(vertex5)).toBe(Infinity);
327
+ expect(distMap.get(vertex6)).toBe(Infinity);
328
+ expect(distMap.get(vertex7)).toBe(Infinity);
329
+ expect(distMap.get(vertex8)).toBe(Infinity);
330
+ expect(distMap.get(vertex9)).toBe(19);
331
+
332
+ expect(minDist).toBe(12);
333
+ expect(minPath).toBeInstanceOf(Array);
334
+ expect(minPath.length).toBe(2);
335
+ expect(minPath[0]).toBe(vertex1);
336
+ expect(minPath[1]).toBe(vertex2);
337
+
338
+ expect(paths).toBeInstanceOf(Array);
339
+ expect(paths.length).toBe(9);
340
+ expect(paths[0]).toBeInstanceOf(Array);
341
+ expect(paths[0][0]).toBe(vertex1);
342
+
343
+ expect(paths[1]).toBeInstanceOf(Array);
344
+ expect(paths[1][0]).toBe(vertex1);
345
+ expect(paths[1][1]).toBe(vertex2);
346
+
347
+ expect(paths[2]).toBeInstanceOf(Array);
348
+ expect(paths[2][0]).toBe(vertex3);
349
+ expect(paths[3]).toBeInstanceOf(Array);
350
+ expect(paths[3][0]).toBe(vertex1);
351
+ expect(paths[3][1]).toBe(vertex4);
352
+ expect(paths[4]).toBeInstanceOf(Array);
353
+ expect(paths[4][0]).toBe(vertex5);
354
+
355
+ expect(paths[5]).toBeInstanceOf(Array);
356
+ expect(paths[5][0]).toBe(vertex6);
357
+ expect(paths[6]).toBeInstanceOf(Array);
358
+ expect(paths[6][0]).toBe(vertex7);
359
+ expect(paths[7]).toBeInstanceOf(Array);
360
+ expect(paths[7][0]).toBe(vertex8);
361
+ expect(paths[8]).toBeInstanceOf(Array);
362
+ expect(paths[8][0]).toBe(vertex1);
363
+ expect(paths[8][1]).toBe(vertex9);
364
+
365
+ }
366
+
367
+ const dijkstraRes1ntt = myGraph.dijkstra(1, null, true, true);
368
+
369
+ expect(dijkstraRes1ntt).toBeTruthy();
370
+ if (dijkstraRes1ntt) {
371
+ const {distMap, minDist, minPath, paths, preMap, seen} = dijkstraRes1ntt;
372
+ expect(distMap).toBeInstanceOf(Map);
373
+ expect(distMap.size).toBe(9);
374
+ expect(distMap.get(vertex1)).toBe(0);
375
+ expect(distMap.get(vertex2)).toBe(12);
376
+ expect(distMap.get(vertex3)).toBe(35);
377
+ expect(distMap.get(vertex4)).toBe(14);
378
+ expect(distMap.get(vertex5)).toBe(70);
379
+ expect(distMap.get(vertex6)).toBe(Infinity);
380
+ expect(distMap.get(vertex7)).toBe(61);
381
+ expect(distMap.get(vertex8)).toBe(Infinity);
382
+ expect(distMap.get(vertex9)).toBe(19);
383
+
384
+ expect(minDist).toBe(12);
385
+ expect(minPath).toBeInstanceOf(Array);
386
+ expect(minPath.length).toBe(2);
387
+ expect(minPath[0]).toBe(vertex1);
388
+ expect(minPath[1]).toBe(vertex2);
389
+
390
+ expect(paths).toBeInstanceOf(Array);
391
+ expect(paths.length).toBe(9);
392
+ expect(paths[0]).toBeInstanceOf(Array);
393
+ expect(paths[0][0]).toBe(vertex1);
394
+
395
+ expect(paths[1]).toBeInstanceOf(Array);
396
+ expect(paths[1][0]).toBe(vertex1);
397
+ expect(paths[1][1]).toBe(vertex2);
398
+
399
+ expect(paths[2]).toBeInstanceOf(Array);
400
+ expect(paths[2][0]).toBe(vertex1);
401
+ expect(paths[2][1]).toBe(vertex2);
402
+ expect(paths[2][2]).toBe(vertex3);
403
+
404
+ expect(paths[3]).toBeInstanceOf(Array);
405
+ expect(paths[3][0]).toBe(vertex1);
406
+ expect(paths[3][1]).toBe(vertex4);
407
+
408
+ expect(paths[4]).toBeInstanceOf(Array);
409
+ expect(paths[4][0]).toBe(vertex1);
410
+ expect(paths[4][1]).toBe(vertex2);
411
+ expect(paths[4][2]).toBe(vertex3);
412
+ expect(paths[4][3]).toBe(vertex5);
413
+
414
+ expect(paths[5]).toBeInstanceOf(Array);
415
+ expect(paths[5][0]).toBe(vertex6);
416
+
417
+ expect(paths[6]).toBeInstanceOf(Array);
418
+ expect(paths[6][0]).toBe(vertex1);
419
+ expect(paths[6][1]).toBe(vertex4);
420
+ expect(paths[6][2]).toBe(vertex7);
421
+
422
+ expect(paths[7]).toBeInstanceOf(Array);
423
+ expect(paths[7][0]).toBe(vertex8);
424
+
425
+ expect(paths[8]).toBeInstanceOf(Array);
426
+ expect(paths[8][0]).toBe(vertex1);
427
+ expect(paths[8][1]).toBe(vertex9);
428
+
429
+ }
430
+
431
+ const dijkstraWithoutHeapRes1ntt = myGraph.dijkstraWithoutHeap(1, null, true, true);
432
+ expect(dijkstraWithoutHeapRes1ntt).toBeTruthy();
433
+ if (dijkstraWithoutHeapRes1ntt) {
434
+ const {distMap, minDist, minPath, paths, preMap, seen} = dijkstraWithoutHeapRes1ntt;
435
+ expect(distMap).toBeInstanceOf(Map);
436
+ expect(distMap.size).toBe(9);
437
+ expect(distMap.get(vertex1)).toBe(0);
438
+ expect(distMap.get(vertex2)).toBe(12);
439
+ expect(distMap.get(vertex3)).toBe(35);
440
+ expect(distMap.get(vertex4)).toBe(14);
441
+ expect(distMap.get(vertex5)).toBe(70);
442
+ expect(distMap.get(vertex6)).toBe(Infinity);
443
+ expect(distMap.get(vertex7)).toBe(61);
444
+ expect(distMap.get(vertex8)).toBe(Infinity);
445
+ expect(distMap.get(vertex9)).toBe(19);
446
+
447
+ expect(minDist).toBe(12);
448
+ expect(minPath).toBeInstanceOf(Array);
449
+ expect(minPath.length).toBe(2);
450
+ expect(minPath[0]).toBe(vertex1);
451
+ expect(minPath[1]).toBe(vertex2);
452
+
453
+ expect(paths).toBeInstanceOf(Array);
454
+ expect(paths.length).toBe(9);
455
+ expect(paths[0]).toBeInstanceOf(Array);
456
+ expect(paths[0][0]).toBe(vertex1);
457
+
458
+ expect(paths[1]).toBeInstanceOf(Array);
459
+ expect(paths[1][0]).toBe(vertex1);
460
+ expect(paths[1][1]).toBe(vertex2);
461
+
462
+ expect(paths[2]).toBeInstanceOf(Array);
463
+ expect(paths[2][0]).toBe(vertex1);
464
+ expect(paths[2][1]).toBe(vertex2);
465
+ expect(paths[2][2]).toBe(vertex3);
466
+
467
+ expect(paths[3]).toBeInstanceOf(Array);
468
+ expect(paths[3][0]).toBe(vertex1);
469
+ expect(paths[3][1]).toBe(vertex4);
470
+
471
+ expect(paths[4]).toBeInstanceOf(Array);
472
+ expect(paths[4][0]).toBe(vertex1);
473
+ expect(paths[4][1]).toBe(vertex2);
474
+ expect(paths[4][2]).toBe(vertex3);
475
+ expect(paths[4][3]).toBe(vertex5);
476
+
477
+ expect(paths[5]).toBeInstanceOf(Array);
478
+ expect(paths[5][0]).toBe(vertex6);
479
+
480
+ expect(paths[6]).toBeInstanceOf(Array);
481
+ expect(paths[6][0]).toBe(vertex1);
482
+ expect(paths[6][1]).toBe(vertex4);
483
+ expect(paths[6][2]).toBe(vertex7);
484
+
485
+ expect(paths[7]).toBeInstanceOf(Array);
486
+ expect(paths[7][0]).toBe(vertex8);
487
+
488
+ expect(paths[8]).toBeInstanceOf(Array);
489
+ expect(paths[8][0]).toBe(vertex1);
490
+ expect(paths[8][1]).toBe(vertex9);
491
+
492
+ }
493
+ });
494
+ });
495
+