示例#1
0
    def test_is_canonical(self):
        for n in range(7):
            for tree in RankTree.all_labelled_trees(n):
                assert tree.is_canonical()

        shape_not_canonical = RankTree(children=[
            RankTree(children=[], label=0),
            RankTree(children=[
                RankTree(children=[
                    RankTree(children=[], label=1),
                    RankTree(children=[], label=2),
                ]),
                RankTree(children=[], label=3),
            ]),
        ])
        assert not shape_not_canonical.is_canonical()

        labels_not_canonical = RankTree(children=[
            RankTree(children=[], label=0),
            RankTree(children=[
                RankTree(children=[
                    RankTree(children=[], label=2),
                    RankTree(children=[], label=3),
                ]),
                RankTree(children=[
                    RankTree(children=[], label=1),
                    RankTree(children=[], label=4),
                ]),
            ]),
        ])
        assert not labels_not_canonical.is_canonical()
示例#2
0
    def test_is_canonical(self):
        for n in range(7):
            for tree in RankTree.all_labelled_trees(n):
                self.assertTrue(tree.is_canonical())

        shape_not_canonical = RankTree(children=[
            RankTree(children=[], label=0),
            RankTree(children=[
                RankTree(children=[
                    RankTree(children=[], label=1),
                    RankTree(children=[], label=2),
                ]),
                RankTree(children=[], label=3),
            ]),
        ])
        self.assertFalse(shape_not_canonical.is_canonical())

        labels_not_canonical = RankTree(children=[
            RankTree(children=[], label=0),
            RankTree(children=[
                RankTree(children=[
                    RankTree(children=[], label=2),
                    RankTree(children=[], label=3),
                ]),
                RankTree(children=[
                    RankTree(children=[], label=1),
                    RankTree(children=[], label=4),
                ]),
            ]),
        ])
        self.assertFalse(labels_not_canonical.is_canonical())