@@ -116,38 +116,55 @@ def insert(self, label: int) -> RedBlackTree:
116
116
117
117
def _insert_repair (self ) -> None :
118
118
"""Repair the coloring from inserting into a tree."""
119
+ coverageList .append (1 )
119
120
if self .parent is None :
121
+ coverageList .append (2 )
120
122
# This node is the root, so it just needs to be black
121
123
self .color = 0
122
124
elif color (self .parent ) == 0 :
125
+ coverageList .append (3 )
123
126
# If the parent is black, then it just needs to be red
124
127
self .color = 1
125
128
else :
129
+ coverageList .append (4 )
126
130
uncle = self .parent .sibling
127
131
if color (uncle ) == 0 :
132
+ coverageList .append (5 )
128
133
if self .is_left () and self .parent .is_right ():
134
+ coverageList .append (6 )
129
135
self .parent .rotate_right ()
130
136
if self .right :
137
+ coverageList .append (7 )
131
138
self .right ._insert_repair ()
132
139
elif self .is_right () and self .parent .is_left ():
140
+ coverageList .append (8 )
133
141
self .parent .rotate_left ()
134
142
if self .left :
143
+ coverageList .append (9 )
135
144
self .left ._insert_repair ()
136
145
elif self .is_left ():
146
+ coverageList .append (10 )
137
147
if self .grandparent :
148
+ coverageList .append (11 )
138
149
self .grandparent .rotate_right ()
139
150
self .parent .color = 0
140
151
if self .parent .right :
152
+ coverageList .append (12 )
141
153
self .parent .right .color = 1
142
154
else :
155
+ coverageList .append (13 )
143
156
if self .grandparent :
157
+ coverageList .append (14 )
144
158
self .grandparent .rotate_left ()
145
159
self .parent .color = 0
146
160
if self .parent .left :
161
+ coverageList .append (15 )
147
162
self .parent .left .color = 1
148
163
else :
164
+ coverageList .append (16 )
149
165
self .parent .color = 0
150
166
if uncle and self .grandparent :
167
+ coverageList .append (17 )
151
168
uncle .color = 0
152
169
self .grandparent .color = 1
153
170
self .grandparent ._insert_repair ()
@@ -719,6 +736,9 @@ def pytests() -> None:
719
736
720
737
721
738
def main () -> None :
739
+ global coverageList
740
+ coverageList = []
741
+ coverageList .append (0 ) #this ID is excluded from the percentage calculation at the end main()
722
742
"""
723
743
>>> pytests()
724
744
"""
@@ -731,8 +751,12 @@ def main() -> None:
731
751
print_results ("Tree traversal" , test_tree_chaining ())
732
752
print ("Testing tree balancing..." )
733
753
print ("This should only be a few seconds." )
734
- test_insertion_speed ()
754
+ # test_insertion_speed()
735
755
print ("Done!" )
756
+ coverageList = list (dict .fromkeys (coverageList ))
757
+ coverageList .sort ()
758
+ print ("Covered IDs:" , coverageList )
759
+ print ("Coverage percentage: " , (len (coverageList )- 1 )/ 17 )
736
760
737
761
738
762
if __name__ == "__main__" :
0 commit comments