-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtree.spec.js
35 lines (31 loc) · 1.18 KB
/
tree.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import {test, expect, describe} from 'vitest';
import { TreeNode } from "#common/structures/TreeNode";
const mockTree = [1, 2, 3];
const mockTree2 = [1,null, 2];
const mockTree3 = [3,9,20,null,null,15,7];
test('测试树', ()=>{
const node = TreeNode.parse(mockTree);
const result = TreeNode.toArray(node)
const node2 = TreeNode.parse(mockTree2);
const result2 = TreeNode.toArray(node2);
expect(result2).toEqual(mockTree2);
expect(result).toEqual(mockTree);
})
test('测试树 toArray特殊值', ()=>{
expect(TreeNode.toArray(null)).toEqual([]);
})
test('测试树 parse 特殊值',() => {
expect(TreeNode.parse([])).toBeNull();
})
test('测试树 parse mockTree',() => {
expect(TreeNode.parse(mockTree)).toEqual(new TreeNode(1, new TreeNode(2), new TreeNode(3)));
})
test('测试树 pase mockTree2', () => {
expect(TreeNode.parse(mockTree2)).toEqual(new TreeNode(1, null, new TreeNode(2)));
})
test('测试树 pase mockTree3', () => {
expect(TreeNode.parse(mockTree3)).toEqual(new TreeNode(3, new TreeNode(9, null), new TreeNode(20, new TreeNode(15, null) ,new TreeNode(7))));
})
test('测试树 pase mockTree3', () => {
expect(TreeNode.parse([0])).toEqual(new TreeNode());
})