data-structure-typed 1.49.3 → 1.49.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 +70 -69
- package/README_zh-CN.md +44 -49
- package/benchmark/report.html +16 -16
- package/benchmark/report.json +187 -187
- package/dist/cjs/data-structures/base/iterable-base.d.ts +1 -1
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +2 -14
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +19 -49
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +0 -16
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +1 -43
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +2 -11
- package/dist/cjs/data-structures/graph/abstract-graph.js +3 -19
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.js +4 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +1 -1
- package/dist/cjs/data-structures/hash/hash-map.js +2 -2
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.js +2 -3
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
- package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/index.d.ts +0 -2
- package/dist/cjs/data-structures/matrix/index.js +0 -2
- package/dist/cjs/data-structures/matrix/index.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.d.ts +128 -10
- package/dist/cjs/data-structures/matrix/matrix.js +400 -15
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +2 -2
- package/dist/cjs/data-structures/queue/deque.js +5 -7
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
- package/dist/cjs/types/data-structures/heap/heap.d.ts +1 -1
- package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/cjs/utils/utils.d.ts +1 -0
- package/dist/cjs/utils/utils.js +6 -1
- package/dist/cjs/utils/utils.js.map +1 -1
- package/dist/mjs/data-structures/base/iterable-base.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +2 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +2 -14
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +20 -50
- package/dist/mjs/data-structures/binary-tree/bst.js +2 -1
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +2 -1
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +0 -16
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +3 -44
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +2 -11
- package/dist/mjs/data-structures/graph/abstract-graph.js +4 -20
- package/dist/mjs/data-structures/graph/directed-graph.js +4 -0
- package/dist/mjs/data-structures/hash/hash-map.d.ts +1 -1
- package/dist/mjs/data-structures/hash/hash-map.js +2 -2
- package/dist/mjs/data-structures/heap/heap.js +2 -3
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +1 -1
- package/dist/mjs/data-structures/matrix/index.d.ts +0 -2
- package/dist/mjs/data-structures/matrix/index.js +0 -2
- package/dist/mjs/data-structures/matrix/matrix.d.ts +128 -10
- package/dist/mjs/data-structures/matrix/matrix.js +399 -16
- package/dist/mjs/data-structures/queue/deque.d.ts +2 -2
- package/dist/mjs/data-structures/queue/deque.js +7 -9
- package/dist/mjs/data-structures/queue/queue.d.ts +1 -1
- package/dist/mjs/data-structures/queue/queue.js +1 -1
- package/dist/mjs/types/data-structures/base/base.d.ts +1 -1
- package/dist/mjs/types/data-structures/heap/heap.d.ts +1 -1
- package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
- package/dist/mjs/utils/utils.d.ts +1 -0
- package/dist/mjs/utils/utils.js +4 -0
- package/dist/umd/data-structure-typed.js +361 -542
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +4 -3
- package/src/data-structures/base/index.ts +1 -1
- package/src/data-structures/base/iterable-base.ts +7 -10
- package/src/data-structures/binary-tree/avl-tree.ts +15 -8
- package/src/data-structures/binary-tree/binary-tree.ts +57 -74
- package/src/data-structures/binary-tree/bst.ts +16 -13
- package/src/data-structures/binary-tree/rb-tree.ts +16 -10
- package/src/data-structures/binary-tree/tree-multimap.ts +11 -48
- package/src/data-structures/graph/abstract-graph.ts +14 -24
- package/src/data-structures/graph/directed-graph.ts +8 -6
- package/src/data-structures/graph/map-graph.ts +6 -1
- package/src/data-structures/graph/undirected-graph.ts +4 -7
- package/src/data-structures/hash/hash-map.ts +18 -16
- package/src/data-structures/heap/heap.ts +7 -10
- package/src/data-structures/heap/max-heap.ts +2 -1
- package/src/data-structures/heap/min-heap.ts +2 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +3 -5
- package/src/data-structures/matrix/index.ts +0 -2
- package/src/data-structures/matrix/matrix.ts +442 -13
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -10
- package/src/data-structures/queue/deque.ts +18 -39
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/interfaces/binary-tree.ts +7 -2
- package/src/types/common.ts +4 -4
- package/src/types/data-structures/base/base.ts +14 -3
- package/src/types/data-structures/base/index.ts +1 -1
- package/src/types/data-structures/graph/abstract-graph.ts +4 -2
- package/src/types/data-structures/hash/hash-map.ts +3 -3
- package/src/types/data-structures/heap/heap.ts +2 -2
- package/src/types/data-structures/priority-queue/priority-queue.ts +2 -2
- package/src/utils/utils.ts +7 -1
- package/test/integration/avl-tree.test.ts +18 -1
- package/test/integration/bst.test.ts +2 -2
- package/test/performance/data-structures/binary-tree/rb-tree.test.ts +1 -1
- package/test/performance/data-structures/comparison/comparison.test.ts +18 -23
- package/test/performance/data-structures/hash/hash-map.test.ts +3 -4
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +16 -28
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +4 -12
- package/test/performance/data-structures/queue/deque.test.ts +11 -12
- package/test/performance/data-structures/queue/queue.test.ts +15 -14
- package/test/performance/data-structures/stack/stack.test.ts +11 -11
- package/test/performance/reportor.ts +14 -15
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +14 -3
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +65 -15
- package/test/unit/data-structures/binary-tree/bst.test.ts +52 -26
- package/test/unit/data-structures/binary-tree/overall.test.ts +16 -18
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +17 -6
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -21
- package/test/unit/data-structures/graph/abstract-graph.test.ts +11 -0
- package/test/unit/data-structures/graph/directed-graph.test.ts +112 -40
- package/test/unit/data-structures/graph/undirected-graph.test.ts +63 -33
- package/test/unit/data-structures/hash/hash-map.test.ts +64 -23
- package/test/unit/data-structures/hash/hash-table.test.ts +0 -4
- package/test/unit/data-structures/heap/heap.test.ts +0 -1
- package/test/unit/data-structures/heap/min-heap.test.ts +6 -5
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -4
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +3 -4
- package/test/unit/data-structures/matrix/matrix.test.ts +345 -52
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +1 -1
- package/test/unit/data-structures/priority-queue/priority-queue.test.ts +0 -1
- package/test/unit/data-structures/queue/deque.test.ts +0 -6
- package/test/unit/data-structures/queue/queue.test.ts +1 -1
- package/test/unit/data-structures/stack/stack.test.ts +3 -4
- package/test/unit/unrestricted-interconversion.test.ts +50 -44
- package/test/utils/big-o.ts +14 -14
- package/test/utils/performanc.ts +1 -1
- package/typedoc.json +30 -0
- package/dist/cjs/data-structures/matrix/matrix2d.d.ts +0 -107
- package/dist/cjs/data-structures/matrix/matrix2d.js +0 -200
- package/dist/cjs/data-structures/matrix/matrix2d.js.map +0 -1
- package/dist/cjs/data-structures/matrix/vector2d.d.ts +0 -200
- package/dist/cjs/data-structures/matrix/vector2d.js +0 -291
- package/dist/cjs/data-structures/matrix/vector2d.js.map +0 -1
- package/dist/mjs/data-structures/matrix/matrix2d.d.ts +0 -107
- package/dist/mjs/data-structures/matrix/matrix2d.js +0 -196
- package/dist/mjs/data-structures/matrix/vector2d.d.ts +0 -200
- package/dist/mjs/data-structures/matrix/vector2d.js +0 -289
- package/src/data-structures/matrix/matrix2d.ts +0 -211
- package/src/data-structures/matrix/vector2d.ts +0 -315
- package/test/unit/data-structures/matrix/matrix2d.test.ts +0 -345
- package/test/unit/data-structures/matrix/vector2d.test.ts +0 -171
|
@@ -176,40 +176,52 @@ describe('UndirectedGraph', () => {
|
|
|
176
176
|
|
|
177
177
|
test('Removing an edge of a UndirectedGraph should not delete additional edges', () => {
|
|
178
178
|
const dg = new UndirectedGraph();
|
|
179
|
-
dg.addVertex('hello')
|
|
180
|
-
dg.addVertex('hi')
|
|
181
|
-
dg.addVertex('hey')
|
|
182
|
-
dg.addEdge('hello', 'hi')
|
|
183
|
-
dg.addEdge('hello', 'hey')
|
|
184
|
-
expect(dg.getEdge('hello', 'hi')?.vertexMap[0]).toBe('hello')
|
|
185
|
-
expect(dg.getEdge('hello', 'hi')?.vertexMap[1]).toBe('hi')
|
|
186
|
-
expect(dg.getEdge('hello', 'hey')?.vertexMap[0]).toBe('hello')
|
|
187
|
-
expect(dg.getEdge('hello', 'hey')?.vertexMap[1]).toBe('hey')
|
|
188
|
-
dg.deleteEdge('hello', 'hi')
|
|
189
|
-
expect(dg.getEdge('hello', 'hi')).toBe(undefined)
|
|
190
|
-
expect(dg.getEdge('hello', 'hey')).toBeInstanceOf(UndirectedEdge)
|
|
179
|
+
dg.addVertex('hello');
|
|
180
|
+
dg.addVertex('hi');
|
|
181
|
+
dg.addVertex('hey');
|
|
182
|
+
dg.addEdge('hello', 'hi');
|
|
183
|
+
dg.addEdge('hello', 'hey');
|
|
184
|
+
expect(dg.getEdge('hello', 'hi')?.vertexMap[0]).toBe('hello');
|
|
185
|
+
expect(dg.getEdge('hello', 'hi')?.vertexMap[1]).toBe('hi');
|
|
186
|
+
expect(dg.getEdge('hello', 'hey')?.vertexMap[0]).toBe('hello');
|
|
187
|
+
expect(dg.getEdge('hello', 'hey')?.vertexMap[1]).toBe('hey');
|
|
188
|
+
dg.deleteEdge('hello', 'hi');
|
|
189
|
+
expect(dg.getEdge('hello', 'hi')).toBe(undefined);
|
|
190
|
+
expect(dg.getEdge('hello', 'hey')).toBeInstanceOf(UndirectedEdge);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('Removing a vertex of a DirectedGraph should delete additional edges', () => {
|
|
194
|
+
const graph = new UndirectedGraph();
|
|
195
|
+
|
|
196
|
+
graph.addVertex('Hello');
|
|
197
|
+
graph.addVertex('Hi');
|
|
198
|
+
|
|
199
|
+
graph.addEdge('Hello', 'Hi');
|
|
200
|
+
graph.deleteVertex('Hello');
|
|
201
|
+
|
|
202
|
+
expect(graph.edgesOf('Hi')).toEqual([]);
|
|
191
203
|
});
|
|
192
204
|
|
|
193
205
|
test('Removing a vertex from a UndirectedGraph should remove its edges', () => {
|
|
194
206
|
const dg = new UndirectedGraph();
|
|
195
|
-
dg.addVertex('hello')
|
|
196
|
-
dg.addVertex('world')
|
|
197
|
-
dg.addVertex('earth')
|
|
207
|
+
dg.addVertex('hello');
|
|
208
|
+
dg.addVertex('world');
|
|
209
|
+
dg.addVertex('earth');
|
|
198
210
|
|
|
199
|
-
dg.addEdge('hello', 'world')
|
|
200
|
-
dg.addEdge('hello', 'earth')
|
|
201
|
-
dg.addEdge('world', 'earth')
|
|
211
|
+
dg.addEdge('hello', 'world');
|
|
212
|
+
dg.addEdge('hello', 'earth');
|
|
213
|
+
dg.addEdge('world', 'earth');
|
|
202
214
|
|
|
203
215
|
expect(dg.getEdge('hello', 'world')?.vertexMap[0]).toBe('hello');
|
|
204
|
-
expect(dg.edgeSet().length).toBe(3)
|
|
205
|
-
expect(dg.edgeSet()[0].vertexMap).toEqual(['hello', 'world'])
|
|
216
|
+
expect(dg.edgeSet().length).toBe(3);
|
|
217
|
+
expect(dg.edgeSet()[0].vertexMap).toEqual(['hello', 'world']);
|
|
206
218
|
|
|
207
|
-
dg.deleteVertex('hello')
|
|
208
|
-
expect(dg.edgeSet().length).toBe(1)
|
|
209
|
-
expect(dg.edgeSet()?.[0].vertexMap[0]).toBe('world')
|
|
219
|
+
dg.deleteVertex('hello');
|
|
220
|
+
expect(dg.edgeSet().length).toBe(1);
|
|
221
|
+
expect(dg.edgeSet()?.[0].vertexMap[0]).toBe('world');
|
|
210
222
|
|
|
211
223
|
expect(dg.getEdge('hello', 'world')).toBe(undefined);
|
|
212
|
-
})
|
|
224
|
+
});
|
|
213
225
|
});
|
|
214
226
|
|
|
215
227
|
describe('cycles, strongly connected components, bridges, articular points in UndirectedGraph', () => {
|
|
@@ -245,8 +257,7 @@ describe('cycles, strongly connected components, bridges, articular points in Un
|
|
|
245
257
|
expect(lowMap.size).toBe(8);
|
|
246
258
|
});
|
|
247
259
|
|
|
248
|
-
it(
|
|
249
|
-
|
|
260
|
+
it('Should return Infinity if dest is not found', () => {
|
|
250
261
|
const graph = new UndirectedGraph<string>();
|
|
251
262
|
|
|
252
263
|
for (let i = 0; i < 3; ++i) {
|
|
@@ -278,8 +289,12 @@ describe('UndirectedGraph getCycles', () => {
|
|
|
278
289
|
graph.addEdge('E', 'B');
|
|
279
290
|
const cycles = graph.getCycles();
|
|
280
291
|
expect(cycles.length).toBe(3);
|
|
281
|
-
expect(cycles).toEqual([
|
|
282
|
-
|
|
292
|
+
expect(cycles).toEqual([
|
|
293
|
+
['A', 'B', 'D', 'C'],
|
|
294
|
+
['A', 'B', 'E', 'D', 'C'],
|
|
295
|
+
['B', 'D', 'E']
|
|
296
|
+
]);
|
|
297
|
+
});
|
|
283
298
|
|
|
284
299
|
test('should simple cycles graph getCycles return correct result', () => {
|
|
285
300
|
const graph = new UndirectedGraph();
|
|
@@ -295,8 +310,12 @@ describe('UndirectedGraph getCycles', () => {
|
|
|
295
310
|
graph.addEdge('A', 'D');
|
|
296
311
|
graph.addEdge('D', 'C');
|
|
297
312
|
const cycles = graph.getCycles();
|
|
298
|
-
expect(cycles.length).toBe(3)
|
|
299
|
-
expect(cycles).toEqual([
|
|
313
|
+
expect(cycles.length).toBe(3);
|
|
314
|
+
expect(cycles).toEqual([
|
|
315
|
+
['A', 'B', 'C'],
|
|
316
|
+
['A', 'B', 'C', 'D'],
|
|
317
|
+
['A', 'C', 'D']
|
|
318
|
+
]);
|
|
300
319
|
});
|
|
301
320
|
|
|
302
321
|
test('should 3 cycles graph getCycles return correct result', () => {
|
|
@@ -322,7 +341,18 @@ describe('UndirectedGraph getCycles', () => {
|
|
|
322
341
|
graph.addEdge('G', 'A');
|
|
323
342
|
|
|
324
343
|
const cycles = graph.getCycles();
|
|
325
|
-
expect(cycles.length).toBe(10)
|
|
326
|
-
expect(cycles).toEqual([
|
|
344
|
+
expect(cycles.length).toBe(10);
|
|
345
|
+
expect(cycles).toEqual([
|
|
346
|
+
['A', 'B', 'D', 'C'],
|
|
347
|
+
['A', 'B', 'D', 'C', 'G'],
|
|
348
|
+
['A', 'B', 'E', 'D', 'C'],
|
|
349
|
+
['A', 'B', 'E', 'D', 'C', 'G'],
|
|
350
|
+
['A', 'B', 'F', 'E', 'D', 'C'],
|
|
351
|
+
['A', 'B', 'F', 'E', 'D', 'C', 'G'],
|
|
352
|
+
['A', 'C', 'G'],
|
|
353
|
+
['B', 'D', 'E'],
|
|
354
|
+
['B', 'D', 'E', 'F'],
|
|
355
|
+
['B', 'E', 'F']
|
|
356
|
+
]);
|
|
327
357
|
});
|
|
328
|
-
})
|
|
358
|
+
});
|
|
@@ -54,7 +54,6 @@ describe('HashMap Test1', () => {
|
|
|
54
54
|
hashMap.set('one', 1);
|
|
55
55
|
hashMap.set('two', 2);
|
|
56
56
|
hashMap.set('three', 3);
|
|
57
|
-
|
|
58
57
|
});
|
|
59
58
|
|
|
60
59
|
it('should resize the table when load factor is exceeded', () => {
|
|
@@ -181,7 +180,6 @@ describe('HashMap Test2', () => {
|
|
|
181
180
|
}
|
|
182
181
|
compareHashMaps(hashMap, stdMap);
|
|
183
182
|
});
|
|
184
|
-
|
|
185
183
|
});
|
|
186
184
|
|
|
187
185
|
describe('HashMap for coordinate object keys', () => {
|
|
@@ -207,30 +205,39 @@ describe('HashMap for coordinate object keys', () => {
|
|
|
207
205
|
|
|
208
206
|
test('delete elements in hash map', () => {
|
|
209
207
|
for (let i = 0; i < 1000; i++) {
|
|
210
|
-
if (i === 500) expect(hashMap.size).toBe(500)
|
|
208
|
+
if (i === 500) expect(hashMap.size).toBe(500);
|
|
211
209
|
const codObj = codObjs[i];
|
|
212
210
|
if (codObj) hashMap.delete(codObj);
|
|
213
211
|
}
|
|
214
212
|
expect(hashMap.size).toBe(0);
|
|
215
213
|
});
|
|
216
|
-
|
|
217
214
|
});
|
|
218
215
|
|
|
219
216
|
describe('HashMap setMany, keys, values', () => {
|
|
220
217
|
const hm: HashMap<number, number> = new HashMap<number, number>();
|
|
221
218
|
|
|
222
219
|
beforeEach(() => {
|
|
223
|
-
hm.clear()
|
|
224
|
-
hm.setMany([
|
|
225
|
-
|
|
226
|
-
|
|
220
|
+
hm.clear();
|
|
221
|
+
hm.setMany([
|
|
222
|
+
[2, 2],
|
|
223
|
+
[3, 3],
|
|
224
|
+
[4, 4],
|
|
225
|
+
[5, 5]
|
|
226
|
+
]);
|
|
227
|
+
hm.setMany([
|
|
228
|
+
[2, 2],
|
|
229
|
+
[3, 3],
|
|
230
|
+
[4, 4],
|
|
231
|
+
[6, 6]
|
|
232
|
+
]);
|
|
233
|
+
});
|
|
227
234
|
|
|
228
235
|
test('keys', () => {
|
|
229
|
-
expect([...hm.keys()]).toEqual([2, 3, 4, 5, 6])
|
|
236
|
+
expect([...hm.keys()]).toEqual([2, 3, 4, 5, 6]);
|
|
230
237
|
});
|
|
231
238
|
|
|
232
239
|
test('values', () => {
|
|
233
|
-
expect([...hm.values()]).toEqual([2, 3, 4, 5, 6])
|
|
240
|
+
expect([...hm.values()]).toEqual([2, 3, 4, 5, 6]);
|
|
234
241
|
});
|
|
235
242
|
});
|
|
236
243
|
|
|
@@ -245,7 +252,7 @@ describe('HashMap HOF', () => {
|
|
|
245
252
|
});
|
|
246
253
|
|
|
247
254
|
test('every() returns true if all elements match the condition', () => {
|
|
248
|
-
expect(hashMap.every(
|
|
255
|
+
expect(hashMap.every(value => typeof value === 'string')).toBe(true);
|
|
249
256
|
});
|
|
250
257
|
|
|
251
258
|
test('some() returns true if any element matches the condition', () => {
|
|
@@ -259,7 +266,7 @@ describe('HashMap HOF', () => {
|
|
|
259
266
|
});
|
|
260
267
|
|
|
261
268
|
test('map() should transform each element', () => {
|
|
262
|
-
const newHashMap = hashMap.map(
|
|
269
|
+
const newHashMap = hashMap.map(value => value.toUpperCase());
|
|
263
270
|
expect(newHashMap.get('key1')).toBe('VALUE1');
|
|
264
271
|
});
|
|
265
272
|
|
|
@@ -274,7 +281,6 @@ describe('HashMap HOF', () => {
|
|
|
274
281
|
});
|
|
275
282
|
});
|
|
276
283
|
|
|
277
|
-
|
|
278
284
|
describe('LinkedHashMap Test1', () => {
|
|
279
285
|
let hashMap: LinkedHashMap<string, number>;
|
|
280
286
|
|
|
@@ -368,7 +374,6 @@ describe('LinkedHashMap Test1', () => {
|
|
|
368
374
|
// expect(hashMap.table[0].length).toBe(2);
|
|
369
375
|
});
|
|
370
376
|
|
|
371
|
-
|
|
372
377
|
// it('should handle number keys correctly', () => {
|
|
373
378
|
// const hm = new LinkedHashMap();
|
|
374
379
|
// hm.set(999, { a: '999Value' });
|
|
@@ -529,29 +534,65 @@ describe('LinkedHashMap for coordinate object keys', () => {
|
|
|
529
534
|
|
|
530
535
|
test('delete elements in hash map', () => {
|
|
531
536
|
for (let i = 0; i < 1000; i++) {
|
|
532
|
-
if (i === 500) expect(hashMap.size).toBe(500)
|
|
537
|
+
if (i === 500) expect(hashMap.size).toBe(500);
|
|
533
538
|
const codObj = codObjs[i];
|
|
534
539
|
if (codObj) hashMap.delete(codObj);
|
|
535
540
|
}
|
|
536
541
|
expect(hashMap.size).toBe(0);
|
|
537
542
|
});
|
|
538
|
-
|
|
539
543
|
});
|
|
540
544
|
|
|
541
545
|
describe('LinkedHashMap setMany, keys, values', () => {
|
|
542
546
|
const hm: LinkedHashMap<number, number> = new LinkedHashMap<number, number>();
|
|
543
547
|
|
|
544
548
|
beforeEach(() => {
|
|
545
|
-
hm.clear()
|
|
546
|
-
hm.setMany([
|
|
547
|
-
|
|
548
|
-
|
|
549
|
+
hm.clear();
|
|
550
|
+
hm.setMany([
|
|
551
|
+
[2, 2],
|
|
552
|
+
[3, 3],
|
|
553
|
+
[4, 4],
|
|
554
|
+
[5, 5]
|
|
555
|
+
]);
|
|
556
|
+
hm.setMany([
|
|
557
|
+
[2, 2],
|
|
558
|
+
[3, 3],
|
|
559
|
+
[4, 4],
|
|
560
|
+
[6, 6]
|
|
561
|
+
]);
|
|
562
|
+
});
|
|
549
563
|
|
|
550
564
|
test('keys', () => {
|
|
551
|
-
expect([...hm.keys()]).toEqual([2, 3, 4, 5, 6])
|
|
565
|
+
expect([...hm.keys()]).toEqual([2, 3, 4, 5, 6]);
|
|
552
566
|
});
|
|
553
567
|
|
|
554
568
|
test('values', () => {
|
|
555
|
-
expect([...hm.values()]).toEqual([2, 3, 4, 5, 6])
|
|
569
|
+
expect([...hm.values()]).toEqual([2, 3, 4, 5, 6]);
|
|
556
570
|
});
|
|
557
|
-
|
|
571
|
+
|
|
572
|
+
test('entries', () => {
|
|
573
|
+
expect([...hm.entries()]).toEqual([
|
|
574
|
+
[2, 2],
|
|
575
|
+
[3, 3],
|
|
576
|
+
[4, 4],
|
|
577
|
+
[5, 5],
|
|
578
|
+
[6, 6]
|
|
579
|
+
]);
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
test('every', () => {
|
|
583
|
+
expect(hm.every(value => value > 4)).toBe(false);
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
test('some', () => {
|
|
587
|
+
expect(hm.some(value => value > 6)).toBe(false);
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
test('hasValue', () => {
|
|
591
|
+
expect(hm.hasValue(3)).toBe(true);
|
|
592
|
+
expect(hm.hasValue(7)).toBe(false);
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
test('print', () => {
|
|
596
|
+
hm.print();
|
|
597
|
+
});
|
|
598
|
+
});
|
|
@@ -185,7 +185,6 @@ describe('HashTable performance', function () {
|
|
|
185
185
|
});
|
|
186
186
|
});
|
|
187
187
|
|
|
188
|
-
|
|
189
188
|
describe('HashTable methods', () => {
|
|
190
189
|
let hashTable: HashTable<string, string>;
|
|
191
190
|
|
|
@@ -215,7 +214,6 @@ describe('HashTable methods', () => {
|
|
|
215
214
|
// }
|
|
216
215
|
// });
|
|
217
216
|
|
|
218
|
-
|
|
219
217
|
test('filter should return a new HashTable with elements that satisfy the condition', () => {
|
|
220
218
|
const filtered = hashTable.filter(([key]) => key.endsWith('1') || key.endsWith('3'));
|
|
221
219
|
|
|
@@ -237,6 +235,4 @@ describe('HashTable methods', () => {
|
|
|
237
235
|
|
|
238
236
|
expect(result).toBe('-value5-value7-value3-value4-value6-value0-value2-value8-value1-value9');
|
|
239
237
|
});
|
|
240
|
-
|
|
241
238
|
});
|
|
242
|
-
|
|
@@ -50,17 +50,15 @@ describe('MinHeap', () => {
|
|
|
50
50
|
expect(minHeap.isEmpty()).toBe(true);
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
|
|
54
53
|
const n = 100000;
|
|
55
54
|
|
|
56
55
|
it('should push & dfs', () => {
|
|
57
56
|
for (let i = 0; i < n; i++) {
|
|
58
57
|
minHeap.add(i);
|
|
59
58
|
}
|
|
60
|
-
expect(minHeap.dfs()[0]).toBe(0)
|
|
61
|
-
expect(minHeap.dfs()[999]).toBe(4126)
|
|
59
|
+
expect(minHeap.dfs()[0]).toBe(0);
|
|
60
|
+
expect(minHeap.dfs()[999]).toBe(4126);
|
|
62
61
|
});
|
|
63
|
-
|
|
64
62
|
});
|
|
65
63
|
|
|
66
64
|
describe('Heap iterative methods', () => {
|
|
@@ -89,7 +87,10 @@ describe('Heap iterative methods', () => {
|
|
|
89
87
|
});
|
|
90
88
|
|
|
91
89
|
test('map method correctly maps elements', () => {
|
|
92
|
-
const result = heap.map(
|
|
90
|
+
const result = heap.map(
|
|
91
|
+
x => x / 10,
|
|
92
|
+
(a: number, b: number) => a - b
|
|
93
|
+
);
|
|
93
94
|
expect([...result]).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
94
95
|
});
|
|
95
96
|
|
|
@@ -398,16 +398,15 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
398
398
|
});
|
|
399
399
|
});
|
|
400
400
|
|
|
401
|
-
|
|
402
401
|
describe('iterable methods', () => {
|
|
403
402
|
it('should forEach, some, every, filter, map, reduce of the deque', () => {
|
|
404
|
-
const dl = new DoublyLinkedList<number>()
|
|
403
|
+
const dl = new DoublyLinkedList<number>();
|
|
405
404
|
dl.push(1);
|
|
406
405
|
dl.push(2);
|
|
407
406
|
dl.push(3);
|
|
408
407
|
|
|
409
408
|
const mockCallback = jest.fn();
|
|
410
|
-
dl.forEach(
|
|
409
|
+
dl.forEach(element => {
|
|
411
410
|
mockCallback(element);
|
|
412
411
|
});
|
|
413
412
|
|
|
@@ -424,4 +423,31 @@ describe('iterable methods', () => {
|
|
|
424
423
|
expect([...dl.map(element => element * 2)]).toEqual([2, 4, 6]);
|
|
425
424
|
expect(dl.reduce((accumulator, element) => accumulator + element, 0)).toEqual(6);
|
|
426
425
|
});
|
|
427
|
-
|
|
426
|
+
|
|
427
|
+
test('values', () => {
|
|
428
|
+
const dl = new DoublyLinkedList<number>();
|
|
429
|
+
dl.push(1);
|
|
430
|
+
dl.push(2);
|
|
431
|
+
dl.push(3);
|
|
432
|
+
dl.delete(2);
|
|
433
|
+
dl.unshift(0);
|
|
434
|
+
dl.shift();
|
|
435
|
+
dl.pop();
|
|
436
|
+
dl.unshift(3);
|
|
437
|
+
expect([...dl.values()]).toEqual([3, 1]);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
test('some', () => {
|
|
441
|
+
const dl = new DoublyLinkedList<number>();
|
|
442
|
+
dl.push(1);
|
|
443
|
+
dl.push(2);
|
|
444
|
+
dl.push(3);
|
|
445
|
+
dl.delete(2);
|
|
446
|
+
dl.unshift(0);
|
|
447
|
+
dl.shift();
|
|
448
|
+
dl.pop();
|
|
449
|
+
dl.unshift(3);
|
|
450
|
+
expect(dl.some(value => value > 1)).toBe(true);
|
|
451
|
+
expect(dl.some(value => value > 100)).toBe(false);
|
|
452
|
+
});
|
|
453
|
+
});
|
|
@@ -472,13 +472,12 @@ describe('SinglyLinkedList', () => {
|
|
|
472
472
|
});
|
|
473
473
|
});
|
|
474
474
|
|
|
475
|
-
|
|
476
475
|
describe('iterable methods', () => {
|
|
477
476
|
it('should forEach, some, every, filter, map, reduce of the deque', () => {
|
|
478
|
-
const sl = new SinglyLinkedList<number>([1, 2, 3])
|
|
477
|
+
const sl = new SinglyLinkedList<number>([1, 2, 3]);
|
|
479
478
|
|
|
480
479
|
const mockCallback = jest.fn();
|
|
481
|
-
sl.forEach(
|
|
480
|
+
sl.forEach(element => {
|
|
482
481
|
mockCallback(element);
|
|
483
482
|
});
|
|
484
483
|
|
|
@@ -495,4 +494,4 @@ describe('iterable methods', () => {
|
|
|
495
494
|
expect([...sl.map(element => element * 2)]).toEqual([2, 4, 6]);
|
|
496
495
|
expect(sl.reduce((accumulator, element) => accumulator + element, 0)).toEqual(6);
|
|
497
496
|
});
|
|
498
|
-
});
|
|
497
|
+
});
|