-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinaryTree_test.py
More file actions
67 lines (49 loc) · 2 KB
/
binaryTree_test.py
File metadata and controls
67 lines (49 loc) · 2 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import unittest
from binaryTree import BinTree
class BinTreeTestMethods(unittest.TestCase):
def test_should_find_the_first_element(self):
# Given a binary tree with example data
exampleData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
bt = BinTree(exampleData)
# When searched for the first element
result = bt.contains(exampleData[0])
# Then it should return True
self.assertTrue(result)
def test_should_find_the_last_element(self):
# Given a binary tree with example data
exampleData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
size = len(exampleData) - 1
bt = BinTree(exampleData)
# When searched for the last element
result = bt.contains(exampleData[size])
# Then it should return True
self.assertTrue(result)
def test_should_find_the_mid_element(self):
# Given a binary tree with example data
exampleData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
max_index = len(exampleData) - 1
min_index = 0
mid_index = (max_index + min_index) // 2
bt = BinTree(exampleData)
# When searched for the mid element
result = bt.contains(exampleData[mid_index])
# Then it should return True
self.assertTrue(result)
def test_should_return_false_if_no_element_is_existing(self):
# Given a binary tree with empty example data
exampleData = []
bt = BinTree(exampleData)
# When searched for a element in empty data list
result = bt.contains(0)
# Then it should return False
self.assertFalse(result)
def test_should_return_false_if_element_is_not_existing(self):
# Given a binary tree with example data
exampleData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
bt = BinTree(exampleData)
# When searched for a element which not exists
result = bt.contains(11)
# Then it should return False
self.assertFalse(result)
if __name__ == '__main__':
unittest.main()