forked from veg/phylotree.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
51 lines (44 loc) · 1.37 KB
/
test.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var path = require("path"),
jsdom = require("jsdom"),
should = require("should");
describe('Phylotree', function(){
before(function(done){
jsdom.env({
file: path.join(__dirname, "index.html"),
features: {
FetchExternalResources: ["script"],
ProcessExternalResources: ["script"]
},
done: function(err, window){
global.window = window;
global.tree = window.tree;
done();
}
});
});
it('Create an instance of a tree.', function(){
window.should.have.properties('tree');
});
it('Equal scaling factor when invoking spacing functions.', function(){
function is_leaf(node){ return node.name && node.name != 'root';}
var original_spacing = tree.spacing_y(),
original_ys = {},
scaling_factor = 0,
scaled_coordinates;
tree.get_nodes().forEach(function(node) {
if(is_leaf(node)) original_ys[node.name] = node.y
});
tree.spacing_y(original_spacing/2).update();
tree.get_nodes().forEach(node => {
if(is_leaf(node) && !scaling_factor){
scaling_factor = original_ys[node.name]/node.y;
scaling_factor.should.not.be.approximately(1, 1e-1);
}
if(is_leaf(node)){
rescaled_y = scaling_factor*node.y;
original_y = original_ys[node.name];
rescaled_y.should.be.approximately(original_y, 1e-8);
}
});
});
});