-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainRunner.py
109 lines (80 loc) · 4.75 KB
/
MainRunner.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# **********************************************************************************************************************
# NAME: Timothy P. McCrary
# CLASS: CS 2302
# LAB 5 OPTION A
# INSTRUCTOR: Diego Aguirre
# TA: Manoj Pravaka Saha
# DATE: 11/25/2018
# PURPOSE: To understand and use a min heap.
# **********************************************************************************************************************
import time
import MinHeap
from MinHeapSort import heap_sort
def main():
# __________TEST 1__________________________________________________________________________________________________
print('\n__________TEST 1__________: Uses file with 1,000 numbers.')
# Creates list from file. This is the test we will be using.
input_list = MinHeap.file_to_list("Numbers.txt")
print('List before converting to min heap:\n', input_list)
start_time = time.time()
# Builds min heap from list then prints list.
min_heap = MinHeap.build_min_heap(input_list)
print('After converting to min heap:\n', min_heap.heap_array)
# Sorts min heap using heap sort then prints list once sorted.
heap_sort(min_heap.heap_array)
print('After using heap sort:\n', min_heap.heap_array)
print("\nRunning time after building min heap then sorting it = %s seconds" % (time.time() - start_time))
# __________TEST 2__________________________________________________________________________________________________
print('\n__________TEST 2__________: Uses hard coded list.')
# Creates list from file. This is the test we will be using.
input_list = [12, 4567, 2, 4, 1, 5678, 34, 43, 6, 7]
print('List before converting to min heap:\n', input_list)
start_time = time.time()
# Builds min heap from list then prints list.
min_heap = MinHeap.build_min_heap(input_list)
print('After converting to min heap:\n', min_heap.heap_array)
# Sorts min heap using heap sort then prints list once sorted.
heap_sort(min_heap.heap_array)
print('After using heap sort:\n', min_heap.heap_array)
print("\nRunning time after building min heap then sorting it = %s seconds" % (time.time() - start_time))
# __________TEST 3__________________________________________________________________________________________________
print('\n__________TEST 3__________: Uses empty file.')
# Creates list from file. This is the test we will be using.
input_list = MinHeap.file_to_list("Empty.txt")
print('List before converting to min heap:\n', input_list)
start_time = time.time()
# Builds min heap from list then prints list.
min_heap = MinHeap.build_min_heap(input_list)
print('After converting to min heap:\n', min_heap.heap_array)
# Sorts min heap using heap sort then prints list once sorted.
heap_sort(min_heap.heap_array)
print('After using heap sort:\n', min_heap.heap_array)
print("\nRunning time after building min heap then sorting it = %s seconds" % (time.time() - start_time))
# __________TEST 4__________________________________________________________________________________________________
print('\n__________TEST 4__________: Uses file not formatted.')
# Creates list from file. This is the test we will be using.
input_list = MinHeap.file_to_list("Not Formatted.txt")
print('List before converting to min heap:\n', input_list)
start_time = time.time()
# Builds min heap from list then prints list.
min_heap = MinHeap.build_min_heap(input_list)
print('After converting to min heap:\n', min_heap.heap_array)
# Sorts min heap using heap sort then prints list once sorted.
heap_sort(min_heap.heap_array)
print('After using heap sort:\n', min_heap.heap_array)
print("\nRunning time after building min heap then sorting it = %s seconds" % (time.time() - start_time))
# __________TEST 5__________________________________________________________________________________________________
print('\n__________TEST 5__________: Uses file that doesn\'t exist.')
# Creates list from file. This is the test we will be using.
input_list = MinHeap.file_to_list("Does Not Exist.txt")
print('List before converting to min heap:\n', input_list)
start_time = time.time()
# Builds min heap from list then prints list.
min_heap = MinHeap.build_min_heap(input_list)
print('After converting to min heap:\n', min_heap.heap_array)
# Sorts min heap using heap sort then prints list once sorted.
heap_sort(min_heap.heap_array)
print('After using heap sort:\n', min_heap.heap_array)
print("\nRunning time after building min heap then sorting it = %s seconds" % (time.time() - start_time))
if __name__ == '__main__':
main()