예제 #1
0
TEST_F(PhyloTreeTest, PrefixCoding) {
    vector<PhyloTreeNode*> nodes1 = Fasta::readFastaFile("tests/aligned.fasta");
    PhyloTree t;
    t.setEvolutionModel(new Kimura(10.0));
    t.buildRandomTree(nodes1);

    double lh1 = t.logLikelihood();
    ASSERT_LT(lh1, 0.0);

    string prefixCoded = PhyloTreeNode::prefixRepresentation(t.getRoot());

    vector<PhyloTreeNode*> nodes2 = Fasta::readFastaFile("tests/aligned.fasta");
    PhyloTree t2 = PhyloTree::decodePrefixNotation(nodes2, prefixCoded, new Kimura(10.0));

    double lh2 = t.logLikelihood();

    ASSERT_DOUBLE_EQ(lh1, lh2);
}
예제 #2
0
TEST_F(PhyloTreeTest, RandomTree) {
    vector<PhyloTreeNode*> leaves;
    unsigned int n = 30;

    for (unsigned int i = 0; i < n; i++) {
        leaves.push_back(new PhyloTreeNode());
    }

    PhyloTree t;
    t.buildRandomTree(leaves);

    ASSERT_LT(log2(n), t.height()); // |tree| must be ≥ log₂(n)
    ASSERT_GE(n+1, t.height());     // |tree| must be ≤ n+1
    ASSERT_TRUE(t.getRoot()->isRoot()); // there should be a parentless root node

    // all leaves should now have a parent
    for (unsigned int i = 0; i < n; i++) {
        ASSERT_TRUE(!leaves.at(i)->isRoot());
    }
}