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_unranking_is_canonical(self):
     for n in range(7):
         for shape_rank in range(comb.num_shapes(n)):
             for label_rank in range(comb.num_labellings(shape_rank, n)):
                 t = RankTree.shape_unrank(shape_rank, n)
                 self.assertTrue(t.is_canonical())
                 t = t.label_unrank(label_rank)
                 self.assertTrue(t.is_canonical())
                 t = tskit.Tree.unrank((shape_rank, label_rank), n)
                 self.assertTrue(RankTree.from_tsk_tree(t).is_canonical())
Beispiel #3
0
 def test_unrank_rank_round_trip(self):
     for n in range(6):  # Can do more but gets slow pretty quickly after 6
         for shape_rank in range(comb.num_shapes(n)):
             tree = RankTree.shape_unrank(shape_rank, n)
             tree = tree.label_unrank(0)
             self.assertEqual(tree.shape_rank(), shape_rank)
             for label_rank in range(tree.num_labellings()):
                 tree = tree.label_unrank(label_rank)
                 self.assertEqual(tree.label_rank(), label_rank)
                 tsk_tree = tree.label_unrank(label_rank).to_tsk_tree()
                 _, tsk_label_rank = tsk_tree.rank()
                 self.assertEqual(tsk_label_rank, label_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_unrank_errors(self):
        self.verify_unrank_errors((-1, 0), 1)
        self.verify_unrank_errors((0, -1), 1)
        self.verify_unrank_errors((-1, 0), 2)
        self.verify_unrank_errors((0, -1), 2)
        self.verify_unrank_errors((-1, 0), 10)
        self.verify_unrank_errors((0, -1), 10)

        self.verify_unrank_errors((0, 1), 1)
        self.verify_unrank_errors((1, 0), 2)
        self.verify_unrank_errors((0, 1), 2)
        self.verify_unrank_errors((2, 0), 3)
        self.verify_unrank_errors((0, 1), 3)
        self.verify_unrank_errors((1, 3), 3)

        invalid_shape = (comb.num_shapes(10), 0)
        self.verify_unrank_errors(invalid_shape, 10)
        invalid_labelling = (0, comb.num_labellings(0, 10))
        self.verify_unrank_errors(invalid_labelling, 10)
Beispiel #6
0
 def test_symmetrical_trees(self):
     for n in range(2, 18, 2):
         last_rank = comb.num_shapes(n) - 1
         t = RankTree.shape_unrank(last_rank, n)
         self.assertTrue(t.is_symmetrical())
Beispiel #7
0
 def test_num_shapes(self):
     for i in range(11):
         all_trees = RankTree.all_unlabelled_trees(i)
         self.assertEqual(len(list(all_trees)), comb.num_shapes(i))
Beispiel #8
0
 def test_num_shapes(self):
     for i in range(11):
         all_trees = RankTree.all_unlabelled_trees(i)
         assert len(list(all_trees)) == comb.num_shapes(i)