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())
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)
def test_shape_unrank(self): for n in range(6): for rank, tree in enumerate(RankTree.all_unlabelled_trees(n)): t = RankTree.shape_unrank(rank, n) self.assertTrue(tree.shape_equal(t)) for n in range(2, 9): for shape_rank, tree in enumerate(RankTree.all_unlabelled_trees(n)): tsk_tree = tskit.Tree.unrank((shape_rank, 0), n) self.assertEqual(shape_rank, tree.shape_rank()) shape_rank, _ = tsk_tree.rank() self.assertEqual(shape_rank, tree.shape_rank())
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())