-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
76 lines (66 loc) · 2.65 KB
/
test.js
File metadata and controls
76 lines (66 loc) · 2.65 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
68
69
70
71
72
73
74
75
76
'use strict';
var Tree = require('./lib/tree/Tree.js');
var Node = require('./lib/tree/TreeNode.js');
var Acorn = require('./lib/Acorn.js');
function TreeWithNoConflictsShouldCompletelyFlatten() {
var root = new Node('root');
var a = new Node('a');
var b = new Node('b');
var c = new Node('c');
var d = new Node('d');
root.addChild(a);
root.addChild(b);
b.addChild(c);
c.addChild(d);
var tree = new Tree(root);
console.log('\nRunning test TreeWithNoConflictsShouldCompletelyFlatten');
tree.flatten();
//Asserts:
if (a.children.length != 0) console.log('Test Failed - a has children.');
if (b.children.length != 0) console.log('Test Failed - b has children.');
if (c.children.length != 0) console.log('Test Failed - c has children.');
if (d.children.length != 0) console.log('Test Failed - d has children.');
if (root.children.length != 4) console.log('Test Failed - root does not have 4 children.');
tree.print();
console.log('***Test Complete***\n');
}
function TreeWithConflictsShouldFlattenCorrectly() {
var root = new Node('root');
var a = new Node('a');
var b = new Node('b');
var c = new Node('c');
var d = new Node('d');
var d2 = new Node('d');
root.addChild(a);
root.addChild(b);
root.addChild(d2);
b.addChild(c);
c.addChild(d);
var tree = new Tree(root);
console.log('\nRunning test TreeWithConflictsShouldFlattenCorrectly');
tree.flatten();
//Asserts:
if (a.children.length != 0) console.log('Test Failed - a has children.');
if (b.children.length != 0) console.log('Test Failed - b has children.');
if (c.children.length != 1) console.log('Test Failed - c should have one child (d).');
if (d.children.length != 0) console.log('Test Failed - d has children.');
if (root.children.length != 4) console.log('Test Failed - root does not have 4 children.');
tree.print();
console.log('***Test Complete***\n');
}
function AcornShouldGrowTreeFromDirectoryAndFlattenCorrectly() {
console.log('\nRunning test AcornShouldGrowTreeFromDirectoryAndFlattenCorrectly');
var acorn = new Acorn('C:/testData/flattenTest');
acorn.grow().then((tree) => {
console.log('tree (unflattened) = ' + tree);
tree.print();
tree.flatten();
console.log('tree (flattened) = ' + tree);
tree.print();
if (tree.root.children.length != 4) console.log("Test Failed - root does not have 4 children.");
console.log('***Test Complete***\n');
});
}
TreeWithNoConflictsShouldCompletelyFlatten();
TreeWithConflictsShouldFlattenCorrectly();
AcornShouldGrowTreeFromDirectoryAndFlattenCorrectly();