From aece11bd01774c3787ce4d31dbeb517bd4ed4a5b Mon Sep 17 00:00:00 2001 From: Revone Date: Tue, 29 Oct 2024 17:27:40 +1300 Subject: [PATCH] release: v1.52.6 --- CHANGELOG.md | 2 +- README.md | 26 +-- package-lock.json | 52 ++--- package.json | 12 +- .../binary-tree/binary-tree.ts | 4 +- src/data-structures/tree/tree.ts | 1 + test/integration/all-in-one.test.ts | 2 +- test/integration/avl-tree.test.ts | 2 +- test/integration/bst.test.ts | 4 +- .../binary-tree/binary-tree.test.ts | 188 +++++++++--------- 10 files changed, 142 insertions(+), 151 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6db496..d4de88a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file. - [Semantic Versioning](https://semver.org/spec/v2.0.0.html) - [`auto-changelog`](https://github.com/CookPete/auto-changelog) -## [v1.52.4](https://github.com/zrwusa/data-structure-typed/compare/v1.51.5...main) (upcoming) +## [v1.52.6](https://github.com/zrwusa/data-structure-typed/compare/v1.51.5...main) (upcoming) ### Changes diff --git a/README.md b/README.md index 5e75843..9654003 100644 --- a/README.md +++ b/README.md @@ -823,43 +823,43 @@ Version 11.7.9 [//]: # (No deletion!!! Start of Replace Section)
heap
-
test nametime taken (ms)executions per secsample deviation
100,000 add7.55132.362.00e-4
100,000 add & poll44.1722.640.00
+
test nametime taken (ms)executions per secsample deviation
100,000 add7.51133.171.36e-4
100,000 add & poll44.2522.600.00
rb-tree
-
test nametime taken (ms)executions per secsample deviation
100,000 add77.0312.980.00
100,000 add randomly80.7412.380.00
100,000 get111.298.990.00
100,000 iterator24.9140.140.01
100,000 add & delete orderly153.126.530.00
100,000 add & delete randomly233.764.280.00
+
test nametime taken (ms)executions per secsample deviation
100,000 add76.9812.990.00
100,000 add randomly80.9612.350.00
100,000 get111.728.950.00
100,000 iterator29.5833.810.00
100,000 add & delete orderly153.216.530.00
100,000 add & delete randomly233.264.290.00
queue
-
test nametime taken (ms)executions per secsample deviation
1,000,000 push43.7922.830.01
100,000 push & shift5.09196.545.29e-4
Native JS Array 100,000 push & shift2134.490.470.18
+
test nametime taken (ms)executions per secsample deviation
1,000,000 push42.1823.710.01
100,000 push & shift5.16193.667.47e-4
Native JS Array 100,000 push & shift2386.290.420.30
deque
-
test nametime taken (ms)executions per secsample deviation
1,000,000 push25.3939.390.00
1,000,000 push & pop32.9330.370.01
1,000,000 push & shift32.3630.900.00
100,000 push & shift3.41293.263.14e-4
Native JS Array 100,000 push & shift2309.810.430.46
100,000 unshift & shift3.24308.353.36e-4
Native JS Array 100,000 unshift & shift4213.920.240.20
+
test nametime taken (ms)executions per secsample deviation
1,000,000 push23.5942.400.00
1,000,000 push & pop31.9331.320.00
1,000,000 push & shift33.1230.190.00
100,000 push & shift3.50285.579.51e-4
Native JS Array 100,000 push & shift2211.260.450.34
100,000 unshift & shift3.41292.895.52e-4
Native JS Array 100,000 unshift & shift4343.810.230.25
hash-map
-
test nametime taken (ms)executions per secsample deviation
1,000,000 set107.769.280.02
Native JS Map 1,000,000 set204.814.880.02
Native JS Set 1,000,000 add165.266.050.01
1,000,000 set & get121.138.260.02
Native JS Map 1,000,000 set & get265.523.770.01
Native JS Set 1,000,000 add & has167.985.950.01
1,000,000 ObjKey set & get331.863.010.04
Native JS Map 1,000,000 ObjKey set & get322.123.100.05
Native JS Set 1,000,000 ObjKey add & has267.743.730.03
+
test nametime taken (ms)executions per secsample deviation
1,000,000 set259.743.850.07
Native JS Map 1,000,000 set208.354.800.02
Native JS Set 1,000,000 add167.665.960.01
1,000,000 set & get260.463.840.04
Native JS Map 1,000,000 set & get265.093.770.02
Native JS Set 1,000,000 add & has169.155.910.01
1,000,000 ObjKey set & get317.233.150.04
Native JS Map 1,000,000 ObjKey set & get304.843.280.04
Native JS Set 1,000,000 ObjKey add & has278.303.590.05
trie
-
test nametime taken (ms)executions per secsample deviation
100,000 push42.7923.377.76e-4
100,000 getWords81.8212.220.00
+
test nametime taken (ms)executions per secsample deviation
100,000 push43.9322.765.95e-4
100,000 getWords82.1812.170.00
avl-tree
-
test nametime taken (ms)executions per secsample deviation
100,000 add270.763.690.01
100,000 add randomly326.943.060.00
100,000 get129.137.740.00
100,000 iterator30.9632.300.00
100,000 add & delete orderly440.622.270.00
100,000 add & delete randomly589.061.700.00
+
test nametime taken (ms)executions per secsample deviation
100,000 add275.723.630.00
100,000 add randomly332.353.010.00
100,000 get129.567.720.00
100,000 iterator32.0331.220.01
100,000 add & delete orderly447.872.230.00
100,000 add & delete randomly605.401.650.03
binary-tree-overall
-
test nametime taken (ms)executions per secsample deviation
10,000 RBTree add randomly6.89145.169.69e-5
10,000 RBTree get randomly9.22108.431.55e-4
10,000 RBTree add & delete randomly18.7053.461.16e-4
10,000 AVLTree add randomly24.4540.912.06e-4
10,000 AVLTree get randomly9.77102.341.09e-4
10,000 AVLTree add & delete randomly45.7121.884.07e-4
+
test nametime taken (ms)executions per secsample deviation
10,000 RBTree add randomly6.91144.821.13e-4
10,000 RBTree get randomly9.08110.147.72e-5
10,000 RBTree add & delete randomly18.9752.718.49e-4
10,000 AVLTree add randomly24.9740.054.34e-4
10,000 AVLTree get randomly9.95100.470.00
10,000 AVLTree add & delete randomly45.9621.765.77e-4
directed-graph
-
test nametime taken (ms)executions per secsample deviation
1,000 addVertex0.109817.839.67e-7
1,000 addEdge6.18161.721.55e-4
1,000 getVertex0.042.51e+45.08e-7
1,000 getEdge22.8243.820.00
tarjan211.734.720.02
topologicalSort188.715.300.02
+
test nametime taken (ms)executions per secsample deviation
1,000 addVertex0.109730.421.39e-6
1,000 addEdge6.01166.329.47e-5
1,000 getVertex0.042.59e+43.52e-7
1,000 getEdge23.8042.030.00
tarjan215.664.640.01
topologicalSort187.855.320.00
doubly-linked-list
-
test nametime taken (ms)executions per secsample deviation
1,000,000 push212.174.710.03
1,000,000 unshift210.094.760.03
1,000,000 unshift & shift213.414.690.07
1,000,000 addBefore320.833.120.07
+
test nametime taken (ms)executions per secsample deviation
1,000,000 push197.455.060.03
1,000,000 unshift214.024.670.08
1,000,000 unshift & shift198.975.030.05
1,000,000 addBefore315.443.170.05
singly-linked-list
-
test nametime taken (ms)executions per secsample deviation
1,000,000 push & shift205.404.870.05
10,000 push & pop220.934.530.00
10,000 addBefore248.194.030.01
+
test nametime taken (ms)executions per secsample deviation
1,000,000 push & shift196.915.080.04
10,000 push & pop222.294.500.01
10,000 addBefore248.874.020.01
priority-queue
-
test nametime taken (ms)executions per secsample deviation
100,000 add27.5536.309.81e-4
100,000 add & poll76.2613.116.92e-4
+
test nametime taken (ms)executions per secsample deviation
100,000 add27.6936.118.96e-4
100,000 add & poll75.3813.276.45e-4
stack
-
test nametime taken (ms)executions per secsample deviation
1,000,000 push39.1925.520.00
1,000,000 push & pop44.9022.270.00
+
test nametime taken (ms)executions per secsample deviation
1,000,000 push39.1925.520.00
1,000,000 push & pop45.2422.100.00
[//]: # (No deletion!!! End of Replace Section) diff --git a/package-lock.json b/package-lock.json index e939219..e1fa1fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "data-structure-typed", - "version": "1.52.4", + "version": "1.52.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "data-structure-typed", - "version": "1.52.4", + "version": "1.52.6", "license": "MIT", "devDependencies": { "@swc/core": "^1.3.96", @@ -16,11 +16,11 @@ "@typescript-eslint/eslint-plugin": "^6.7.4", "@typescript-eslint/parser": "^6.7.4", "auto-changelog": "^2.4.0", - "avl-tree-typed": "^1.52.3", + "avl-tree-typed": "^1.52.5", "benchmark": "^2.1.4", - "binary-tree-typed": "^1.52.3", - "bst-typed": "^1.52.3", - "data-structure-typed": "^1.52.3", + "binary-tree-typed": "^1.52.5", + "bst-typed": "^1.52.5", + "data-structure-typed": "^1.52.5", "dependency-cruiser": "^14.1.0", "doctoc": "^2.2.1", "eslint": "^8.50.0", @@ -29,7 +29,7 @@ "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-import": "^2.28.1", "fast-glob": "^3.3.1", - "heap-typed": "^1.52.3", + "heap-typed": "^1.52.5", "istanbul-badges-readme": "^1.8.5", "jest": "^29.7.0", "js-sdsl": "^4.4.2", @@ -3331,13 +3331,13 @@ } }, "node_modules/avl-tree-typed": { - "version": "1.52.3", - "resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.52.3.tgz", - "integrity": "sha512-r+SKVutucbF9VLDTRxthCZXAtKa1gXVsWgz2/0JISW7gZ09IfhND1Sj40LwivQSACU2YxfsVPcNFs2AnaDXz2g==", + "version": "1.52.5", + "resolved": "https://registry.npmjs.org/avl-tree-typed/-/avl-tree-typed-1.52.5.tgz", + "integrity": "sha512-vyIoFiP73qDNTLkTreE8FCzwVhEMm0XlAHvIHKGwbX2OFVPoS84wnrbKOWhz5XGtX+/NeQm9eJkEORnFWGGFHg==", "dev": true, "license": "MIT", "dependencies": { - "data-structure-typed": "^1.52.3" + "data-structure-typed": "^1.52.5" } }, "node_modules/babel-jest": { @@ -3562,13 +3562,13 @@ } }, "node_modules/binary-tree-typed": { - "version": "1.52.3", - "resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.52.3.tgz", - "integrity": "sha512-mozUp3u+iHym8EhpUL+CyvRil9ZgDrKEwE0d/E8CKiS7XggWTjNVIXPOxGBB4vNFPbmOf+PaMdVivncr9nEQGQ==", + "version": "1.52.5", + "resolved": "https://registry.npmjs.org/binary-tree-typed/-/binary-tree-typed-1.52.5.tgz", + "integrity": "sha512-RlJCcnaq0w1M/X92Z20DbnDVY09QE6+5bvyZzI3pB2EvUSyXDiTiyJI4c9S3GtkXDg3jaMGGGPp4wfkkDcVXgQ==", "dev": true, "license": "MIT", "dependencies": { - "data-structure-typed": "^1.52.3" + "data-structure-typed": "^1.52.5" } }, "node_modules/brace-expansion": { @@ -3651,13 +3651,13 @@ } }, "node_modules/bst-typed": { - "version": "1.52.3", - "resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.52.3.tgz", - "integrity": "sha512-fJLUL5O7+5ozB5bb0tkRAvxiB4Ldmgr7yVTBjTS8w2TbBCafT4viYJ2H+1rrAhgR6mHgHt+8w20O7emzCwkacA==", + "version": "1.52.5", + "resolved": "https://registry.npmjs.org/bst-typed/-/bst-typed-1.52.5.tgz", + "integrity": "sha512-wl3iu4bPEdd3f25AlrlkPyCl1COAN7LkxJ+mTJqvRoc7QM/wYK1r2/YETnkPAWO16HEK6GMRKiroIb16BFwVaQ==", "dev": true, "license": "MIT", "dependencies": { - "data-structure-typed": "^1.52.3" + "data-structure-typed": "^1.52.5" } }, "node_modules/buffer-from": { @@ -4141,9 +4141,9 @@ } }, "node_modules/data-structure-typed": { - "version": "1.52.3", - "resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.52.3.tgz", - "integrity": "sha512-7TGeW3NN3WT+lPH+//B7W8QPV81jtzuDy+lGGsyOe9vNikWt5NjEWmdDXreLg0T6EPbDG12LEp6f2lafUaYwCw==", + "version": "1.52.5", + "resolved": "https://registry.npmjs.org/data-structure-typed/-/data-structure-typed-1.52.5.tgz", + "integrity": "sha512-nWI6dUp3teOmGf1D9hZVhekNBYb2ZMZxAgSX2lKvXUWuuEsd5GBu6uMFO5Vn+3I/f0nHCNptjq9c5WTK9dEycg==", "dev": true, "license": "MIT" }, @@ -6008,13 +6008,13 @@ } }, "node_modules/heap-typed": { - "version": "1.52.3", - "resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.52.3.tgz", - "integrity": "sha512-G2PQwpAVfJBO2/C+398n6BPXxE5HZm/aKY9rqkkDWB1jdzyAvMQxy+bELrjP0or0KJAFw7vrgcm2x23Ox7Ul1g==", + "version": "1.52.5", + "resolved": "https://registry.npmjs.org/heap-typed/-/heap-typed-1.52.5.tgz", + "integrity": "sha512-qW7dNZxquHbm73fVw4dRWy/nZIY8XiFpx24hXslHw364QATAc3eZ9CAAtlzFgh3fteMzAb8iMzkVND/NCUr48w==", "dev": true, "license": "MIT", "dependencies": { - "data-structure-typed": "^1.52.3" + "data-structure-typed": "^1.52.5" } }, "node_modules/html-escaper": { diff --git a/package.json b/package.json index b19c699..11adc0e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "data-structure-typed", - "version": "1.52.5", + "version": "1.52.6", "description": "Javascript Data Structure. Heap, Binary Tree, Red Black Tree, Linked List, Deque, Trie, HashMap, Directed Graph, Undirected Graph, Binary Search Tree(BST), AVL Tree, Priority Queue, Graph, Queue, Tree Multiset, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue, Stack. Benchmark compared with C++ STL. API aligned with ES6 and Java.util. Usability is comparable to Python", "main": "dist/cjs/index.js", "module": "dist/mjs/index.js", @@ -66,11 +66,11 @@ "@typescript-eslint/eslint-plugin": "^6.7.4", "@typescript-eslint/parser": "^6.7.4", "auto-changelog": "^2.4.0", - "avl-tree-typed": "^1.52.3", + "avl-tree-typed": "^1.52.5", "benchmark": "^2.1.4", - "binary-tree-typed": "^1.52.3", - "bst-typed": "^1.52.3", - "data-structure-typed": "^1.52.3", + "binary-tree-typed": "^1.52.5", + "bst-typed": "^1.52.5", + "data-structure-typed": "^1.52.5", "dependency-cruiser": "^14.1.0", "doctoc": "^2.2.1", "eslint": "^8.50.0", @@ -79,7 +79,7 @@ "eslint-import-resolver-typescript": "^3.6.1", "eslint-plugin-import": "^2.28.1", "fast-glob": "^3.3.1", - "heap-typed": "^1.52.3", + "heap-typed": "^1.52.5", "istanbul-badges-readme": "^1.8.5", "jest": "^29.7.0", "js-sdsl": "^4.4.2", diff --git a/src/data-structures/binary-tree/binary-tree.ts b/src/data-structures/binary-tree/binary-tree.ts index 80160db..228947b 100644 --- a/src/data-structures/binary-tree/binary-tree.ts +++ b/src/data-structures/binary-tree/binary-tree.ts @@ -335,7 +335,7 @@ export class BinaryTree< * @returns a boolean value. */ isRealNodeOrNull(node: R | BTNKeyOrNodeOrEntry): node is NODE | null { - return this.isRealNode(node) || node === null; + return node === null || this.isRealNode(node); } /** @@ -1843,7 +1843,7 @@ export class BinaryTree< if (includeNull) return this.isRealNodeOrNull(node); return this.isRealNode(node); }, - shouldProcessRoot: (node: OptBTNOrNull) => boolean = node => true + shouldProcessRoot: (node: OptBTNOrNull) => boolean = node => this.isRealNodeOrNull(node) ): ReturnType[] { beginRoot = this.ensureNode(beginRoot); if (!beginRoot) return []; diff --git a/src/data-structures/tree/tree.ts b/src/data-structures/tree/tree.ts index eeb3d50..6b45728 100644 --- a/src/data-structures/tree/tree.ts +++ b/src/data-structures/tree/tree.ts @@ -12,6 +12,7 @@ export class TreeNode { constructor(key: string, value?: V, children?: TreeNode[]) { this._key = key; this._value = value || undefined; + if (children) this._children = children; } protected _key: string; diff --git a/test/integration/all-in-one.test.ts b/test/integration/all-in-one.test.ts index 7baf79b..ddd7d2f 100644 --- a/test/integration/all-in-one.test.ts +++ b/test/integration/all-in-one.test.ts @@ -19,7 +19,7 @@ describe('AVL Tree Test from data-structure-typed', () => { expect(getMinNodeByRoot?.key).toBe(1); const node15 = tree.getNode(15); - const getMinNodeBySpecificNode = node15 && tree.getLeftMost(node15); + const getMinNodeBySpecificNode = node15 && tree.getLeftMost(node => node, node15); expect(getMinNodeBySpecificNode?.key).toBe(12); let subTreeSum = 0; diff --git a/test/integration/avl-tree.test.ts b/test/integration/avl-tree.test.ts index 5fd2226..e4bd339 100644 --- a/test/integration/avl-tree.test.ts +++ b/test/integration/avl-tree.test.ts @@ -36,7 +36,7 @@ describe('AVL Tree Test', () => { expect(getMinNodeByRoot?.key).toBe(1); const node15 = tree.getNode(15); - const getMinNodeBySpecificNode = node15 && tree.getLeftMost(node15); + const getMinNodeBySpecificNode = node15 && tree.getLeftMost(node => node, node15); expect(getMinNodeBySpecificNode?.key).toBe(12); let subTreeSum = 0; diff --git a/test/integration/bst.test.ts b/test/integration/bst.test.ts index ae55591..aab3632 100644 --- a/test/integration/bst.test.ts +++ b/test/integration/bst.test.ts @@ -30,7 +30,7 @@ describe('Individual package BST operations test', () => { expect(leftMost?.key).toBe(1); const node15 = bst.getNode(15); - const minNodeBySpecificNode = node15 && bst.getLeftMost(node15); + const minNodeBySpecificNode = node15 && bst.getLeftMost(node => node, node15); expect(minNodeBySpecificNode?.key).toBe(12); let subTreeSum = 0; @@ -230,7 +230,7 @@ describe('Individual package BST operations test', () => { key: 15, keyA: 15 }); - const minNodeBySpecificNode = node15 && objBST.getLeftMost(node15); + const minNodeBySpecificNode = node15 && objBST.getLeftMost(node => node, node15); expect(minNodeBySpecificNode?.key).toBe(12); let subTreeSum = 0; diff --git a/test/unit/data-structures/binary-tree/binary-tree.test.ts b/test/unit/data-structures/binary-tree/binary-tree.test.ts index 273b6bf..f1692c4 100644 --- a/test/unit/data-structures/binary-tree/binary-tree.test.ts +++ b/test/unit/data-structures/binary-tree/binary-tree.test.ts @@ -848,110 +848,100 @@ describe('BinaryTree toEntryFn', () => { }); describe('BinaryTree traversals', () => { - const tree = new BinaryTree(); + it('traversals', () => { + const tree = new BinaryTree(); - const arr = [35, 20, 40, 15, 29, null, 50, null, 16, 28, 30, 45, 55]; - tree.refill(arr); - expect(tree.bfs(node => node, tree.root, 'ITERATIVE', true).map(node => (node ? node.key : null))).toEqual([ - 35, - 20, - 40, - 15, - 29, - null, - 50, - null, - 16, - 28, - 30, - 45, - 55 - ]); - expect(tree.bfs(node => node, tree.root, 'RECURSIVE', true).map(node => (node ? node.key : null))).toEqual([ - 35, - 20, - 40, - 15, - 29, - null, - 50, - null, - 16, - 28, - 30, - 45, - 55 - ]); - expect(tree.bfs(node => node, tree.root, 'ITERATIVE').map(node => (node === null ? null : node.key))).toEqual([ - 35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55 - ]); - expect(tree.bfs(node => node, tree.root, 'RECURSIVE').map(node => (node === null ? null : node.key))).toEqual([ - 35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55 - ]); + const arr = [35, 20, 40, 15, 29, null, 50, null, 16, 28, 30, 45, 55]; + tree.refill(arr); + expect(tree.bfs(node => node, tree.root, 'ITERATIVE', true).map(node => (node ? node.key : null))).toEqual([ + 35, + 20, + 40, + 15, + 29, + null, + 50, + null, + 16, + 28, + 30, + 45, + 55 + ]); + expect(tree.bfs(node => node, tree.root, 'RECURSIVE', true).map(node => (node ? node.key : null))).toEqual([ + 35, + 20, + 40, + 15, + 29, + null, + 50, + null, + 16, + 28, + 30, + 45, + 55 + ]); + expect(tree.bfs(node => node, tree.root, 'ITERATIVE').map(node => (node === null ? null : node.key))).toEqual([ + 35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55 + ]); + expect(tree.bfs(node => node, tree.root, 'RECURSIVE').map(node => (node === null ? null : node.key))).toEqual([ + 35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55 + ]); - expect(tree.dfs(node => node.key, 'PRE')).toEqual([35, 20, 15, 16, 29, 28, 30, 40, 50, 45, 55]); - expect(tree.dfs(node => node.key, 'PRE', tree.root, 'RECURSIVE')).toEqual([ - 35, 20, 15, 16, 29, 28, 30, 40, 50, 45, 55 - ]); - expect(tree.dfs(node => node, 'PRE', tree.root, 'ITERATIVE', true).map(node => (node ? node.key : null))).toEqual([ - 35, - 20, - 15, - null, - 16, - 29, - 28, - 30, - 40, - null, - 50, - 45, - 55 - ]); - expect(tree.dfs(node => node, 'PRE', tree.root, 'RECURSIVE', true).map(node => (node ? node.key : null))).toEqual([ - 35, - 20, - 15, - null, - 16, - 29, - 28, - 30, - 40, - null, - 50, - 45, - 55 - ]); + expect(tree.dfs(node => node.key, 'PRE')).toEqual([35, 20, 15, 16, 29, 28, 30, 40, 50, 45, 55]); + expect(tree.dfs(node => node.key, 'PRE', tree.root, 'RECURSIVE')).toEqual([ + 35, 20, 15, 16, 29, 28, 30, 40, 50, 45, 55 + ]); + expect( + tree.dfs(node => node, 'PRE', tree.root, 'ITERATIVE', true).map(node => (node === null ? null : node.key)) + ).toEqual([35, 20, 15, null, 16, 29, 28, 30, 40, null, 50, 45, 55]); + expect(tree.dfs(node => node, 'PRE', tree.root, 'RECURSIVE', true).map(node => (node ? node.key : null))).toEqual([ + 35, + 20, + 15, + null, + 16, + 29, + 28, + 30, + 40, + null, + 50, + 45, + 55 + ]); - expect(tree.dfs(node => node.key, 'IN')).toEqual([15, 16, 20, 28, 29, 30, 35, 40, 45, 50, 55]); - expect(tree.dfs(node => node.key, 'POST')).toEqual([16, 15, 28, 30, 29, 20, 45, 55, 50, 40, 35]); - expect(tree.dfs(node => node.key, 'POST', tree.root, 'RECURSIVE')).toEqual([ - 16, 15, 28, 30, 29, 20, 45, 55, 50, 40, 35 - ]); - expect(tree.bfs(node => node.key, tree.root, 'RECURSIVE')).toEqual([35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55]); - expect(tree.bfs(node => node.key, tree.root, 'ITERATIVE')).toEqual([35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55]); + expect(tree.dfs(node => node.key, 'IN')).toEqual([15, 16, 20, 28, 29, 30, 35, 40, 45, 50, 55]); + expect(tree.dfs(node => node.key, 'POST')).toEqual([16, 15, 28, 30, 29, 20, 45, 55, 50, 40, 35]); + expect(tree.dfs(node => node.key, 'POST', tree.root, 'RECURSIVE')).toEqual([ + 16, 15, 28, 30, 29, 20, 45, 55, 50, 40, 35 + ]); + expect(tree.bfs(node => node.key, tree.root, 'RECURSIVE')).toEqual([35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55]); + expect(tree.bfs(node => node.key, tree.root, 'ITERATIVE')).toEqual([35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55]); - expect(tree.listLevels(node => node.key)).toEqual([[35], [20, 40], [15, 29, 50], [16, 28, 30, 45, 55]]); + expect(tree.listLevels(node => node.key)).toEqual([[35], [20, 40], [15, 29, 50], [16, 28, 30, 45, 55]]); - expect(tree.listLevels(node => node.key, tree.root, 'RECURSIVE')).toEqual([ - [35], - [20, 40], - [15, 29, 50], - [16, 28, 30, 45, 55] - ]); - expect(tree.listLevels(node => (node ? node.key : null), tree.root, 'ITERATIVE', true)).toEqual([ - [35], - [20, 40], - [15, 29, null, 50], - [null, 16, 28, 30, 45, 55] - ]); - expect(tree.listLevels(node => (node ? node.key : null), tree.root, 'RECURSIVE', true)).toEqual([ - [35], - [20, 40], - [15, 29, null, 50], - [null, 16, 28, 30, 45, 55] - ]); + expect(tree.listLevels(node => node.key, tree.root, 'RECURSIVE')).toEqual([ + [35], + [20, 40], + [15, 29, 50], + [16, 28, 30, 45, 55] + ]); + expect(tree.listLevels(node => (node ? node.key : null), tree.root, 'ITERATIVE', true)).toEqual([ + [35], + [20, 40], + [15, 29, null, 50], + [null, 16, 28, 30, 45, 55] + ]); + expect(tree.listLevels(node => (node ? node.key : null), tree.root, 'RECURSIVE', true)).toEqual([ + [35], + [20, 40], + [15, 29, null, 50], + [null, 16, 28, 30, 45, 55] + ]); + }); }); describe('BinaryTree', () => {