def test_false(self): s = BinaryTree() s.gen_tree([1, 2, 4, 1]) t = BinaryTree() t.gen_tree([1, 3, 2, 3]) res = Solution() assert res.isSameTree2(s.root, t.root) is False
def test_false(self): s = BinaryTree() s.gen_tree([1, 2, 3, 4, 5]) t = BinaryTree() t.gen_tree([2, 5, 4]) res = Solution() assert res.isSubtree_2(s.root, t.root) is False
def test_is_same(self, nums, expect): s = BinaryTree() s.gen_tree(nums) e_s = BinaryTree() e_s.gen_tree(expect) res = Solution() new_node = res.invertTree(s.root) assert self.is_same(new_node, e_s.root)
def test(self, nums, expect): s = BinaryTree() s.gen_tree(nums) res = Solution() assert res.isBalanced(s.root) is expect
def test_equal(self, t1, t2, expect): t1_tree = BinaryTree() t1_tree.gen_tree(t1) t2_tree = BinaryTree() t2_tree.gen_tree(t2) ex_tree = BinaryTree() ex_tree.gen_tree(expect) res = Solution() actual = res.mergeTrees(t1_tree.root, t2_tree.root) assert self.is_same(actual, ex_tree.root)
def test_true(self): s = BinaryTree() s.gen_tree([1, 2, 4, 1]) t = s res = Solution() assert res.isSameTree(s.root, t.root) is True
def test_false(self): s = BinaryTree() s.gen_tree([3, 4, 2, 7, 3, 1, 8]) res = Solution() assert res.hasPathSum(s.root, 99) is False
def test_true(self): s = BinaryTree() s.gen_tree([5, 4, 8, 11, None, 13, 4, 7, 2, None, None, None, None, None, 1]) res = Solution() assert res.hasPathSum(s.root, 22) is True
def test(self): s = BinaryTree() s.gen_tree([3, 9, 20, None, None, 15, 7]) res = Solution() assert res.sumOfLeftLeaves(root=s.root) is 24
def test(self, nums, expect): s = BinaryTree() s.gen_tree(nums) res = Solution() assert res.maxDepth(s.root) is expect
def test_false(self): s = BinaryTree() s.gen_tree([1, 2, 2, None, 3, None, 3]) res = Solution() assert res.isSymmetric(s.root) is False
def test_true(self): s = BinaryTree() s.gen_tree([1, 2, 2, 3, 4, 4, 3, 1, 2, 3, 4, 4, 3, 2, 1]) res = Solution() assert res.isSymmetric2(s.root) is True