Skip to content

Commit

Permalink
Creates two unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenshank committed Apr 27, 2017
1 parent 41cde70 commit 5c96934
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## phylotree.js
# phylotree.js

A JavaScript interactive viewer of [phylogenetic trees](https://en.wikipedia.org/wiki/Phylogenetic_tree), written as an extension of the [D3](http://d3js.org) [hierarchy layout](https://github.com/mbostock/d3/wiki/Hierarchy-Layout). It generates high quality SVG vector graphics, allows a great degree of customizability (CSS or JavaScript callbacks), and comes with a lot of *built-in* convenicence features.

Expand All @@ -25,8 +25,12 @@ Key features

1. A [gallery of examples](http://bl.ocks.org/spond) is a good place to learn different ways that phylotree.js can be used to display and annotate the trees.
2. A [full-featured web application](http://veg.github.io/phylotree.js/index.html) based on phylotree.js, implemented in [index.html](index.html).
3. phylotree.js is also used by the 2015 revision of the [datamonkey.org server](http://test.datamonkey.org) for molecular sequence analyis.
3. phylotree.js is also used by the 2015 revision of the [datamonkey.org server](http://test.datamonkey.org) for molecular sequence analysis.

## Dependencies

See [bower.json](bower.json) for dependencies.

## Tests

Run tests using `mocha`.
51 changes: 51 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
});
});

});

0 comments on commit 5c96934

Please sign in to comment.