data-structure-typed 1.52.4 → 1.52.5
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.
- package/CHANGELOG.md +1 -1
- package/README.md +13 -13
- package/README_zh-CN.md +216 -26
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +158 -158
- package/dist/cjs/data-structures/base/iterable-element-base.d.ts +1 -37
- package/dist/cjs/data-structures/base/iterable-element-base.js +1 -37
- package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
- package/dist/cjs/data-structures/base/iterable-entry-base.d.ts +2 -54
- package/dist/cjs/data-structures/base/iterable-entry-base.js +1 -49
- package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
- package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +0 -46
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +0 -46
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +82 -147
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +299 -331
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +1 -40
- package/dist/cjs/data-structures/binary-tree/bst.js +12 -44
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +0 -48
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +2 -50
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +9 -41
- package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +0 -75
- package/dist/cjs/data-structures/graph/abstract-graph.js +0 -75
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +0 -98
- package/dist/cjs/data-structures/graph/directed-graph.js +0 -98
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +0 -50
- package/dist/cjs/data-structures/graph/undirected-graph.js +0 -50
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +5 -92
- package/dist/cjs/data-structures/hash/hash-map.js +27 -111
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +0 -32
- package/dist/cjs/data-structures/heap/heap.js +0 -32
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +5 -88
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +1 -83
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +2 -84
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +1 -35
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +1 -35
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +1 -98
- package/dist/cjs/data-structures/queue/deque.js +3 -99
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +1 -54
- package/dist/cjs/data-structures/queue/queue.js +0 -53
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +1 -34
- package/dist/cjs/data-structures/stack/stack.js +1 -34
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/tree/tree.js +0 -1
- package/dist/cjs/data-structures/tree/tree.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +0 -64
- package/dist/cjs/data-structures/trie/trie.js +0 -64
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +6 -0
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/types/utils/utils.d.ts +13 -12
- package/dist/cjs/utils/number.d.ts +13 -0
- package/dist/cjs/utils/number.js +13 -0
- package/dist/cjs/utils/number.js.map +1 -1
- package/dist/cjs/utils/utils.d.ts +125 -3
- package/dist/cjs/utils/utils.js +177 -21
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/base/iterable-element-base.d.ts +1 -37
- package/dist/mjs/data-structures/base/iterable-element-base.js +1 -37
- package/dist/mjs/data-structures/base/iterable-entry-base.d.ts +2 -54
- package/dist/mjs/data-structures/base/iterable-entry-base.js +1 -49
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
- package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +0 -46
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +0 -46
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +82 -147
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +298 -332
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +1 -40
- package/dist/mjs/data-structures/binary-tree/bst.js +12 -44
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +0 -48
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +2 -50
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
- package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +9 -41
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +0 -75
- package/dist/mjs/data-structures/graph/abstract-graph.js +0 -75
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +0 -98
- package/dist/mjs/data-structures/graph/directed-graph.js +0 -98
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +0 -50
- package/dist/mjs/data-structures/graph/undirected-graph.js +0 -50
- package/dist/mjs/data-structures/hash/hash-map.d.ts +5 -92
- package/dist/mjs/data-structures/hash/hash-map.js +27 -111
- package/dist/mjs/data-structures/heap/heap.d.ts +0 -32
- package/dist/mjs/data-structures/heap/heap.js +0 -32
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +5 -88
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +1 -83
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +2 -84
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +1 -35
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +1 -35
- package/dist/mjs/data-structures/queue/deque.d.ts +1 -98
- package/dist/mjs/data-structures/queue/deque.js +3 -99
- package/dist/mjs/data-structures/queue/queue.d.ts +1 -54
- package/dist/mjs/data-structures/queue/queue.js +0 -53
- package/dist/mjs/data-structures/stack/stack.d.ts +1 -34
- package/dist/mjs/data-structures/stack/stack.js +1 -34
- package/dist/mjs/data-structures/tree/tree.js +0 -1
- package/dist/mjs/data-structures/trie/trie.d.ts +0 -64
- package/dist/mjs/data-structures/trie/trie.js +0 -64
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +5 -1
- package/dist/mjs/types/utils/utils.d.ts +13 -12
- package/dist/mjs/utils/number.d.ts +13 -0
- package/dist/mjs/utils/number.js +13 -0
- package/dist/mjs/utils/utils.d.ts +125 -3
- package/dist/mjs/utils/utils.js +177 -21
- package/dist/umd/data-structure-typed.js +408 -1474
- package/dist/umd/data-structure-typed.min.js +5 -4
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +6 -6
- package/src/data-structures/base/iterable-element-base.ts +2 -42
- package/src/data-structures/base/iterable-entry-base.ts +3 -62
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +8 -48
- package/src/data-structures/binary-tree/avl-tree.ts +0 -57
- package/src/data-structures/binary-tree/binary-tree.ts +329 -358
- package/src/data-structures/binary-tree/bst.ts +11 -54
- package/src/data-structures/binary-tree/rb-tree.ts +2 -62
- package/src/data-structures/binary-tree/tree-multi-map.ts +8 -48
- package/src/data-structures/graph/abstract-graph.ts +0 -92
- package/src/data-structures/graph/directed-graph.ts +0 -122
- package/src/data-structures/graph/undirected-graph.ts +0 -62
- package/src/data-structures/hash/hash-map.ts +29 -133
- package/src/data-structures/heap/heap.ts +0 -40
- package/src/data-structures/linked-list/doubly-linked-list.ts +5 -112
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -104
- package/src/data-structures/linked-list/skip-linked-list.ts +1 -44
- package/src/data-structures/queue/deque.ts +2 -125
- package/src/data-structures/queue/queue.ts +1 -68
- package/src/data-structures/stack/stack.ts +1 -43
- package/src/data-structures/tree/tree.ts +1 -1
- package/src/data-structures/trie/trie.ts +0 -80
- package/src/types/data-structures/binary-tree/binary-tree.ts +8 -1
- package/src/types/utils/utils.ts +17 -15
- package/src/utils/number.ts +13 -0
- package/src/utils/utils.ts +174 -18
- package/test/config.ts +8 -0
- package/test/integration/all-in-one.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +13 -13
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +18 -13
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +471 -64
- package/test/unit/data-structures/binary-tree/bst.test.ts +167 -23
- package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +136 -13
- package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +18 -13
- package/test/unit/data-structures/graph/directed-graph.test.ts +46 -32
- package/test/unit/data-structures/graph/map-graph.test.ts +24 -2
- package/test/unit/data-structures/graph/undirected-graph.test.ts +24 -24
- package/test/unit/data-structures/hash/hash-map.test.ts +225 -35
- package/test/unit/data-structures/heap/heap.test.ts +47 -39
- package/test/unit/data-structures/heap/min-heap.test.ts +5 -5
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +34 -4
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +32 -0
- package/test/unit/data-structures/matrix/matrix.test.ts +35 -5
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +31 -0
- package/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +18 -0
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +17 -0
- package/test/unit/data-structures/queue/deque.test.ts +288 -47
- package/test/unit/data-structures/queue/queue.test.ts +62 -37
- package/test/unit/data-structures/stack/stack.test.ts +30 -5
- package/test/unit/data-structures/tree/tree.test.ts +58 -0
- package/test/unit/data-structures/trie/trie.test.ts +46 -5
- package/test/unit/utils/utils.test.ts +169 -0
|
@@ -139,14 +139,6 @@ class MyDirectedGraph<
|
|
|
139
139
|
override createEdge(src: VertexKey, dest: VertexKey, weight?: number, value?: E): EO {
|
|
140
140
|
return new MyEdge(src, dest, weight ?? 1, value) as EO;
|
|
141
141
|
}
|
|
142
|
-
|
|
143
|
-
setInEdgeMap(value: Map<VO, EO[]>) {
|
|
144
|
-
this._inEdgeMap = value;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
setOutEdgeMap(value: Map<VO, EO[]>) {
|
|
148
|
-
this._outEdgeMap = value;
|
|
149
|
-
}
|
|
150
142
|
}
|
|
151
143
|
|
|
152
144
|
describe('Inherit from DirectedGraph and perform operations', () => {
|
|
@@ -172,8 +164,8 @@ describe('Inherit from DirectedGraph and perform operations', () => {
|
|
|
172
164
|
myGraph.addVertex(2, 'data2');
|
|
173
165
|
myGraph.addEdge(1, 2, 10, 'edge-data1-2');
|
|
174
166
|
myGraph.addEdge(new MyEdge(2, 1, 20, 'edge-data2-1'));
|
|
175
|
-
myGraph.
|
|
176
|
-
myGraph.
|
|
167
|
+
myGraph.inEdgeMap = myGraph.inEdgeMap;
|
|
168
|
+
myGraph.outEdgeMap = myGraph.outEdgeMap;
|
|
177
169
|
|
|
178
170
|
expect(myGraph.edgeSet().length).toBe(2);
|
|
179
171
|
// TODO
|
|
@@ -205,11 +197,14 @@ describe('Inherit from DirectedGraph and perform operations', () => {
|
|
|
205
197
|
});
|
|
206
198
|
|
|
207
199
|
it('Remove edge between vertexMap', () => {
|
|
200
|
+
expect(myGraph.isEmpty()).toBe(true);
|
|
208
201
|
myGraph.addVertex(1, 'data1');
|
|
209
202
|
myGraph.addVertex(2, 'data2');
|
|
210
203
|
myGraph.addEdge(1, 2, 10, 'edge-data1-2');
|
|
204
|
+
expect(myGraph.isEmpty()).toBe(false);
|
|
211
205
|
|
|
212
206
|
const removedEdge = myGraph.deleteEdgeSrcToDest(1, 2);
|
|
207
|
+
expect(myGraph.deleteEdgeSrcToDest(2, 10)).toBe(undefined);
|
|
213
208
|
const edgeAfterRemoval = myGraph.getEdge(1, 2);
|
|
214
209
|
|
|
215
210
|
expect(removedEdge).toBeInstanceOf(MyEdge);
|
|
@@ -220,6 +215,25 @@ describe('Inherit from DirectedGraph and perform operations', () => {
|
|
|
220
215
|
expect(edgeAfterRemoval).toBe(undefined);
|
|
221
216
|
});
|
|
222
217
|
|
|
218
|
+
it('should clear', () => {
|
|
219
|
+
expect(myGraph.isEmpty()).toBe(true);
|
|
220
|
+
myGraph.addVertex(1, 'data1');
|
|
221
|
+
myGraph.addVertex(2, 'data2');
|
|
222
|
+
myGraph.addEdge(1, 2, 10, 'edge-data1-2');
|
|
223
|
+
expect(myGraph.isEmpty()).toBe(false);
|
|
224
|
+
myGraph.clear();
|
|
225
|
+
expect(myGraph.isEmpty()).toBe(true);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('should clone', () => {
|
|
229
|
+
myGraph.addVertex(1, 'data1');
|
|
230
|
+
myGraph.addVertex(2, 'data2');
|
|
231
|
+
myGraph.addEdge(1, 2, 10, 'edge-data1-2');
|
|
232
|
+
const cloned = myGraph.clone();
|
|
233
|
+
expect(cloned.hasVertex(1)).toBe(true);
|
|
234
|
+
expect(cloned.hasEdge(1, 2)).toBe(true);
|
|
235
|
+
});
|
|
236
|
+
|
|
223
237
|
it('Topological sort', () => {
|
|
224
238
|
const sorted = myGraph.topologicalSort();
|
|
225
239
|
|
|
@@ -656,7 +670,7 @@ describe('DirectedGraph iterative Methods', () => {
|
|
|
656
670
|
vertexMap.forEach(vertex => graph.addVertex(vertex));
|
|
657
671
|
});
|
|
658
672
|
|
|
659
|
-
|
|
673
|
+
it('[Symbol.iterator] should iterate over all vertexMap', () => {
|
|
660
674
|
const iteratedVertices = [];
|
|
661
675
|
for (const vertex of graph) {
|
|
662
676
|
iteratedVertices.push(vertex[0]);
|
|
@@ -664,13 +678,13 @@ describe('DirectedGraph iterative Methods', () => {
|
|
|
664
678
|
expect(iteratedVertices).toEqual(vertexMap);
|
|
665
679
|
});
|
|
666
680
|
|
|
667
|
-
|
|
681
|
+
it('forEach should apply a function to each vertex', () => {
|
|
668
682
|
const result: VertexKey[] = [];
|
|
669
683
|
graph.forEach((value, key) => key && result.push(key));
|
|
670
684
|
expect(result).toEqual(vertexMap);
|
|
671
685
|
});
|
|
672
686
|
|
|
673
|
-
|
|
687
|
+
it('filter should return vertexMap that satisfy the condition', () => {
|
|
674
688
|
const filtered = graph.filter((value, vertex) => vertex === 'A' || vertex === 'B');
|
|
675
689
|
expect(filtered).toEqual([
|
|
676
690
|
['A', undefined],
|
|
@@ -678,17 +692,17 @@ describe('DirectedGraph iterative Methods', () => {
|
|
|
678
692
|
]);
|
|
679
693
|
});
|
|
680
694
|
|
|
681
|
-
|
|
695
|
+
it('map should apply a function to each vertex and return a new array', () => {
|
|
682
696
|
const mapped = graph.map((value, vertex) => vertex + '_mapped');
|
|
683
697
|
expect(mapped).toEqual(vertexMap.map(v => v + '_mapped'));
|
|
684
698
|
});
|
|
685
699
|
|
|
686
|
-
|
|
700
|
+
it('reduce should accumulate a value based on each vertex', () => {
|
|
687
701
|
const concatenated = graph.reduce((acc, value, key) => acc + key, '');
|
|
688
702
|
expect(concatenated).toBe(vertexMap.join(''));
|
|
689
703
|
});
|
|
690
704
|
|
|
691
|
-
|
|
705
|
+
it('Removing an edge of a DirectedGraph should delete additional edges', () => {
|
|
692
706
|
const dg = new DirectedGraph();
|
|
693
707
|
dg.addVertex('hello');
|
|
694
708
|
dg.addVertex('hi');
|
|
@@ -705,7 +719,7 @@ describe('DirectedGraph iterative Methods', () => {
|
|
|
705
719
|
expect(dg.incomingEdgesOf('Hi')).toEqual([]);
|
|
706
720
|
});
|
|
707
721
|
|
|
708
|
-
|
|
722
|
+
it('Removing a vertex of a DirectedGraph should delete additional edges', () => {
|
|
709
723
|
const graph = new DirectedGraph();
|
|
710
724
|
|
|
711
725
|
graph.addVertex('Hello');
|
|
@@ -717,7 +731,7 @@ describe('DirectedGraph iterative Methods', () => {
|
|
|
717
731
|
expect(graph.incomingEdgesOf('Hi')).toEqual([]);
|
|
718
732
|
});
|
|
719
733
|
|
|
720
|
-
|
|
734
|
+
it('Removing a vertex from a DirectedGraph should remove its edges', () => {
|
|
721
735
|
const dg = new DirectedGraph();
|
|
722
736
|
dg.addVertex('hello');
|
|
723
737
|
dg.addVertex('world');
|
|
@@ -740,7 +754,7 @@ describe('DirectedGraph iterative Methods', () => {
|
|
|
740
754
|
});
|
|
741
755
|
|
|
742
756
|
describe('DirectedGraph getCycles', () => {
|
|
743
|
-
|
|
757
|
+
it('should getCycles return correct result', () => {
|
|
744
758
|
const graph = new DirectedGraph();
|
|
745
759
|
graph.addVertex('A');
|
|
746
760
|
graph.addVertex('B');
|
|
@@ -758,7 +772,7 @@ describe('DirectedGraph getCycles', () => {
|
|
|
758
772
|
expect(cycles[0]).toEqual(['B', 'D', 'E']);
|
|
759
773
|
});
|
|
760
774
|
|
|
761
|
-
|
|
775
|
+
it('should simple cycles graph getCycles return correct result', () => {
|
|
762
776
|
const graph = new DirectedGraph();
|
|
763
777
|
|
|
764
778
|
graph.addVertex('A');
|
|
@@ -779,7 +793,7 @@ describe('DirectedGraph getCycles', () => {
|
|
|
779
793
|
]);
|
|
780
794
|
});
|
|
781
795
|
|
|
782
|
-
|
|
796
|
+
it('should 3 cycles graph getCycles return correct result', () => {
|
|
783
797
|
const graph = new DirectedGraph();
|
|
784
798
|
|
|
785
799
|
graph.addVertex('A');
|
|
@@ -812,7 +826,7 @@ describe('DirectedGraph getCycles', () => {
|
|
|
812
826
|
});
|
|
813
827
|
|
|
814
828
|
describe('DirectedGraph tarjan', () => {
|
|
815
|
-
|
|
829
|
+
it('should simple cycles graph tarjan cycles return correct result', () => {
|
|
816
830
|
const graph = new DirectedGraph();
|
|
817
831
|
|
|
818
832
|
graph.addVertex('A');
|
|
@@ -853,14 +867,14 @@ describe('DirectedGraph tarjan', () => {
|
|
|
853
867
|
return graph;
|
|
854
868
|
}
|
|
855
869
|
|
|
856
|
-
|
|
870
|
+
it('should tarjan cycles return correct result', () => {
|
|
857
871
|
const graph = createExampleGraph1();
|
|
858
872
|
const cycles = graph.getCycles();
|
|
859
873
|
expect(cycles.length).toBe(1);
|
|
860
874
|
expect(cycles).toEqual([['B', 'D', 'E']]);
|
|
861
875
|
});
|
|
862
876
|
|
|
863
|
-
|
|
877
|
+
it('should tarjan SCCs return correct result', () => {
|
|
864
878
|
const graph = createExampleGraph1();
|
|
865
879
|
const sccs = graph.tarjan().SCCs;
|
|
866
880
|
expect(sccs.size).toBe(3);
|
|
@@ -878,7 +892,7 @@ describe('DirectedGraph tarjan', () => {
|
|
|
878
892
|
return graph;
|
|
879
893
|
}
|
|
880
894
|
|
|
881
|
-
|
|
895
|
+
it('should 3 cycles graph tarjan cycles return correct result', () => {
|
|
882
896
|
const graph = createExampleGraph2();
|
|
883
897
|
const cycles = graph.getCycles();
|
|
884
898
|
expect(cycles.length).toBe(3);
|
|
@@ -889,7 +903,7 @@ describe('DirectedGraph tarjan', () => {
|
|
|
889
903
|
]);
|
|
890
904
|
});
|
|
891
905
|
|
|
892
|
-
|
|
906
|
+
it('should 3 cycles graph tarjan SCCs return correct result', () => {
|
|
893
907
|
const graph = createExampleGraph2();
|
|
894
908
|
const sccs = graph.tarjan().SCCs;
|
|
895
909
|
expect(sccs.size).toBe(2);
|
|
@@ -919,7 +933,7 @@ describe('DirectedGraph tarjan', () => {
|
|
|
919
933
|
return graph;
|
|
920
934
|
}
|
|
921
935
|
|
|
922
|
-
|
|
936
|
+
it('should cuttable graph tarjan cycles return correct result', () => {
|
|
923
937
|
const graph = createExampleGraph3();
|
|
924
938
|
const cycles = graph.getCycles();
|
|
925
939
|
expect(cycles.length).toBe(2);
|
|
@@ -929,7 +943,7 @@ describe('DirectedGraph tarjan', () => {
|
|
|
929
943
|
]);
|
|
930
944
|
});
|
|
931
945
|
|
|
932
|
-
|
|
946
|
+
it('should cuttable graph tarjan SCCs return correct result', () => {
|
|
933
947
|
const graph = createExampleGraph3();
|
|
934
948
|
const sccs = graph.tarjan().SCCs;
|
|
935
949
|
expect(sccs.size).toBe(3);
|
|
@@ -951,7 +965,7 @@ describe('DirectedGraph tarjan', () => {
|
|
|
951
965
|
return graph;
|
|
952
966
|
}
|
|
953
967
|
|
|
954
|
-
|
|
968
|
+
it('should more cuttable graph tarjan cycles return correct result', () => {
|
|
955
969
|
const graph = createExampleGraph4();
|
|
956
970
|
const cycles = graph.getCycles();
|
|
957
971
|
expect(cycles.length).toBe(4);
|
|
@@ -963,7 +977,7 @@ describe('DirectedGraph tarjan', () => {
|
|
|
963
977
|
]);
|
|
964
978
|
});
|
|
965
979
|
|
|
966
|
-
|
|
980
|
+
it('should more cuttable graph tarjan SCCs return correct result', () => {
|
|
967
981
|
const graph = createExampleGraph4();
|
|
968
982
|
const sccs = graph.tarjan().SCCs;
|
|
969
983
|
expect(sccs.size).toBe(3);
|
|
@@ -976,7 +990,7 @@ describe('DirectedGraph tarjan', () => {
|
|
|
976
990
|
return graph;
|
|
977
991
|
}
|
|
978
992
|
|
|
979
|
-
|
|
993
|
+
it('should uncuttable graph tarjan cycles return correct result', () => {
|
|
980
994
|
const graph = createExampleGraph5();
|
|
981
995
|
const cycles = graph.getCycles();
|
|
982
996
|
expect(cycles.length).toBe(4);
|
|
@@ -988,7 +1002,7 @@ describe('DirectedGraph tarjan', () => {
|
|
|
988
1002
|
]);
|
|
989
1003
|
});
|
|
990
1004
|
|
|
991
|
-
|
|
1005
|
+
it('should uncuttable graph tarjan SCCs return correct result', () => {
|
|
992
1006
|
const graph = createExampleGraph5();
|
|
993
1007
|
const sccs = graph.tarjan().SCCs;
|
|
994
1008
|
expect(sccs.size).toBe(3);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { MapEdge, MapGraph, MapVertex } from '../../../../src';
|
|
2
2
|
|
|
3
3
|
describe('MapGraph Operation Test', () => {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
let mapGraph: MapGraph;
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
mapGraph = new MapGraph([5.500338, 100.173665]);
|
|
6
7
|
|
|
7
8
|
mapGraph.addVertex(new MapVertex('Surin', '', 5.466724, 100.274805));
|
|
8
9
|
mapGraph.addVertex(new MapVertex('Batu Feringgi Beach', '', 5.475141, 100.27667));
|
|
@@ -27,6 +28,9 @@ describe('MapGraph Operation Test', () => {
|
|
|
27
28
|
mapGraph.addEdge('Trinity Auto', 'Saanen Goat Farm', 26.3);
|
|
28
29
|
mapGraph.addEdge('The Breeza', 'Penang Airport', 24.8);
|
|
29
30
|
mapGraph.addEdge('Penang Airport', 'Saanen Goat Farm', 21.2);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('dijkstra shortest path', () => {
|
|
30
34
|
const expected1 = ['Surin', 'Lotus', 'The Breeza', 'Trinity Auto', 'Saanen Goat Farm'];
|
|
31
35
|
|
|
32
36
|
const minPathBetween = mapGraph.getMinPathBetween('Surin', 'Saanen Goat Farm');
|
|
@@ -42,6 +46,24 @@ describe('MapGraph Operation Test', () => {
|
|
|
42
46
|
expect(surinToSaanenGoatFarmViaDij?.minPath.map(v => v.key)).toEqual(expected2);
|
|
43
47
|
expect(surinToSaanenGoatFarmViaDij?.minDist).toBe(25.2);
|
|
44
48
|
});
|
|
49
|
+
|
|
50
|
+
it('should clone', () => {
|
|
51
|
+
const cloned = mapGraph.clone();
|
|
52
|
+
const expected1 = ['Surin', 'Lotus', 'The Breeza', 'Trinity Auto', 'Saanen Goat Farm'];
|
|
53
|
+
|
|
54
|
+
const minPathBetween = cloned.getMinPathBetween('Surin', 'Saanen Goat Farm');
|
|
55
|
+
expect(minPathBetween?.map(v => v.key)).toEqual(expected1);
|
|
56
|
+
const surinToSaanenGoatFarmDij = cloned.dijkstra('Surin', 'Saanen Goat Farm', true, true);
|
|
57
|
+
expect(surinToSaanenGoatFarmDij?.minPath.map(v => v.key)).toEqual(expected1);
|
|
58
|
+
expect(surinToSaanenGoatFarmDij?.minDist).toBe(41.1);
|
|
59
|
+
cloned.addEdge('Surin', 'Batu Feringgi Beach', 1.5);
|
|
60
|
+
const expected2 = ['Surin', 'Batu Feringgi Beach', 'Hard Rock Hotel', 'Saanen Goat Farm'];
|
|
61
|
+
const minPathBetweenViaBFB = cloned.getMinPathBetween('Surin', 'Saanen Goat Farm', true);
|
|
62
|
+
expect(minPathBetweenViaBFB?.map(v => v.key)).toEqual(expected2);
|
|
63
|
+
const surinToSaanenGoatFarmViaDij = cloned.dijkstra('Surin', 'Saanen Goat Farm', true, true);
|
|
64
|
+
expect(surinToSaanenGoatFarmViaDij?.minPath.map(v => v.key)).toEqual(expected2);
|
|
65
|
+
expect(surinToSaanenGoatFarmViaDij?.minDist).toBe(25.2);
|
|
66
|
+
});
|
|
45
67
|
});
|
|
46
68
|
|
|
47
69
|
describe('MapGraph', () => {
|
|
@@ -174,7 +174,7 @@ describe('UndirectedGraph', () => {
|
|
|
174
174
|
expect(minWeightedPath?.minPath?.[4]?.key).toBe('Intersection_5');
|
|
175
175
|
});
|
|
176
176
|
|
|
177
|
-
|
|
177
|
+
it('Removing an edge of a UndirectedGraph should not delete additional edges', () => {
|
|
178
178
|
const dg = new UndirectedGraph();
|
|
179
179
|
dg.addVertex('hello');
|
|
180
180
|
dg.addVertex('hi');
|
|
@@ -190,7 +190,7 @@ describe('UndirectedGraph', () => {
|
|
|
190
190
|
expect(dg.getEdge('hello', 'hey')).toBeInstanceOf(UndirectedEdge);
|
|
191
191
|
});
|
|
192
192
|
|
|
193
|
-
|
|
193
|
+
it('Removing a vertex of a UndirectedGraph should delete additional edges', () => {
|
|
194
194
|
const graph = new UndirectedGraph();
|
|
195
195
|
|
|
196
196
|
graph.addVertex('Hello');
|
|
@@ -202,7 +202,7 @@ describe('UndirectedGraph', () => {
|
|
|
202
202
|
expect(graph.edgesOf('Hi')).toEqual([]);
|
|
203
203
|
});
|
|
204
204
|
|
|
205
|
-
|
|
205
|
+
it('Removing a vertex from a UndirectedGraph should remove its edges', () => {
|
|
206
206
|
const dg = new UndirectedGraph();
|
|
207
207
|
dg.addVertex('hello');
|
|
208
208
|
dg.addVertex('world');
|
|
@@ -274,7 +274,7 @@ it('Should return Infinity if dest is not found', () => {
|
|
|
274
274
|
});
|
|
275
275
|
|
|
276
276
|
describe('UndirectedGraph getCycles', () => {
|
|
277
|
-
|
|
277
|
+
it('should getCycles return correct result', () => {
|
|
278
278
|
const graph = new UndirectedGraph();
|
|
279
279
|
graph.addVertex('A');
|
|
280
280
|
graph.addVertex('B');
|
|
@@ -296,7 +296,7 @@ describe('UndirectedGraph getCycles', () => {
|
|
|
296
296
|
]);
|
|
297
297
|
});
|
|
298
298
|
|
|
299
|
-
|
|
299
|
+
it('should simple cycles graph getCycles return correct result', () => {
|
|
300
300
|
const graph = new UndirectedGraph();
|
|
301
301
|
|
|
302
302
|
graph.addVertex('A');
|
|
@@ -318,7 +318,7 @@ describe('UndirectedGraph getCycles', () => {
|
|
|
318
318
|
]);
|
|
319
319
|
});
|
|
320
320
|
|
|
321
|
-
|
|
321
|
+
it('should 3 cycles graph getCycles return correct result', () => {
|
|
322
322
|
const graph = new UndirectedGraph();
|
|
323
323
|
|
|
324
324
|
graph.addVertex('A');
|
|
@@ -358,7 +358,7 @@ describe('UndirectedGraph getCycles', () => {
|
|
|
358
358
|
});
|
|
359
359
|
|
|
360
360
|
describe('UndirectedGraph tarjan', () => {
|
|
361
|
-
|
|
361
|
+
it('should simple cycles graph tarjan cycles return correct result', () => {
|
|
362
362
|
const graph = new UndirectedGraph();
|
|
363
363
|
|
|
364
364
|
graph.addVertex('A');
|
|
@@ -396,38 +396,38 @@ describe('UndirectedGraph tarjan', () => {
|
|
|
396
396
|
return graph;
|
|
397
397
|
}
|
|
398
398
|
|
|
399
|
-
|
|
399
|
+
it('should tarjan cut vertexes return correct result', () => {
|
|
400
400
|
const graph = createExampleGraph1();
|
|
401
401
|
const cutVertices = graph.tarjan().cutVertices;
|
|
402
402
|
expect(cutVertices.length).toBe(0);
|
|
403
403
|
});
|
|
404
404
|
|
|
405
|
-
|
|
405
|
+
it('should tarjan bridges return correct result', () => {
|
|
406
406
|
const graph = createExampleGraph1();
|
|
407
407
|
const bridges = graph.tarjan().bridges;
|
|
408
408
|
expect(bridges.length).toBe(0);
|
|
409
409
|
});
|
|
410
410
|
|
|
411
|
-
|
|
411
|
+
it('should 3 cycles graph tarjan cut vertexes return correct result', () => {
|
|
412
412
|
const graph = createExampleGraph1();
|
|
413
413
|
const cutVertices = graph.tarjan().cutVertices;
|
|
414
414
|
expect(cutVertices.length).toBe(0);
|
|
415
415
|
});
|
|
416
416
|
|
|
417
|
-
|
|
417
|
+
it('should 3 cycles graph tarjan bridges return correct result', () => {
|
|
418
418
|
const graph = createExampleGraph1();
|
|
419
419
|
const bridges = graph.tarjan().bridges;
|
|
420
420
|
expect(bridges.length).toBe(0);
|
|
421
421
|
});
|
|
422
422
|
|
|
423
|
-
|
|
423
|
+
it('should cuttable graph tarjan cut vertexes return correct result', () => {
|
|
424
424
|
const graph = createExampleGraph3();
|
|
425
425
|
const cutVertices = graph.tarjan().cutVertices;
|
|
426
426
|
expect(cutVertices.length).toBe(3);
|
|
427
427
|
expect(cutVertices.map(cv => cv.key)).toEqual(['B', 'E', 'A']);
|
|
428
428
|
});
|
|
429
429
|
|
|
430
|
-
|
|
430
|
+
it('should cuttable graph tarjan bridges return correct result', () => {
|
|
431
431
|
const graph = createExampleGraph3();
|
|
432
432
|
const bridges = graph.tarjan().bridges;
|
|
433
433
|
expect(bridges.length).toBe(2);
|
|
@@ -437,14 +437,14 @@ describe('UndirectedGraph tarjan', () => {
|
|
|
437
437
|
]);
|
|
438
438
|
});
|
|
439
439
|
|
|
440
|
-
|
|
440
|
+
it('should more cuttable graph tarjan cut vertexes return correct result', () => {
|
|
441
441
|
const graph = createExampleGraph4();
|
|
442
442
|
const cutVertices = graph.tarjan().cutVertices;
|
|
443
443
|
expect(cutVertices.length).toBe(4);
|
|
444
444
|
expect(cutVertices.map(cv => cv.key)).toEqual(['H', 'B', 'E', 'A']);
|
|
445
445
|
});
|
|
446
446
|
|
|
447
|
-
|
|
447
|
+
it('should more cuttable graph tarjan bridges return correct result', () => {
|
|
448
448
|
const graph = createExampleGraph4();
|
|
449
449
|
const bridges = graph.tarjan().bridges;
|
|
450
450
|
expect(bridges.length).toBe(2);
|
|
@@ -454,13 +454,13 @@ describe('UndirectedGraph tarjan', () => {
|
|
|
454
454
|
]);
|
|
455
455
|
});
|
|
456
456
|
|
|
457
|
-
|
|
457
|
+
it('should uncuttable graph tarjan cut vertexes return correct result', () => {
|
|
458
458
|
const graph = createExampleGraph5();
|
|
459
459
|
const cutVertices = graph.tarjan().cutVertices;
|
|
460
460
|
expect(cutVertices.length).toBe(1);
|
|
461
461
|
});
|
|
462
462
|
|
|
463
|
-
|
|
463
|
+
it('should uncuttable graph tarjan bridges return correct result', () => {
|
|
464
464
|
const graph = createExampleGraph5();
|
|
465
465
|
const bridges = graph.tarjan().bridges;
|
|
466
466
|
expect(bridges.length).toBe(0);
|
|
@@ -477,7 +477,7 @@ describe('UndirectedGraph tarjan', () => {
|
|
|
477
477
|
return graph;
|
|
478
478
|
}
|
|
479
479
|
|
|
480
|
-
|
|
480
|
+
it('should 3 cycles graph tarjan cycles return correct result', () => {
|
|
481
481
|
const graph = createExampleGraph2();
|
|
482
482
|
const cycles = graph.getCycles();
|
|
483
483
|
expect(cycles.length).toBe(10);
|
|
@@ -515,7 +515,7 @@ describe('UndirectedGraph tarjan', () => {
|
|
|
515
515
|
return graph;
|
|
516
516
|
}
|
|
517
517
|
|
|
518
|
-
|
|
518
|
+
it('should cuttable graph tarjan cycles return correct result', () => {
|
|
519
519
|
const graph = createExampleGraph3();
|
|
520
520
|
const cycles = graph.getCycles();
|
|
521
521
|
expect(cycles.length).toBe(2);
|
|
@@ -525,7 +525,7 @@ describe('UndirectedGraph tarjan', () => {
|
|
|
525
525
|
]);
|
|
526
526
|
});
|
|
527
527
|
|
|
528
|
-
//
|
|
528
|
+
// it('should cuttable graph tarjan CCs return correct result', () => {
|
|
529
529
|
// const graph = createExampleGraph3();
|
|
530
530
|
// const ccs = graph.tarjan().CCs;
|
|
531
531
|
// expect(ccs.size).toBe(3);
|
|
@@ -547,7 +547,7 @@ describe('UndirectedGraph tarjan', () => {
|
|
|
547
547
|
return graph;
|
|
548
548
|
}
|
|
549
549
|
|
|
550
|
-
|
|
550
|
+
it('should more cuttable graph tarjan cycles return correct result', () => {
|
|
551
551
|
const graph = createExampleGraph4();
|
|
552
552
|
const cycles = graph.getCycles();
|
|
553
553
|
expect(cycles.length).toBe(5);
|
|
@@ -560,7 +560,7 @@ describe('UndirectedGraph tarjan', () => {
|
|
|
560
560
|
]);
|
|
561
561
|
});
|
|
562
562
|
|
|
563
|
-
//
|
|
563
|
+
// it('should more cuttable graph tarjan SCCs return correct result', () => {
|
|
564
564
|
// const graph = createExampleGraph4();
|
|
565
565
|
// const ccs = graph.tarjan().CCs;
|
|
566
566
|
// expect(ccs.size).toBe(3);
|
|
@@ -573,7 +573,7 @@ describe('UndirectedGraph tarjan', () => {
|
|
|
573
573
|
return graph;
|
|
574
574
|
}
|
|
575
575
|
|
|
576
|
-
|
|
576
|
+
it('should uncuttable graph tarjan cycles return correct result', () => {
|
|
577
577
|
const graph = createExampleGraph5();
|
|
578
578
|
const cycles = graph.getCycles();
|
|
579
579
|
expect(cycles.length).toBe(13);
|
|
@@ -594,7 +594,7 @@ describe('UndirectedGraph tarjan', () => {
|
|
|
594
594
|
]);
|
|
595
595
|
});
|
|
596
596
|
|
|
597
|
-
//
|
|
597
|
+
// it('should uncuttable graph tarjan SCCs return correct result', () => {
|
|
598
598
|
// const graph = createExampleGraph5();
|
|
599
599
|
// const ccs = graph.tarjan().CCs;
|
|
600
600
|
// expect(ccs.size).toBe(3);
|