Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this user
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
jansonsa
/
210CT-Coursework
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Projects
0
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Projects
Security
Insights
Files
8022eca
.vscode
__pycache__
BST.py
BSTExceptions.py
BST_unit_test.py
Graph.py
GraphExceptions.py
Graph_unit_test.py
words.txt
Breadcrumbs
210CT-Coursework
/
BST_unit_test.py
Blame
Blame
Latest commit
History
History
118 lines (98 loc) · 3.9 KB
Breadcrumbs
210CT-Coursework
/
BST_unit_test.py
Top
File metadata and controls
Code
Blame
118 lines (98 loc) · 3.9 KB
Raw
import BST import unittest class Tests(unittest.TestCase): def test_insert_into_empty(self): # Inserting into empty tree, should return a tree self.assertNotEqual(BST.tree_insert(None,"A"), None) def test_insert_duplicates(self): tree = BST.tree_insert(None,"A") BST.tree_insert(tree, "A") node = BST.tree_find(tree, "A") self.assertEqual(node.frequency, 2) def test_goes_to_left(self): tree = BST.tree_insert(None, "B") BST.tree_insert(tree, "A") node = BST.tree_find(tree,"A") self.assertEqual(tree.left, node) def test_goes_to_right(self): tree = BST.tree_insert(None, "A") BST.tree_insert(tree, "B") node = BST.tree_find(tree,"B") self.assertEqual(tree.right, node) def test_delete_root(self): tree = BST.tree_insert(None, "A") empty = BST.tree_delete(tree, "A") self.assertEqual(empty, None) def test_delete_one_child_right_and_is_root(self): tree = BST.tree_insert(None, "A") BST.tree_insert(tree, "B") tree = BST.tree_delete(tree, "A") pre_order1 = BST.pre_order(tree) equalTree = BST.tree_insert(None, "B") pre_order2 = BST.pre_order(equalTree) self.assertEqual(pre_order1,pre_order2) def test_delete_one_child_left_and_is_root(self): tree = BST.tree_insert(None, "B") BST.tree_insert(tree, "A") tree = BST.tree_delete(tree, "B") pre_order1 = BST.pre_order(tree) equalTree = BST.tree_insert(None, "A") pre_order2 = BST.pre_order(equalTree) self.assertEqual(pre_order1,pre_order2) def test_delete_two_children_and_is_root(self): tree = BST.tree_insert(None, "B") BST.tree_insert(tree, "A") BST.tree_insert(tree, "C") tree = BST.tree_delete(tree, "B") pre_order1 = BST.pre_order(tree) equalTree = BST.tree_insert(None, "A") BST.tree_insert(equalTree, "C") pre_order2 = BST.pre_order(equalTree) self.assertEqual(pre_order1,pre_order2) def test_delete_one_child_right(self): tree = BST.tree_insert(None, "A") BST.tree_insert(tree, "B") BST.tree_insert(tree, "C") tree = BST.tree_delete(tree, "B") pre_order1 = BST.pre_order(tree) equalTree = BST.tree_insert(None, "A") BST.tree_insert(equalTree,"C") pre_order2 = BST.pre_order(equalTree) self.assertEqual(pre_order1,pre_order2) def test_delete_one_child_left(self): tree = BST.tree_insert(None, "A") BST.tree_insert(tree, "C") BST.tree_insert(tree, "B") tree = BST.tree_delete(tree, "C") pre_order1 = BST.pre_order(tree) equalTree = BST.tree_insert(None, "A") BST.tree_insert(equalTree,"B") pre_order2 = BST.pre_order(equalTree) self.assertEqual(pre_order1,pre_order2) def test_delete_two_children(self): tree = BST.tree_insert(None, "A") BST.tree_insert(tree, "C") BST.tree_insert(tree, "B") BST.tree_insert(tree, "D") tree = BST.tree_delete(tree, "C") pre_order1 = BST.pre_order(tree) equalTree = BST.tree_insert(None, "A") BST.tree_insert(equalTree,"B") BST.tree_insert(equalTree,"D") pre_order2 = BST.pre_order(equalTree) self.assertEqual(pre_order1,pre_order2) def test_find_when_not_in_tree(self): tree = BST.tree_insert(None, "A") node = BST.tree_find(tree, "B") self.assertEqual(node, None) def test_find(self): tree = BST.tree_insert(None, "A") BST.tree_insert(tree, "C") BST.tree_insert(tree, "B") BST.tree_insert(tree, "D") BST.tree_insert(tree, "B") node = BST.tree_find(tree, "B") self.assertEqual(node.value, "B") self.assertEqual(node.frequency, 2) if __name__ == "__main__": unittest.main()
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
You can’t perform that action at this time.