def test_3_2(self):
     tree = TreeNode()
     tree.build_from_heap([
         1, None, 2, None, None, None, 3, None, None, None, None, None,
         None, None, 4, None, None, None, None, None, None, None, None,
         None, None, None, None, None, None, None, 5
     ])
     self.assertEqual(path_sum(tree, 3), 2)
Example #2
0
 def test_long_4(self):
     tree = TreeNode()
     tree.build_from_heap([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
     self.assertEqual(max_depth(tree), 4)
Example #3
0
 def test_3_1(self):
     tree = TreeNode()
     tree.build_from_heap([3])
     self.assertEqual(max_depth(tree), 1)
Example #4
0
 def test_3920157_3(self):
     tree = TreeNode()
     tree.build_from_heap([3, 9, 20, None, None, 15, 7])
     self.assertEqual(max_depth(tree), 3)
 def test_two_false(self):
     tree1 = TreeNode()
     tree2 = TreeNode()
     tree1.build_from_heap([1])
     tree2.build_from_heap([2])
     self.assertFalse(same_tree(tree1, tree2))
 def test_two_paths_none(self):
     tree = TreeNode()
     tree.build_from_heap([6, 4, 8, 11, None, 13, 4, 7, 2,
                           None, None, None, None, 5, 1])
     self.assertEqual(path_sum(tree, 22), [])
 def test_blank_false(self):
     tree = TreeNode()
     tree.build_from_heap([])
     self.assertFalse(path_sum(tree, 14))
 def test_1_true(self):
     tree = TreeNode()
     tree.build_from_heap([1])
     self.assertTrue(path_sum(tree, 1))
 def test_small_2(self):
     input_tree = TreeNode()
     input_tree.build_from_heap([1, 2])
     test_tree = TreeNode()
     test_tree.build_from_heap([1, None, 2])
     self.assertEqual(invert_bin_tree(input_tree), test_tree)
 def test_single(self):
     input_tree = TreeNode()
     input_tree.build_from_heap([1])
     test_tree = TreeNode()
     test_tree.build_from_heap([1])
     self.assertEqual(invert_bin_tree(input_tree), test_tree)
 def test_4271369(self):
     input_tree = TreeNode()
     input_tree.build_from_heap([4, 2, 7, 1, 3, 6, 9])
     test_tree = TreeNode()
     test_tree.build_from_heap([4, 7, 2, 9, 6, 3, 1])
     self.assertEqual(invert_bin_tree(input_tree), test_tree)
 def test_short_5(self):
     tree = TreeNode()
     tree.build_from_heap([2, 3, 3])
     self.assertEqual(path_sum(tree, 5), [[2, 3], [2, 3]])
 def test_one_path_26(self):
     tree = TreeNode()
     tree.build_from_heap([5, 4, 8, 11, None, 13, 4, 7, 2,
                           None, None, None, None, 5, 1])
     self.assertEqual(path_sum(tree, 26), [[5, 8, 13]])
 def test_26_true(self):
     tree = TreeNode()
     tree.build_from_heap(
         [5, 4, 8, 11, None, 13, 4, 7, 2, None, None, None, None, None, 1])
     self.assertTrue(path_sum(tree, 26))
 def test_small_asym_false(self):
     tree1 = TreeNode()
     tree2 = TreeNode()
     tree1.build_from_heap([1, 2])
     tree2.build_from_heap([1, None, 2])
     self.assertFalse(same_tree(tree1, tree2))
 def test_1000_false(self):
     tree = TreeNode()
     tree.build_from_heap(
         [5, 4, 8, 11, None, 13, 4, 7, 2, None, None, None, None, None, 1])
     self.assertFalse(path_sum(tree, 1000))
 def test_blank_false(self):
     tree1 = TreeNode()
     tree2 = TreeNode()
     tree1.build_from_heap([1, 2, 3, 4])
     tree2.build_from_heap([])
     self.assertFalse(same_tree(tree1, tree2))
 def test_1_false(self):
     tree = TreeNode()
     tree.build_from_heap([1])
     self.assertFalse(path_sum(tree, 20))
 def test_one_true(self):
     tree1 = TreeNode()
     tree2 = TreeNode()
     tree1.build_from_heap([1])
     tree2.build_from_heap([1])
     self.assertTrue(same_tree(tree1, tree2))
Example #20
0
 def test_5_digits(self):
     built_tree = convert_array([-10, -3, 0, 5, 9])
     test_tree = TreeNode()
     test_tree.build_from_heap([0, -3, 9, -10, None, 5])
     self.assertEqual(built_tree, test_tree)
 def test_two_paths_22(self):
     tree = TreeNode()
     tree.build_from_heap([5, 4, 8, 11, None, 13, 4, 7, 2,
                           None, None, None, None, 5, 1])
     self.assertEqual(path_sum(tree, 22), [[5, 4, 11, 2], [5, 8, 4, 5]])