binary-tree-typed 1.34.4 → 1.34.6
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/coverage/clover.xml +7 -3
- package/coverage/coverage-final.json +2 -1
- package/coverage/coverage-summary.json +2 -1
- package/coverage/lcov-report/index.html +25 -10
- package/coverage/lcov-report/index.ts.html +109 -0
- package/coverage/lcov.info +14 -0
- package/package.json +2 -2
- package/test/index.test.ts +137 -2
package/coverage/clover.xml
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<coverage generated="
|
|
3
|
-
<project timestamp="
|
|
4
|
-
<metrics statements="
|
|
2
|
+
<coverage generated="1696760523176" clover="3.2.0">
|
|
3
|
+
<project timestamp="1696760523176" name="All files">
|
|
4
|
+
<metrics statements="1" coveredstatements="1" conditionals="0" coveredconditionals="0" methods="2" coveredmethods="2" elements="3" coveredelements="3" complexity="0" loc="1" ncloc="1" packages="1" files="1" classes="1"/>
|
|
5
|
+
<file name="index.ts" path="/Users/revone/projects/data-structure-typed-individuals/binary-tree-typed/src/index.ts">
|
|
6
|
+
<metrics statements="1" coveredstatements="1" conditionals="0" coveredconditionals="0" methods="2" coveredmethods="2"/>
|
|
7
|
+
<line num="8" count="15" type="stmt"/>
|
|
8
|
+
</file>
|
|
5
9
|
</project>
|
|
6
10
|
</coverage>
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
{}
|
|
1
|
+
{"/Users/revone/projects/data-structure-typed-individuals/binary-tree-typed/src/index.ts": {"path":"/Users/revone/projects/data-structure-typed-individuals/binary-tree-typed/src/index.ts","statementMap":{"0":{"start":{"line":8,"column":0},"end":{"line":8,"column":9}},"1":{"start":{"line":8,"column":9},"end":{"line":8,"column":25}},"2":{"start":{"line":8,"column":25},"end":{"line":8,"column":66}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":8,"column":9},"end":{"line":8,"column":23}},"loc":{"start":{"line":8,"column":9},"end":{"line":8,"column":25}}},"1":{"name":"(anonymous_1)","decl":{"start":{"line":8,"column":25},"end":{"line":8,"column":35}},"loc":{"start":{"line":8,"column":25},"end":{"line":8,"column":66}}}},"branchMap":{},"s":{"0":1,"1":15,"2":6},"f":{"0":14,"1":5},"b":{}}
|
|
2
|
+
}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
{"total": {"lines":{"total":
|
|
1
|
+
{"total": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":3,"covered":3,"skipped":0,"pct":100},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":"Unknown"}}
|
|
2
|
+
,"/Users/revone/projects/data-structure-typed-individuals/binary-tree-typed/src/index.ts": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":3,"covered":3,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
|
|
2
3
|
}
|
|
@@ -23,30 +23,30 @@
|
|
|
23
23
|
<div class='clearfix'>
|
|
24
24
|
|
|
25
25
|
<div class='fl pad1y space-right2'>
|
|
26
|
-
<span class="strong">
|
|
26
|
+
<span class="strong">100% </span>
|
|
27
27
|
<span class="quiet">Statements</span>
|
|
28
|
-
<span class='fraction'>
|
|
28
|
+
<span class='fraction'>3/3</span>
|
|
29
29
|
</div>
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
<div class='fl pad1y space-right2'>
|
|
33
|
-
<span class="strong">
|
|
33
|
+
<span class="strong">100% </span>
|
|
34
34
|
<span class="quiet">Branches</span>
|
|
35
35
|
<span class='fraction'>0/0</span>
|
|
36
36
|
</div>
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
<div class='fl pad1y space-right2'>
|
|
40
|
-
<span class="strong">
|
|
40
|
+
<span class="strong">100% </span>
|
|
41
41
|
<span class="quiet">Functions</span>
|
|
42
|
-
<span class='fraction'>
|
|
42
|
+
<span class='fraction'>2/2</span>
|
|
43
43
|
</div>
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
<div class='fl pad1y space-right2'>
|
|
47
|
-
<span class="strong">
|
|
47
|
+
<span class="strong">100% </span>
|
|
48
48
|
<span class="quiet">Lines</span>
|
|
49
|
-
<span class='fraction'>
|
|
49
|
+
<span class='fraction'>1/1</span>
|
|
50
50
|
</div>
|
|
51
51
|
|
|
52
52
|
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
</div>
|
|
62
62
|
</template>
|
|
63
63
|
</div>
|
|
64
|
-
<div class='status-line
|
|
64
|
+
<div class='status-line high'></div>
|
|
65
65
|
<div class="pad1">
|
|
66
66
|
<table class="coverage-summary">
|
|
67
67
|
<thead>
|
|
@@ -78,7 +78,22 @@
|
|
|
78
78
|
<th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
|
|
79
79
|
</tr>
|
|
80
80
|
</thead>
|
|
81
|
-
<tbody
|
|
81
|
+
<tbody><tr>
|
|
82
|
+
<td class="file high" data-value="index.ts"><a href="index.ts.html">index.ts</a></td>
|
|
83
|
+
<td data-value="100" class="pic high">
|
|
84
|
+
<div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
|
|
85
|
+
</td>
|
|
86
|
+
<td data-value="100" class="pct high">100%</td>
|
|
87
|
+
<td data-value="3" class="abs high">3/3</td>
|
|
88
|
+
<td data-value="100" class="pct high">100%</td>
|
|
89
|
+
<td data-value="0" class="abs high">0/0</td>
|
|
90
|
+
<td data-value="100" class="pct high">100%</td>
|
|
91
|
+
<td data-value="2" class="abs high">2/2</td>
|
|
92
|
+
<td data-value="100" class="pct high">100%</td>
|
|
93
|
+
<td data-value="1" class="abs high">1/1</td>
|
|
94
|
+
</tr>
|
|
95
|
+
|
|
96
|
+
</tbody>
|
|
82
97
|
</table>
|
|
83
98
|
</div>
|
|
84
99
|
<div class='push'></div><!-- for sticky footer -->
|
|
@@ -86,7 +101,7 @@
|
|
|
86
101
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
87
102
|
Code coverage generated by
|
|
88
103
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
89
|
-
at 2023-10-
|
|
104
|
+
at 2023-10-08T10:22:03.193Z
|
|
90
105
|
</div>
|
|
91
106
|
<script src="prettify.js"></script>
|
|
92
107
|
<script>
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
|
|
2
|
+
<!doctype html>
|
|
3
|
+
<html lang="en">
|
|
4
|
+
|
|
5
|
+
<head>
|
|
6
|
+
<title>Code coverage report for index.ts</title>
|
|
7
|
+
<meta charset="utf-8" />
|
|
8
|
+
<link rel="stylesheet" href="prettify.css" />
|
|
9
|
+
<link rel="stylesheet" href="base.css" />
|
|
10
|
+
<link rel="shortcut icon" type="image/x-icon" href="favicon.png" />
|
|
11
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
12
|
+
<style type='text/css'>
|
|
13
|
+
.coverage-summary .sorter {
|
|
14
|
+
background-image: url(sort-arrow-sprite.png);
|
|
15
|
+
}
|
|
16
|
+
</style>
|
|
17
|
+
</head>
|
|
18
|
+
|
|
19
|
+
<body>
|
|
20
|
+
<div class='wrapper'>
|
|
21
|
+
<div class='pad1'>
|
|
22
|
+
<h1><a href="index.html">All files</a> index.ts</h1>
|
|
23
|
+
<div class='clearfix'>
|
|
24
|
+
|
|
25
|
+
<div class='fl pad1y space-right2'>
|
|
26
|
+
<span class="strong">100% </span>
|
|
27
|
+
<span class="quiet">Statements</span>
|
|
28
|
+
<span class='fraction'>3/3</span>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<div class='fl pad1y space-right2'>
|
|
33
|
+
<span class="strong">100% </span>
|
|
34
|
+
<span class="quiet">Branches</span>
|
|
35
|
+
<span class='fraction'>0/0</span>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
<div class='fl pad1y space-right2'>
|
|
40
|
+
<span class="strong">100% </span>
|
|
41
|
+
<span class="quiet">Functions</span>
|
|
42
|
+
<span class='fraction'>2/2</span>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
<div class='fl pad1y space-right2'>
|
|
47
|
+
<span class="strong">100% </span>
|
|
48
|
+
<span class="quiet">Lines</span>
|
|
49
|
+
<span class='fraction'>1/1</span>
|
|
50
|
+
</div>
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
<p class="quiet">
|
|
55
|
+
Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
|
|
56
|
+
</p>
|
|
57
|
+
<template id="filterTemplate">
|
|
58
|
+
<div class="quiet">
|
|
59
|
+
Filter:
|
|
60
|
+
<input oninput="onInput()" type="search" id="fileSearch">
|
|
61
|
+
</div>
|
|
62
|
+
</template>
|
|
63
|
+
</div>
|
|
64
|
+
<div class='status-line high'></div>
|
|
65
|
+
<pre><table class="coverage">
|
|
66
|
+
<tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
|
|
67
|
+
<a name='L2'></a><a href='#L2'>2</a>
|
|
68
|
+
<a name='L3'></a><a href='#L3'>3</a>
|
|
69
|
+
<a name='L4'></a><a href='#L4'>4</a>
|
|
70
|
+
<a name='L5'></a><a href='#L5'>5</a>
|
|
71
|
+
<a name='L6'></a><a href='#L6'>6</a>
|
|
72
|
+
<a name='L7'></a><a href='#L7'>7</a>
|
|
73
|
+
<a name='L8'></a><a href='#L8'>8</a>
|
|
74
|
+
<a name='L9'></a><a href='#L9'>9</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
|
|
75
|
+
<span class="cline-any cline-neutral"> </span>
|
|
76
|
+
<span class="cline-any cline-neutral"> </span>
|
|
77
|
+
<span class="cline-any cline-neutral"> </span>
|
|
78
|
+
<span class="cline-any cline-neutral"> </span>
|
|
79
|
+
<span class="cline-any cline-neutral"> </span>
|
|
80
|
+
<span class="cline-any cline-neutral"> </span>
|
|
81
|
+
<span class="cline-any cline-yes">15x</span>
|
|
82
|
+
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">/**
|
|
83
|
+
* data-structure-typed
|
|
84
|
+
*
|
|
85
|
+
* @author Tyler Zeng
|
|
86
|
+
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
87
|
+
* @license MIT License
|
|
88
|
+
*/
|
|
89
|
+
export { BinaryTreeNode, BinaryTree } from 'data-structure-typed';
|
|
90
|
+
</pre></td></tr></table></pre>
|
|
91
|
+
|
|
92
|
+
<div class='push'></div><!-- for sticky footer -->
|
|
93
|
+
</div><!-- /wrapper -->
|
|
94
|
+
<div class='footer quiet pad2 space-top1 center small'>
|
|
95
|
+
Code coverage generated by
|
|
96
|
+
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
97
|
+
at 2023-10-08T10:22:03.193Z
|
|
98
|
+
</div>
|
|
99
|
+
<script src="prettify.js"></script>
|
|
100
|
+
<script>
|
|
101
|
+
window.onload = function () {
|
|
102
|
+
prettyPrint();
|
|
103
|
+
};
|
|
104
|
+
</script>
|
|
105
|
+
<script src="sorter.js"></script>
|
|
106
|
+
<script src="block-navigation.js"></script>
|
|
107
|
+
</body>
|
|
108
|
+
</html>
|
|
109
|
+
|
package/coverage/lcov.info
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "binary-tree-typed",
|
|
3
|
-
"version": "1.34.
|
|
3
|
+
"version": "1.34.6",
|
|
4
4
|
"description": "Binary Tree. Javascript & Typescript Data Structure.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -139,6 +139,6 @@
|
|
|
139
139
|
"typescript": "^4.9.5"
|
|
140
140
|
},
|
|
141
141
|
"dependencies": {
|
|
142
|
-
"data-structure-typed": "^1.34.
|
|
142
|
+
"data-structure-typed": "^1.34.6"
|
|
143
143
|
}
|
|
144
144
|
}
|
package/test/index.test.ts
CHANGED
|
@@ -1,5 +1,140 @@
|
|
|
1
|
+
import {BinaryTree, BinaryTreeNode} from '../src';
|
|
2
|
+
|
|
3
|
+
describe('BinaryTreeNode', () => {
|
|
4
|
+
it('should create an instance of BinaryTreeNode', () => {
|
|
5
|
+
const node = new BinaryTreeNode<number>(1);
|
|
6
|
+
expect(node).toBeInstanceOf(BinaryTreeNode);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('should set and get the ID correctly', () => {
|
|
10
|
+
const node = new BinaryTreeNode<number>(1);
|
|
11
|
+
expect(node.id).toBe(1);
|
|
12
|
+
|
|
13
|
+
node.id = 2;
|
|
14
|
+
expect(node.id).toBe(2);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should set and get the value correctly', () => {
|
|
18
|
+
const node: BinaryTreeNode<number> = new BinaryTreeNode<number>(1, 42);
|
|
19
|
+
expect(node.val).toBe(42);
|
|
20
|
+
|
|
21
|
+
node.val = 55;
|
|
22
|
+
expect(node.val).toBe(55);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should set and get the left child correctly', () => {
|
|
26
|
+
const node1 = new BinaryTreeNode<number>(1);
|
|
27
|
+
const node2 = new BinaryTreeNode<number>(2);
|
|
28
|
+
|
|
29
|
+
node1.left = node2;
|
|
30
|
+
|
|
31
|
+
expect(node1.left).toBe(node2);
|
|
32
|
+
expect(node2.parent).toBe(node1);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should set and get the right child correctly', () => {
|
|
36
|
+
const node1 = new BinaryTreeNode<number>(1);
|
|
37
|
+
const node2 = new BinaryTreeNode<number>(2);
|
|
38
|
+
|
|
39
|
+
node1.right = node2;
|
|
40
|
+
|
|
41
|
+
expect(node1.right).toBe(node2);
|
|
42
|
+
expect(node2.parent).toBe(node1);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should set and get the parent correctly', () => {
|
|
46
|
+
const node1 = new BinaryTreeNode<number>(1);
|
|
47
|
+
const node2 = new BinaryTreeNode<number>(2);
|
|
48
|
+
|
|
49
|
+
node1.left = node2;
|
|
50
|
+
|
|
51
|
+
expect(node2.parent).toBe(node1);
|
|
52
|
+
expect(node1.left).toBe(node2);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should set and get the height correctly', () => {
|
|
56
|
+
const node = new BinaryTreeNode<number>(1);
|
|
57
|
+
expect(node.height).toBe(0);
|
|
58
|
+
|
|
59
|
+
node.height = 3;
|
|
60
|
+
expect(node.height).toBe(3);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should determine family position correctly', () => {
|
|
64
|
+
const root = new BinaryTreeNode<number>(1);
|
|
65
|
+
const leftChild = new BinaryTreeNode<number>(2);
|
|
66
|
+
const rightChild = new BinaryTreeNode<number>(3);
|
|
67
|
+
|
|
68
|
+
root.left = leftChild;
|
|
69
|
+
root.right = rightChild;
|
|
70
|
+
|
|
71
|
+
expect(leftChild.familyPosition).toBe('LEFT');
|
|
72
|
+
expect(rightChild.familyPosition).toBe('RIGHT');
|
|
73
|
+
expect(root.familyPosition).toBe('ROOT');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
1
76
|
describe('Operation Test', () => {
|
|
2
|
-
|
|
3
|
-
|
|
77
|
+
let binaryTree: BinaryTree;
|
|
78
|
+
|
|
79
|
+
beforeEach(() => {
|
|
80
|
+
binaryTree = new BinaryTree();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
afterEach(() => {
|
|
84
|
+
binaryTree.clear();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('should add a node', () => {
|
|
88
|
+
const node = binaryTree.add(1);
|
|
89
|
+
expect(node).not.toBeNull();
|
|
90
|
+
expect(binaryTree.size).toBe(1);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('should remove a node', () => {
|
|
94
|
+
const node = binaryTree.add(1);
|
|
95
|
+
expect(binaryTree.size).toBe(1);
|
|
96
|
+
|
|
97
|
+
if (node) {
|
|
98
|
+
const result = binaryTree.remove(node);
|
|
99
|
+
expect(result).toHaveLength(1);
|
|
100
|
+
expect(binaryTree.size).toBe(0);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('should add and find nodes', () => {
|
|
105
|
+
binaryTree.add(1);
|
|
106
|
+
binaryTree.add(2);
|
|
107
|
+
binaryTree.add(3);
|
|
108
|
+
|
|
109
|
+
expect(binaryTree.has(1)).toBe(true);
|
|
110
|
+
expect(binaryTree.has(2)).toBe(true);
|
|
111
|
+
expect(binaryTree.has(3)).toBe(true);
|
|
112
|
+
expect(binaryTree.has(4)).toBe(false);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('should traverse in-order', () => {
|
|
116
|
+
binaryTree.add(4);
|
|
117
|
+
binaryTree.add(2);
|
|
118
|
+
binaryTree.add(6);
|
|
119
|
+
binaryTree.add(1);
|
|
120
|
+
binaryTree.add(3);
|
|
121
|
+
binaryTree.add(5);
|
|
122
|
+
binaryTree.add(7);
|
|
123
|
+
|
|
124
|
+
const inOrder = binaryTree.DFS('in');
|
|
125
|
+
|
|
126
|
+
expect(inOrder).toEqual([1, 2, 3, 4, 5, 6, 7]);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('should clear the tree', () => {
|
|
130
|
+
binaryTree.add(1);
|
|
131
|
+
binaryTree.add(2);
|
|
132
|
+
|
|
133
|
+
expect(binaryTree.size).toBe(2);
|
|
134
|
+
|
|
135
|
+
binaryTree.clear();
|
|
136
|
+
|
|
137
|
+
expect(binaryTree.size).toBe(0);
|
|
138
|
+
expect(binaryTree.root).toBeNull();
|
|
4
139
|
});
|
|
5
140
|
});
|