Beispiel #1
0
 def test_all_labellings_roundtrip(self):
     n = 5
     rank_tree = RankTree.unrank((comb.num_shapes(n) - 1, 0), n)
     tsk_tree = rank_tree.to_tsk_tree()
     rank_tree_labellings = RankTree.all_labellings(rank_tree)
     tsk_tree_labellings = tskit.all_tree_labellings(tsk_tree)
     for rank_t, tsk_t in zip(rank_tree_labellings, tsk_tree_labellings):
         self.assertEqual(rank_t, RankTree.from_tsk_tree(tsk_t))
Beispiel #2
0
 def test_num_labellings(self):
     for n in range(2, 8):
         for tree in RankTree.all_unlabelled_trees(n):
             tree = tree.label_unrank(0)
             tree2 = tree.to_tsk_tree()
             n_labellings = sum(1 for _ in RankTree.all_labellings(tree))
             assert n_labellings == RankTree.from_tsk_tree(
                 tree2).num_labellings()
Beispiel #3
0
 def test_label_unrank(self):
     for n in range(7):
         for shape_rank, tree in enumerate(RankTree.all_unlabelled_trees(n)):
             for label_rank, labelled_tree in enumerate(
                 RankTree.all_labellings(tree)
             ):
                 rank = (shape_rank, label_rank)
                 unranked = tree.label_unrank(label_rank)
                 self.assertEqual(labelled_tree.rank(), rank)
                 self.assertEqual(unranked.rank(), rank)
Beispiel #4
0
    def test_unrank(self):
        for n in range(6):
            for shape_rank, t in enumerate(RankTree.all_unlabelled_trees(n)):
                for label_rank, labelled_tree in enumerate(RankTree.all_labellings(t)):
                    unranked = RankTree.unrank((shape_rank, label_rank), n)
                    self.assertTrue(labelled_tree == unranked)

        # The number of labelled trees gets very big quickly
        for n in range(6, 10):
            for shape_rank in range(comb.num_shapes(n)):
                rank = (shape_rank, 0)
                unranked = RankTree.unrank(rank, n)
                self.assertTrue(rank, unranked.rank())

                rank = (shape_rank, comb.num_labellings(shape_rank, n) - 1)
                unranked = RankTree.unrank(rank, n)
                self.assertTrue(rank, unranked.rank())
Beispiel #5
0
 def test_label_rank(self):
     for n in range(7):
         for tree in RankTree.all_unlabelled_trees(n):
             for rank, labelled_tree in enumerate(RankTree.all_labellings(tree)):
                 self.assertEqual(labelled_tree.label_rank(), rank)