-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestLinkSort.py
More file actions
242 lines (178 loc) · 6.3 KB
/
testLinkSort.py
File metadata and controls
242 lines (178 loc) · 6.3 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
"""
Bri Miskovitz
Computer Science I
Homework 8
testLinkSort tests SlList for various different cases
and sets up the main function so the user can create more
test files. Test functions and main creates list objects using
the slList class
"""
import slList as module
def readFile(fileName):
"""
readFile
readFile : file -> object
pre-conditions : filename exists as text file
post-conditions : list is built as a slList object
:param fileName: a file
:return: a list
"""
lst = module.createList()
for line in fileName:
module.append(lst, line)
return lst
def main():
"""
pre-conditions:
1. fileName is a text file integer values, one per line
2.
:return:
"""
fileName = input("Enter a filename: ")
lst = readFile(fileName)
print("The unsorted list:", module.toString(lst))
lst = module.linkSort(lst)
print("The sorted list:", module.toString(lst))
def empty():
"""
empty creates a list object where the list is
empty, tests linkSort from slLink.py, and prints the
list before and after it's sorted as a string
pre-conditions : slLink.py is accessible
post-conditions : slLink.py is accessible
:return: list before and after sorted as strings
"""
LST = []
lst = module.createList()
for ele in range(len(LST)):
module.append(lst, LST[ele])
print("Tests empty list:")
print("unsorted: ", module.toString(lst))
module.linkSort(lst)
print("sorted:", module.toString(lst))
def singleList():
"""
singleList creates a list object where there's only
one element, tests linkSort from slLink.py, and prints the
list before and after it's sorted as a string
pre-conditions : slLink.py is accessible
post-conditions : slLink.py is accessible
:return: list before and after sorted as strings
"""
LST = [5]
lst = module.createList()
for ele in range(len(LST)):
module.append(lst, LST[ele])
print("Tests a list that contains only one element:")
print("unsorted: ", module.toString(lst))
module.linkSort(lst)
print("sorted: ", module.toString(lst))
def opposite():
"""
opposite creates a list object where the elements
are in opposite order, tests linkSort from
slLink.py, and prints the list before and
after it's sorted as a string
pre-conditions : slLink.py is accessible
post-conditions : slLink.py is accessible
:return: list before and after sorted as strings
"""
LST = [15, 13, 12, 11, 9, 7, 3, 1, 0]
lst = module.createList()
for ele in range(len(LST)):
module.append(lst, LST[ele])
print("Tests a list that's in opposite order:")
print("unsorted: ", module.toString(lst))
module.linkSort(lst)
print("sorted:", module.toString(lst))
def orderedEven():
"""
orderedEven creates a ordered list object contains an even number
of elements, tests linkSort from slLink.py, and prints the
list before and after it's sorted as a string
pre-conditions : slLink.py is accessible
post-conditions : slLink.py is accessible
:return: list before and after sorted
"""
LST = [6, 8, 9, 11, 12, 14, 18, 31]
lst = module.createList()
for ele in range(len(LST)):
module.append(lst, LST[ele])
print("Tests an ordered list with an even number of elements:")
print("unsorted: ", module.toString(lst))
module.linkSort(lst)
print("sorted: ", module.toString(lst))
def orderedOdd():
"""
orderedOdd creates a ordered list object contains an odd number
of elements, tests linkSort from slLink.py, and prints the
list before and after it's sorted as a string
pre-conditions : slLink.py is accessible
post-conditions : slLink.py is accessible
:return: list before and after sorted
"""
LST = [5, 6, 8, 9, 11, 12, 14, 18, 31]
lst = module.createList()
for ele in range(len(LST)):
module.append(lst, LST[ele])
print("Tests an ordered list with an odd number of elements:")
print("unsorted: ", module.toString(lst))
module.linkSort(lst)
print("sorted: ", module.toString(lst))
def sameList():
"""
wack creates a list object contains equal integers,
tests linkSort from slLink.py, and prints the
list before and after it's sorted as a string
pre-conditions : slLink.py is accessible
post-conditions : slLink.py is accessible
:return: list before and after sorted
"""
LST = [5, 5, 5, 5, 5, 5]
lst = module.createList()
for ele in range(len(LST)):
module.append(lst, LST[ele])
print("Tests a list that contains equal integers:")
print("unsorted: ", module.toString(lst))
module.linkSort(lst)
print("sorted:", module.toString(lst))
def wack():
"""
wack creates a unordered list object, tests linkSort
from slLink.py, and prints the list before and after
it's sorted as a string
pre-conditions : slLink.py is accessible
post-conditions : slLink.py is accessible
:return: list before and after sorted
"""
LST = [3, 9, 4, 1, 5, 7, 2, 10, 4, 6]
lst = module.createList()
for ele in range(len(LST)):
module.append(lst, LST[ele])
print("Tests an unordered list:")
print("unsorted: ", module.toString(lst))
# print(module.findMinFrom(lst.head))
# print(module.findMinFrom(lst.head.next))
module.linkSort(lst)
print("sorted: ", module.toString(lst))
def TestorMain():
"""
TestorMain allows user to choose if it wants to run test
cases or call main and make its own
pre-condition: test functions and main function exist
post-conditions : slLink.py is accessible
:return: list before and after sorted
"""
print("Would you like to run the test functions already created or run your own?")
val = int(input("Enter 1 for the first option and 2 for the latter: "))
if val == 2:
main()
else:
empty()
singleList()
opposite()
orderedEven()
orderedOdd()
sameList()
wack()
TestorMain()