From 7c4ddc633cb39d03c4f661f9d149b7766cbbc9fb Mon Sep 17 00:00:00 2001 From: Ronald Ngounou <74538524+ronaldngounou@users.noreply.github.com> Date: Sun, 6 Oct 2024 13:38:43 -0400 Subject: [PATCH 1/3] test: Add unit tests --- .../binary_tree/binary_tree_path_sum.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/data_structures/binary_tree/binary_tree_path_sum.py b/data_structures/binary_tree/binary_tree_path_sum.py index a3fe9ca7a7e2..90205b593cc5 100644 --- a/data_structures/binary_tree/binary_tree_path_sum.py +++ b/data_structures/binary_tree/binary_tree_path_sum.py @@ -50,6 +50,26 @@ class BinaryTreePathSum: >>> tree.right.right = Node(10) >>> BinaryTreePathSum().path_sum(tree, 8) 2 + >>> BinaryTreePathSum().path_sum(None, 0) + 0 + >>> BinaryTreePathSum().path_sum(tree, 0) + 0 + + The second tree looks like this + + >>> tree2 = Node(0) + >>> tree2.left = Node(5) + >>> tree2.right = Node(5) + 0 + / \ + 5 5 + >>> BinaryTreePathSum().path_sum(tree, 5) + 2 + >>> BinaryTreePathSum().path_sum(tree, -1) + 0 + >>> BinaryTreePathSum().path_sum(tree, 0) + 1 + """ target: int From 1ee8199cd3c529bc72300552df95e54fffc5fa8d Mon Sep 17 00:00:00 2001 From: Ronald Ngounou <74538524+ronaldngounou@users.noreply.github.com> Date: Sun, 6 Oct 2024 13:43:10 -0400 Subject: [PATCH 2/3] test: Add successful tests in binaree_tree_path_sum --- .../binary_tree/binary_tree_path_sum.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/data_structures/binary_tree/binary_tree_path_sum.py b/data_structures/binary_tree/binary_tree_path_sum.py index 90205b593cc5..43df30f2e308 100644 --- a/data_structures/binary_tree/binary_tree_path_sum.py +++ b/data_structures/binary_tree/binary_tree_path_sum.py @@ -56,18 +56,19 @@ class BinaryTreePathSum: 0 The second tree looks like this - - >>> tree2 = Node(0) - >>> tree2.left = Node(5) - >>> tree2.right = Node(5) 0 / \ 5 5 - >>> BinaryTreePathSum().path_sum(tree, 5) + + >>> tree2 = Node(0) + >>> tree2.left = Node(5) + >>> tree2.right = Node(15) + + >>> BinaryTreePathSum().path_sum(tree2, 5) 2 - >>> BinaryTreePathSum().path_sum(tree, -1) + >>> BinaryTreePathSum().path_sum(tree2, -1) 0 - >>> BinaryTreePathSum().path_sum(tree, 0) + >>> BinaryTreePathSum().path_sum(tree2, 0) 1 """ From 8ea7d2a5857574253478a6eb6624df09a98d8471 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 6 Oct 2024 17:48:25 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- data_structures/binary_tree/binary_tree_path_sum.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data_structures/binary_tree/binary_tree_path_sum.py b/data_structures/binary_tree/binary_tree_path_sum.py index 43df30f2e308..d8e6f06123ee 100644 --- a/data_structures/binary_tree/binary_tree_path_sum.py +++ b/data_structures/binary_tree/binary_tree_path_sum.py @@ -54,7 +54,7 @@ class BinaryTreePathSum: 0 >>> BinaryTreePathSum().path_sum(tree, 0) 0 - + The second tree looks like this 0 / \ @@ -63,7 +63,7 @@ class BinaryTreePathSum: >>> tree2 = Node(0) >>> tree2.left = Node(5) >>> tree2.right = Node(15) - + >>> BinaryTreePathSum().path_sum(tree2, 5) 2 >>> BinaryTreePathSum().path_sum(tree2, -1)