- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinaryTreeTest.py
More file actions
Latest commit
33 lines (23 loc) · 791 Bytes
/
Copy pathbinaryTreeTest.py
File metadata and controls
33 lines (23 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
frombinaryTreeimportTreeNode
frombinaryTreeimportis_bst
importunittest
classBinaryTreeValidationTest(unittest.TestCase):
deftest_validBinaryTreeIsValid(self):
root=TreeNode(5)
root.left=TreeNode(3)
root.right=TreeNode(7)
root.left.left=TreeNode(1)
root.left.right=TreeNode(4)
root.right.left=TreeNode(6)
self.assertTrue(is_bst(root))
deftest_emptyTree(self):
self.assertTrue(is_bst(None))
deftest_invalidTreeIsNotBST(self):
root=TreeNode(20)
root.left=TreeNode(10)
root.right=TreeNode(30)
root.right.left=TreeNode(5)
root.right.right=TreeNode(40)
self.assertFalse(is_bst(root))
if__name__=='__main__':
unittest.main()