コード例 #1
0
ファイル: test_tree.py プロジェクト: JavaDevVictoria/lingpy
class TestTree(object):

    def setup(self):

        self.tree = Tree('((a,b),(c,d),e)')

        assert sorted(self.tree.taxa) == list('abcde')
    
    def test_getDistanceToRoot(self):

        
        assert self.tree.getDistanceToRoot('a') == 2

    def test_get_LCA(self):

        assert str(self.tree.get_LCA('a','b')) == '(a,b);'

    def test_get_distance(self):

        treeA = Tree('((a:1,b:1):1,(c:1,d:1):1)')
        treeB = Tree('((a:1,c:1):1,(b:1,d:1):1)')

        assert treeA.get_distance(treeB,'grf') == 1.0
        assert treeA.get_distance(treeB,'rf') == 1.0
        assert treeA.get_distance(treeB,'symmetric') == 2
        assert treeA.get_distance(treeB,'grf') == 1.0
コード例 #2
0
ファイル: test_tree.py プロジェクト: vermillionbee/lingpy
class TestTree(TestCase):
    def setUp(self):
        self.tree = Tree('((a,b),(c,d),e)')
        assert sorted(self.tree.taxa) == list('abcde')

    def test_getDistanceToRoot(self):
        assert self.tree.getDistanceToRoot('a') == 2

    def test_get_LCA(self):
        assert str(self.tree.get_LCA('a', 'b')) == '(a,b);'

    def test_get_distance(self):
        tree_a = Tree('((a:1,b:1):1,(c:1,d:1):1)')
        tree_b = Tree('((a:1,c:1):1,(b:1,d:1):1)')

        assert tree_a.get_distance(tree_b, 'grf') == 1.0
        assert tree_a.get_distance(tree_b, 'rf') == 1.0
        assert tree_a.get_distance(tree_b, 'symmetric') == 2
        assert tree_a.get_distance(tree_b, 'grf') == 1.0

    def test_get_distance_unknown(self):
        """test failure with unknown distance"""
        with self.assertRaises(ValueError):
            Tree('(a,b)').get_distance(Tree('(a,b)'), 'xxx')

    def test_init_from_file(self):
        tree = Tree(test_data('phybo.tre'))
        assert len(tree.taxa) == 40, "should have a taxa attribute and 40 tips"

    def test_init_from_list(self):
        tree = Tree(['Simon', 'Mattis', 'Robert'])
        assert len(tree.taxa) == 3, "should have a taxa attribute and 3 tips"
コード例 #3
0
class TestTree(TestCase):
    def setUp(self):
        self.tree = Tree('((a,b),(c,d),e)')
        assert sorted(self.tree.taxa) == list('abcde')

    def test_getDistanceToRoot(self):
        assert self.tree.getDistanceToRoot('a') == 2

    def test_get_LCA(self):
        assert str(self.tree.get_LCA('a', 'b')) == '(a,b);'

    def test_get_distance(self):
        treeA = Tree('((a:1,b:1):1,(c:1,d:1):1)')
        treeB = Tree('((a:1,c:1):1,(b:1,d:1):1)')

        assert treeA.get_distance(treeB, 'grf') == 1.0
        assert treeA.get_distance(treeB, 'rf') == 1.0
        assert treeA.get_distance(treeB, 'symmetric') == 2
        assert treeA.get_distance(treeB, 'grf') == 1.0