mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-03-04 14:48:45 +00:00
Added bst validate challenge.
This commit is contained in:
33
graphs_trees/bst_validate/test_bst_validate.py
Normal file
33
graphs_trees/bst_validate/test_bst_validate.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from nose.tools import assert_equal
|
||||
|
||||
|
||||
class TestBstValidate(object):
|
||||
|
||||
def test_bst_validate(self):
|
||||
node = Node(5)
|
||||
insert(node, 8)
|
||||
insert(node, 5)
|
||||
insert(node, 6)
|
||||
insert(node, 4)
|
||||
insert(node, 7)
|
||||
assert_equal(validate_bst(node), True)
|
||||
|
||||
root = Node(5)
|
||||
left = Node(5)
|
||||
right = Node(8)
|
||||
invalid = Node(20)
|
||||
root.left = left
|
||||
root.right = right
|
||||
root.left.right = invalid
|
||||
assert_equal(validate_bst(root), False)
|
||||
|
||||
print('Success: test_bst_validate')
|
||||
|
||||
|
||||
def main():
|
||||
test = TestBstValidate()
|
||||
test.test_bst_validate()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user