forked from Firkraag/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
min_gap_tree_test.py
executable file
·92 lines (90 loc) · 3.27 KB
/
min_gap_tree_test.py
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
#!/usr/bin/env ipython
import unittest
from min_gap_tree import min_gap_tree, min_gap_node
class TestMinGapTree(unittest.TestCase):
def test_insert_one(self):
T = min_gap_tree([50])
self.wrap(T, 50, float("Inf"))
def test_insert_two(self):
T = min_gap_tree([50, 38])
self.wrap(T, 50, 12)
self.wrap(T, 38, 12)
def test_insert_three(self):
T = min_gap_tree([50, 38, 31])
self.wrap(T, 38, 7)
self.wrap(T, 31, 7)
self.wrap(T, 50, float("Inf"))
def test_insert_four(self):
T = min_gap_tree([50, 38, 31, 12])
self.wrap(T, 38, 7)
self.wrap(T, 31, 7)
self.wrap(T, 50, float("Inf"))
self.wrap(T, 12, 19)
def test_insert_five(self):
T = min_gap_tree([50, 38, 31, 12, 19])
self.wrap(T, 38, 7)
self.wrap(T, 19, 7)
self.wrap(T, 50, float("Inf"))
self.wrap(T, 12, 7)
self.wrap(T, 31, 7)
def test_insert_six(self):
T = min_gap_tree([50, 38, 31, 12, 19, 9])
self.wrap(T, 38, 3)
self.wrap(T, 19, 3)
self.wrap(T, 50, float("Inf"))
self.wrap(T, 12, 3)
self.wrap(T, 31, 7)
self.wrap(T, 9, 3)
def test_delete_one(self):
T = min_gap_tree([50, 38, 31, 12, 19, 9])
T.delete(T.iterative_tree_search(9))
self.wrap(T, 38, 7)
self.wrap(T, 19, 7)
self.wrap(T, 50, float("Inf"))
self.wrap(T, 12, 7)
self.wrap(T, 31, 7)
def test_delete_two(self):
T = min_gap_tree([50, 38, 31, 12, 19, 9])
T.delete(T.iterative_tree_search(9))
T.delete(T.iterative_tree_search(12))
self.wrap(T, 38, 7)
self.wrap(T, 19, 7)
self.wrap(T, 50, float("Inf"))
self.wrap(T, 31, 7)
def test_delete_three(self):
T = min_gap_tree([50, 38, 31, 12, 19, 9])
T.delete(T.iterative_tree_search(9))
T.delete(T.iterative_tree_search(12))
T.delete(T.iterative_tree_search(19))
self.wrap(T, 38, 7)
self.wrap(T, 31, 7)
self.wrap(T, 50, float("Inf"))
def test_delete_four(self):
T = min_gap_tree([50, 38, 31, 12, 19, 9])
T.delete(T.iterative_tree_search(9))
T.delete(T.iterative_tree_search(12))
T.delete(T.iterative_tree_search(19))
T.delete(T.iterative_tree_search(31))
self.wrap(T, 38, 12)
self.wrap(T, 50, float("Inf"))
def test_delete_five(self):
T = min_gap_tree([50, 38, 31, 12, 19, 9])
T.delete(T.iterative_tree_search(9))
T.delete(T.iterative_tree_search(12))
T.delete(T.iterative_tree_search(19))
T.delete(T.iterative_tree_search(31))
T.delete(T.iterative_tree_search(38))
self.wrap(T, 50, float("Inf"))
def test_delete_six(self):
T = min_gap_tree([50, 38, 31, 12, 19, 9])
T.delete(T.iterative_tree_search(9))
T.delete(T.iterative_tree_search(12))
T.delete(T.iterative_tree_search(19))
T.delete(T.iterative_tree_search(31))
T.delete(T.iterative_tree_search(38))
T.delete(T.iterative_tree_search(50))
self.assertEquals(T.root, T.nil)
def wrap(self, tree, node, min_gap):
self.assertEquals(tree.iterative_tree_search(node).min_gap, min_gap)
if __name__ == '__main__':
unittest.main()