Esempio n. 1
0
    def test(self, levels):
        node_descr = build_node_descr(levels)
        node_descr_expected = build_node_descr(levels, True)
        
        root = TreeMaker.from_node_description(node_descr)
        root_expected = TreeMaker.from_node_description(node_descr_expected)

        reverse_tree(root)
        self.assertEqual(root, root_expected)
Esempio n. 2
0
    def test_provided_example_2(self):
        """Can't use other methods as this has a duplicated node data in it"""        
        root0 = Node(26)
        root0.left = Node(10)
        root0.right = Node(3)
        root0.right.right = Node(3)
        root0.left.left = Node(4)
        root0.left.right = Node(6)
        root0.left.right.left = Node(30)
        node_des1 = [(10, 4, "L"), (10, 6, "R"), (4, 30, "R")]
        root1 = TreeMaker.from_node_description(node_des1)

        is_subtree_expected = False
        self.assertEqual(is_subtree(root0, root1), is_subtree_expected)
Esempio n. 3
0
 def test_trees(self, _, node_description, is_full_expected):
     root = TreeMaker.from_node_description(node_description)
     self.assertEqual(is_full_binary_tree(root), is_full_expected)
Esempio n. 4
0
 def test(self, _, node_des0, node_des1, is_subtree_expected):
     root0 = TreeMaker.from_node_description(node_des0)
     root1 = TreeMaker.from_node_description(node_des1)
     self.assertEqual(is_subtree(root0, root1), is_subtree_expected)
 def test(self, _, node_description, value0, value1, expected_lca_value):
     root = TreeMaker.from_node_description(node_description)
     self.assertEqual(lowest_common_ancestor(root, value0, value1), expected_lca_value)