forked from akshitagit/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
67 lines (56 loc) · 1.49 KB
/
test.js
File metadata and controls
67 lines (56 loc) · 1.49 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const T = require('./index');
const Node = T.Node;
const Tree = T.Tree;
describe('Node', () => {
test('Node is a constructor', () => {
expect(typeof Node.prototype.constructor).toEqual('function');
});
test('Node has a data and children properties', () => {
const n = new Node('a');
expect(n.data).toEqual('a');
expect(n.children.length).toEqual(0);
});
test('Node can add children', () => {
const n = new Node('a');
n.add('b');
expect(n.children.length).toEqual(1);
expect(n.children[0].children).toEqual([]);
});
test('Node can remove children', () => {
const n = new Node('a');
n.add('b');
expect(n.children.length).toEqual(1);
n.remove('b');
expect(n.children.length).toEqual(0);
});
});
describe.skip('Tree', () => {
test('starts empty', () => {
const t = new Tree();
expect(t.root).toEqual(null);
});
test('Can traverse bf', () => {
const letters = [];
const t = new Tree();
t.root = new Node('a');
t.root.add('b');
t.root.add('c');
t.root.children[0].add('d');
t.traverseBF(node => {
letters.push(node.data);
});
expect(letters).toEqual(['a', 'b', 'c', 'd']);
});
test('Can traverse DF', () => {
const letters = [];
const t = new Tree();
t.root = new Node('a');
t.root.add('b');
t.root.add('d');
t.root.children[0].add('c');
t.traverseDF(node => {
letters.push(node.data);
});
expect(letters).toEqual(['a', 'b', 'c', 'd']);
});
});