data-structure-typed 1.39.2 → 1.39.3
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/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +10 -10
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +4 -4
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +49 -108
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +27 -27
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +22 -22
- package/dist/cjs/data-structures/binary-tree/bst.js +12 -12
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multiset.d.ts +14 -14
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js +7 -7
- package/dist/cjs/data-structures/binary-tree/tree-multiset.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-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.js.map +1 -1
- package/dist/cjs/data-structures/hash/tree-map.js.map +1 -1
- package/dist/cjs/data-structures/hash/tree-set.js.map +1 -1
- 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/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/matrix/vector2d.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +4 -4
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +2 -2
- package/dist/cjs/types/helpers.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +10 -10
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +4 -4
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +49 -108
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +27 -27
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +22 -22
- package/dist/mjs/data-structures/binary-tree/bst.js +12 -12
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/mjs/data-structures/binary-tree/tree-multiset.d.ts +14 -14
- package/dist/mjs/data-structures/binary-tree/tree-multiset.js +7 -7
- package/dist/mjs/interfaces/binary-tree.d.ts +4 -4
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +2 -2
- package/dist/mjs/types/helpers.d.ts +1 -1
- package/dist/umd/data-structure-typed.min.js +1 -1
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +5 -5
- package/src/data-structures/binary-tree/avl-tree.ts +13 -12
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +1 -1
- package/src/data-structures/binary-tree/binary-tree.ts +130 -60
- package/src/data-structures/binary-tree/bst.ts +31 -32
- package/src/data-structures/binary-tree/rb-tree.ts +7 -6
- package/src/data-structures/binary-tree/tree-multiset.ts +16 -15
- package/src/data-structures/graph/abstract-graph.ts +11 -10
- package/src/data-structures/graph/directed-graph.ts +2 -1
- package/src/data-structures/graph/undirected-graph.ts +5 -4
- package/src/data-structures/hash/hash-map.ts +1 -1
- package/src/data-structures/hash/tree-map.ts +1 -2
- package/src/data-structures/hash/tree-set.ts +1 -2
- package/src/data-structures/heap/heap.ts +2 -2
- package/src/data-structures/heap/max-heap.ts +1 -1
- package/src/data-structures/heap/min-heap.ts +1 -1
- package/src/data-structures/linked-list/doubly-linked-list.ts +1 -1
- package/src/data-structures/linked-list/singly-linked-list.ts +1 -1
- package/src/data-structures/matrix/matrix.ts +1 -1
- package/src/data-structures/matrix/vector2d.ts +1 -2
- package/src/data-structures/priority-queue/max-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/min-priority-queue.ts +1 -1
- package/src/data-structures/priority-queue/priority-queue.ts +1 -1
- package/src/data-structures/queue/deque.ts +4 -5
- package/src/data-structures/queue/queue.ts +1 -1
- package/src/interfaces/binary-tree.ts +4 -4
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/bst.ts +2 -2
- package/src/types/data-structures/matrix/navigator.ts +1 -1
- package/src/types/helpers.ts +1 -1
- package/src/types/utils/utils.ts +1 -1
- package/src/types/utils/validate-type.ts +2 -2
- package/test/integration/bst.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +14 -8
- package/test/unit/data-structures/binary-tree/bst.test.ts +6 -6
- package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/tree-multiset.test.ts +2 -2
- package/test/unit/data-structures/hash/coordinate-map.test.ts +2 -2
- package/test/unit/data-structures/hash/coordinate-set.test.ts +2 -2
- package/test/unit/data-structures/heap/heap.test.ts +2 -2
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +2 -6
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +4 -7
- package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +2 -2
- package/test/utils/big-o.ts +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {BSTNode} from '../../../data-structures';
|
|
2
|
-
import type {
|
|
2
|
+
import type {BTNKey, BinaryTreeOptions} from './binary-tree';
|
|
3
3
|
|
|
4
|
-
export type BSTComparator = (a:
|
|
4
|
+
export type BSTComparator = (a: BTNKey, b: BTNKey) => number;
|
|
5
5
|
|
|
6
6
|
// prettier-ignore
|
|
7
7
|
export type BSTNodeNested<T> = BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, BSTNode<T, any>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
package/src/types/helpers.ts
CHANGED
package/src/types/utils/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type ToThunkFn = () => ReturnType<TrlFn>;
|
|
2
|
-
export type Thunk = () => ReturnType<ToThunkFn> & {
|
|
2
|
+
export type Thunk = () => ReturnType<ToThunkFn> & {__THUNK__: symbol};
|
|
3
3
|
export type TrlFn = (...args: any[]) => any;
|
|
4
4
|
export type TrlAsyncFn = (...args: any[]) => any;
|
|
5
5
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export type KeyValueObject = {
|
|
1
|
+
export type KeyValueObject = {[key: string]: any};
|
|
2
2
|
|
|
3
|
-
export type KeyValueObjectWithKey = {
|
|
3
|
+
export type KeyValueObjectWithKey = {[key: string]: any; key: string | number | symbol};
|
|
4
4
|
|
|
5
5
|
export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
|
|
6
6
|
|
|
@@ -183,7 +183,7 @@ describe('Individual package BST operations test', () => {
|
|
|
183
183
|
});
|
|
184
184
|
|
|
185
185
|
it('should perform various operations on a Binary Search Tree with object values', () => {
|
|
186
|
-
const objBST = new BST<{
|
|
186
|
+
const objBST = new BST<{key: number; keyA: number}>();
|
|
187
187
|
expect(objBST).toBeInstanceOf(BST);
|
|
188
188
|
objBST.add(11, {key: 11, keyA: 11});
|
|
189
189
|
objBST.add(3, {key: 3, keyA: 3});
|
|
@@ -219,7 +219,7 @@ describe('AVL Tree Test recursively', () => {
|
|
|
219
219
|
});
|
|
220
220
|
|
|
221
221
|
describe('AVLTree APIs test', () => {
|
|
222
|
-
const avl = new AVLTree<{
|
|
222
|
+
const avl = new AVLTree<{id: number; text: string}>();
|
|
223
223
|
beforeEach(() => {
|
|
224
224
|
avl.clear();
|
|
225
225
|
});
|
|
@@ -71,10 +71,10 @@ describe('BinaryTreeNode', () => {
|
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
describe('BinaryTree', () => {
|
|
74
|
-
let tree: BinaryTree
|
|
74
|
+
let tree: BinaryTree<number>;
|
|
75
75
|
|
|
76
76
|
beforeEach(() => {
|
|
77
|
-
tree = new BinaryTree();
|
|
77
|
+
tree = new BinaryTree<number>();
|
|
78
78
|
});
|
|
79
79
|
|
|
80
80
|
afterEach(() => {
|
|
@@ -99,16 +99,18 @@ describe('BinaryTree', () => {
|
|
|
99
99
|
});
|
|
100
100
|
|
|
101
101
|
it('should add and find nodes', () => {
|
|
102
|
-
tree.add(1);
|
|
103
|
-
tree.add(2);
|
|
104
|
-
tree.add(3);
|
|
102
|
+
tree.add(1, 1);
|
|
103
|
+
tree.add(2, 2);
|
|
104
|
+
tree.add(3, 3);
|
|
105
105
|
|
|
106
106
|
expect(tree.has(1)).toBe(true);
|
|
107
107
|
expect(tree.has(2)).toBe(true);
|
|
108
108
|
expect(tree.has(3)).toBe(true);
|
|
109
109
|
expect(tree.has(4)).toBe(false);
|
|
110
110
|
const node4 = tree.get(4);
|
|
111
|
+
expect(tree.has(node4)).toBe(false);
|
|
111
112
|
expect(tree.has(node4, node => node)).toBe(false);
|
|
113
|
+
expect(tree.has('3', node => node.val?.toString())).toBe(true);
|
|
112
114
|
});
|
|
113
115
|
|
|
114
116
|
it('should getDepth return correct depth', () => {
|
|
@@ -241,7 +243,7 @@ describe('BinaryTree Morris Traversal', () => {
|
|
|
241
243
|
});
|
|
242
244
|
|
|
243
245
|
describe('BinaryTree APIs test', () => {
|
|
244
|
-
const avl = new AVLTree<{
|
|
246
|
+
const avl = new AVLTree<{id: number; text: string}>();
|
|
245
247
|
beforeEach(() => {
|
|
246
248
|
avl.clear();
|
|
247
249
|
});
|
|
@@ -265,10 +267,14 @@ describe('BinaryTree traversals', () => {
|
|
|
265
267
|
const arr = [35, 20, 40, 15, 29, null, 50, null, 16, 28, 30, 45, 55];
|
|
266
268
|
tree.refill(arr);
|
|
267
269
|
expect(tree.dfs(node => node.key, 'pre')).toEqual([35, 20, 15, 16, 29, 28, 30, 40, 50, 45, 55]);
|
|
268
|
-
expect(tree.dfs(node => node.key, 'pre', tree.root, IterationType.RECURSIVE)).toEqual([
|
|
270
|
+
expect(tree.dfs(node => node.key, 'pre', tree.root, IterationType.RECURSIVE)).toEqual([
|
|
271
|
+
35, 20, 15, 16, 29, 28, 30, 40, 50, 45, 55
|
|
272
|
+
]);
|
|
269
273
|
expect(tree.dfs(node => node.key, 'in')).toEqual([15, 16, 20, 28, 29, 30, 35, 40, 45, 50, 55]);
|
|
270
274
|
expect(tree.dfs(node => node.key, 'post')).toEqual([16, 15, 28, 30, 29, 20, 45, 55, 50, 40, 35]);
|
|
271
|
-
expect(tree.dfs(node => node.key, 'post', tree.root, IterationType.RECURSIVE)).toEqual([
|
|
275
|
+
expect(tree.dfs(node => node.key, 'post', tree.root, IterationType.RECURSIVE)).toEqual([
|
|
276
|
+
16, 15, 28, 30, 29, 20, 45, 55, 50, 40, 35
|
|
277
|
+
]);
|
|
272
278
|
expect(tree.bfs(node => node.key, tree.root, IterationType.RECURSIVE)).toEqual([
|
|
273
279
|
35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55
|
|
274
280
|
]);
|
|
@@ -189,7 +189,7 @@ describe('BST operations test', () => {
|
|
|
189
189
|
});
|
|
190
190
|
|
|
191
191
|
it('should perform various operations on a Binary Search Tree with object values', () => {
|
|
192
|
-
const objBST = new BST<{
|
|
192
|
+
const objBST = new BST<{key: number; keyA: number}>();
|
|
193
193
|
expect(objBST).toBeInstanceOf(BST);
|
|
194
194
|
objBST.add(11, {key: 11, keyA: 11});
|
|
195
195
|
objBST.add(3, {key: 3, keyA: 3});
|
|
@@ -260,7 +260,7 @@ describe('BST operations test', () => {
|
|
|
260
260
|
objBST.perfectlyBalance();
|
|
261
261
|
expect(objBST.isPerfectlyBalanced()).toBe(true);
|
|
262
262
|
|
|
263
|
-
const bfsNodesAfterBalanced: BSTNode<{
|
|
263
|
+
const bfsNodesAfterBalanced: BSTNode<{key: number; keyA: number}>[] = [];
|
|
264
264
|
objBST.bfs(node => bfsNodesAfterBalanced.push(node));
|
|
265
265
|
expect(bfsNodesAfterBalanced[0].key).toBe(8);
|
|
266
266
|
expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].key).toBe(16);
|
|
@@ -385,7 +385,7 @@ describe('BST operations test', () => {
|
|
|
385
385
|
expect(bfsIDs[1]).toBe(12);
|
|
386
386
|
expect(bfsIDs[2]).toBe(16);
|
|
387
387
|
|
|
388
|
-
const bfsNodes: BSTNode<{
|
|
388
|
+
const bfsNodes: BSTNode<{key: number; keyA: number}>[] = [];
|
|
389
389
|
objBST.bfs(node => bfsNodes.push(node));
|
|
390
390
|
expect(bfsNodes[0].key).toBe(2);
|
|
391
391
|
expect(bfsNodes[1].key).toBe(12);
|
|
@@ -579,7 +579,7 @@ describe('BST operations test recursively', () => {
|
|
|
579
579
|
});
|
|
580
580
|
|
|
581
581
|
it('should perform various operations on a Binary Search Tree with object values', () => {
|
|
582
|
-
const objBST = new BST<{
|
|
582
|
+
const objBST = new BST<{key: number; keyA: number}>();
|
|
583
583
|
expect(objBST).toBeInstanceOf(BST);
|
|
584
584
|
objBST.add(11, {key: 11, keyA: 11});
|
|
585
585
|
objBST.add(3, {key: 3, keyA: 3});
|
|
@@ -650,7 +650,7 @@ describe('BST operations test recursively', () => {
|
|
|
650
650
|
objBST.perfectlyBalance();
|
|
651
651
|
expect(objBST.isPerfectlyBalanced()).toBe(true);
|
|
652
652
|
|
|
653
|
-
const bfsNodesAfterBalanced: BSTNode<{
|
|
653
|
+
const bfsNodesAfterBalanced: BSTNode<{key: number; keyA: number}>[] = [];
|
|
654
654
|
objBST.bfs(node => bfsNodesAfterBalanced.push(node));
|
|
655
655
|
expect(bfsNodesAfterBalanced[0].key).toBe(8);
|
|
656
656
|
expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].key).toBe(16);
|
|
@@ -775,7 +775,7 @@ describe('BST operations test recursively', () => {
|
|
|
775
775
|
expect(bfsIDs[1]).toBe(12);
|
|
776
776
|
expect(bfsIDs[2]).toBe(16);
|
|
777
777
|
|
|
778
|
-
const bfsNodes: BSTNode<{
|
|
778
|
+
const bfsNodes: BSTNode<{key: number; keyA: number}>[] = [];
|
|
779
779
|
objBST.bfs(node => bfsNodes.push(node));
|
|
780
780
|
expect(bfsNodes[0].key).toBe(2);
|
|
781
781
|
expect(bfsNodes[1].key).toBe(12);
|
|
@@ -29,7 +29,7 @@ describe('Overall BinaryTree Test', () => {
|
|
|
29
29
|
bfsIDs[0] === 11; // true
|
|
30
30
|
expect(bfsIDs[0]).toBe(11);
|
|
31
31
|
|
|
32
|
-
const objBST = new BST<{
|
|
32
|
+
const objBST = new BST<{key: number; keyA: number}>();
|
|
33
33
|
objBST.add(11, {key: 11, keyA: 11});
|
|
34
34
|
objBST.add(3, {key: 3, keyA: 3});
|
|
35
35
|
|
|
@@ -207,7 +207,7 @@ describe('TreeMultiset operations test', () => {
|
|
|
207
207
|
});
|
|
208
208
|
|
|
209
209
|
it('should perform various operations on a Binary Search Tree with object values', () => {
|
|
210
|
-
const objTreeMultiset = new TreeMultiset<{
|
|
210
|
+
const objTreeMultiset = new TreeMultiset<{key: number; keyA: number}>();
|
|
211
211
|
expect(objTreeMultiset).toBeInstanceOf(TreeMultiset);
|
|
212
212
|
objTreeMultiset.add(11, {key: 11, keyA: 11});
|
|
213
213
|
objTreeMultiset.add(3, {key: 3, keyA: 3});
|
|
@@ -447,7 +447,7 @@ describe('TreeMultiset operations test recursively', () => {
|
|
|
447
447
|
});
|
|
448
448
|
|
|
449
449
|
it('should perform various operations on a Binary Search Tree with object values', () => {
|
|
450
|
-
const objTreeMultiset = new TreeMultiset<{
|
|
450
|
+
const objTreeMultiset = new TreeMultiset<{key: number; keyA: number}>();
|
|
451
451
|
expect(objTreeMultiset).toBeInstanceOf(TreeMultiset);
|
|
452
452
|
objTreeMultiset.add(11, {key: 11, keyA: 11});
|
|
453
453
|
objTreeMultiset.add(3, {key: 3, keyA: 3});
|
|
@@ -57,7 +57,7 @@ describe('CoordinateMap', () => {
|
|
|
57
57
|
class MyCoordinateMap<V = any> extends CoordinateMap<V> {
|
|
58
58
|
constructor(joint?: string) {
|
|
59
59
|
super(joint);
|
|
60
|
-
this._setJoint(joint += '-')
|
|
60
|
+
this._setJoint((joint += '-'));
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -67,7 +67,7 @@ describe('CoordinateMap', () => {
|
|
|
67
67
|
cMap.set([0, 0], 0);
|
|
68
68
|
cMap.set([0, 1], 1);
|
|
69
69
|
cMap.set([1, 1], 11);
|
|
70
|
-
})
|
|
70
|
+
});
|
|
71
71
|
it('should joint to be *-', () => {
|
|
72
72
|
expect(cMap.joint).toBe('*-');
|
|
73
73
|
});
|
|
@@ -44,7 +44,7 @@ describe('MyCoordinateSet', () => {
|
|
|
44
44
|
class MyCoordinateSet extends CoordinateSet {
|
|
45
45
|
constructor(joint?: string) {
|
|
46
46
|
super(joint);
|
|
47
|
-
this._setJoint(joint += '-')
|
|
47
|
+
this._setJoint((joint += '-'));
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -54,7 +54,7 @@ describe('MyCoordinateSet', () => {
|
|
|
54
54
|
mySet.add([0, 0]);
|
|
55
55
|
mySet.add([0, 1]);
|
|
56
56
|
mySet.add([1, 1]);
|
|
57
|
-
})
|
|
57
|
+
});
|
|
58
58
|
it('should joint to be *-', () => {
|
|
59
59
|
expect(mySet.joint).toBe('*-');
|
|
60
60
|
});
|
|
@@ -22,7 +22,7 @@ describe('Heap Operation Test', () => {
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
it('should object heap work well', function () {
|
|
25
|
-
const minHeap = new MinHeap<{
|
|
25
|
+
const minHeap = new MinHeap<{a: string; key: number}>({comparator: (a, b) => a.key - b.key});
|
|
26
26
|
minHeap.add({key: 1, a: 'a1'});
|
|
27
27
|
minHeap.add({key: 6, a: 'a6'});
|
|
28
28
|
minHeap.add({key: 2, a: 'a2'});
|
|
@@ -37,7 +37,7 @@ describe('Heap Operation Test', () => {
|
|
|
37
37
|
i++;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const maxHeap = new MaxHeap<{
|
|
40
|
+
const maxHeap = new MaxHeap<{key: number; a: string}>({comparator: (a, b) => b.key - a.key});
|
|
41
41
|
maxHeap.add({key: 1, a: 'a1'});
|
|
42
42
|
maxHeap.add({key: 6, a: 'a6'});
|
|
43
43
|
maxHeap.add({key: 5, a: 'a5'});
|
|
@@ -7,7 +7,7 @@ describe('DoublyLinkedListNode', () => {
|
|
|
7
7
|
expect(node1.val).toBe(2);
|
|
8
8
|
node1.val = 1;
|
|
9
9
|
expect(node1.val).toBe(1);
|
|
10
|
-
})
|
|
10
|
+
});
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
describe('DoublyLinkedList Operation Test', () => {
|
|
@@ -38,10 +38,8 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
38
38
|
expect(list.tail?.val).toBe(4);
|
|
39
39
|
});
|
|
40
40
|
|
|
41
|
-
|
|
42
41
|
it('should find null', () => {
|
|
43
42
|
expect(list.find(val => val === 6)).toBe(null);
|
|
44
|
-
|
|
45
43
|
});
|
|
46
44
|
|
|
47
45
|
it('should indexOf -1', () => {
|
|
@@ -60,13 +58,11 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
60
58
|
// @ts-ignore
|
|
61
59
|
expect([...list]).toEqual([1, 2, 3, 4, 5]);
|
|
62
60
|
});
|
|
63
|
-
|
|
64
|
-
|
|
65
61
|
});
|
|
66
62
|
|
|
67
63
|
describe('DoublyLinkedList Operation Test', () => {
|
|
68
64
|
let list: DoublyLinkedList<number>;
|
|
69
|
-
let objectList: DoublyLinkedList<{
|
|
65
|
+
let objectList: DoublyLinkedList<{keyA: number}>;
|
|
70
66
|
|
|
71
67
|
beforeEach(() => {
|
|
72
68
|
list = new DoublyLinkedList();
|
|
@@ -7,15 +7,15 @@ describe('SinglyLinkedListNode', () => {
|
|
|
7
7
|
expect(node1.val).toBe(2);
|
|
8
8
|
node1.val = 1;
|
|
9
9
|
expect(node1.val).toBe(1);
|
|
10
|
-
})
|
|
10
|
+
});
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
describe('SinglyLinkedList Operation Test', () => {
|
|
14
14
|
let list: SinglyLinkedList<number>;
|
|
15
|
-
let objectList: SinglyLinkedList<{
|
|
15
|
+
let objectList: SinglyLinkedList<{keyA: number}>;
|
|
16
16
|
beforeEach(() => {
|
|
17
17
|
list = new SinglyLinkedList<number>();
|
|
18
|
-
objectList = new SinglyLinkedList<{
|
|
18
|
+
objectList = new SinglyLinkedList<{keyA: number}>();
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
describe('push', () => {
|
|
@@ -446,7 +446,6 @@ describe('SinglyLinkedList', () => {
|
|
|
446
446
|
expect(list.length).toBe(1);
|
|
447
447
|
});
|
|
448
448
|
|
|
449
|
-
|
|
450
449
|
it('should reverse the list', () => {
|
|
451
450
|
list.push(1);
|
|
452
451
|
list.push(2);
|
|
@@ -457,7 +456,6 @@ describe('SinglyLinkedList', () => {
|
|
|
457
456
|
// Add more assertions for reversed order.
|
|
458
457
|
});
|
|
459
458
|
|
|
460
|
-
|
|
461
459
|
it('should convert the list to an array', () => {
|
|
462
460
|
list.push(1);
|
|
463
461
|
list.push(2);
|
|
@@ -475,13 +473,12 @@ describe('SinglyLinkedList', () => {
|
|
|
475
473
|
expect(list.filter(val => val !== 2).toArray()).toEqual([1, 3]);
|
|
476
474
|
});
|
|
477
475
|
|
|
478
|
-
|
|
479
476
|
it('should forEach the list', () => {
|
|
480
477
|
list.push(1);
|
|
481
478
|
list.push(2);
|
|
482
479
|
list.push(3);
|
|
483
480
|
list.forEach(val => val++);
|
|
484
|
-
expect(list.toArray()).toEqual([1, 2, 3])
|
|
481
|
+
expect(list.toArray()).toEqual([1, 2, 3]);
|
|
485
482
|
});
|
|
486
483
|
|
|
487
484
|
it('should map the list', () => {
|
|
@@ -17,7 +17,7 @@ describe('MaxPriorityQueue Operation Test', () => {
|
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
it('should add elements and maintain heap property in a object MaxPriorityQueue', () => {
|
|
20
|
-
const priorityQueue = new MaxPriorityQueue<{
|
|
20
|
+
const priorityQueue = new MaxPriorityQueue<{keyA: number}>({comparator: (a, b) => b.keyA - a.keyA});
|
|
21
21
|
priorityQueue.refill([{keyA: 5}, {keyA: 3}, {keyA: 1}]);
|
|
22
22
|
priorityQueue.add({keyA: 7});
|
|
23
23
|
|
|
@@ -64,7 +64,7 @@ describe('MaxPriorityQueue Operation Test', () => {
|
|
|
64
64
|
|
|
65
65
|
it('should correctly heapify an object array', () => {
|
|
66
66
|
const nodes = [{keyA: 5}, {keyA: 3}, {keyA: 7}, {keyA: 1}];
|
|
67
|
-
const maxPQ = MaxPriorityQueue.heapify<{
|
|
67
|
+
const maxPQ = MaxPriorityQueue.heapify<{keyA: number}>({nodes: nodes, comparator: (a, b) => b.keyA - a.keyA});
|
|
68
68
|
|
|
69
69
|
expect(maxPQ.poll()?.keyA).toBe(7);
|
|
70
70
|
expect(maxPQ.poll()?.keyA).toBe(5);
|
package/test/utils/big-o.ts
CHANGED
|
@@ -26,7 +26,7 @@ export const bigO = {
|
|
|
26
26
|
|
|
27
27
|
function findPotentialN(input: any): number {
|
|
28
28
|
let longestArray: any[] = [];
|
|
29
|
-
let mostProperties: {
|
|
29
|
+
let mostProperties: {[key: string]: any} = {};
|
|
30
30
|
|
|
31
31
|
function recurse(obj: any) {
|
|
32
32
|
if (Array.isArray(obj)) {
|