예제 #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)
예제 #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)
예제 #3
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)
예제 #4
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)
예제 #5
0
 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)
예제 #6
0
    def test(self, _, node_idents, min_path_len, expected_node_idents):
        root = TreeMaker.from_node_idents(node_idents)
        remove_nodes(root, min_path_len)

        root_expected = TreeMaker.from_node_idents(expected_node_idents)
        self.assertEqual(root, root_expected)
예제 #7
0
 def test_trees(self, _, node_description, expected_bottom_view):
     root, num_nodes = TreeMaker.tree_and_node_count_from_node_description(
         node_description)
     self.assertEqual(bottom_view(root, num_nodes), expected_bottom_view)
예제 #8
0
    def test_all_removed(self, _, node_idents, min_path_len):
        root = TreeMaker.from_node_idents(node_idents)
        root_produced = remove_nodes(root, min_path_len)

        self.assertEqual(root_produced, None)