Example #1
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())
Example #2
0
    def test_big_trees(self):
        n = 14
        shape = 22
        labelling = 0
        tree = RankTree.unrank((shape, labelling), n)
        tsk_tree = tskit.Tree.unrank((shape, labelling), n)
        self.assertEqual(tree.rank(), tsk_tree.rank())

        n = 10
        shape = 95
        labelling = comb.num_labellings(shape, n) // 2
        tree = RankTree.unrank((shape, labelling), n)
        tsk_tree = tskit.Tree.unrank((shape, labelling), n)
        self.assertEqual(tree.rank(), tsk_tree.rank())
Example #3
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())
Example #4
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)