-
Notifications
You must be signed in to change notification settings - Fork 0
/
testSet.py
62 lines (57 loc) · 1.76 KB
/
testSet.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
"""
File: testSet.py
Author: Harry Pinkerton, James Lawson, Laurie Jones
Project: 5
A tester program for set implementations.
"""
from arraySet import ArraySet
from linkedSet import LinkedSet
from arraySortedSet import ArraySortedSet
def test(setType):
"""Expects a set type as an argument and runs some tests
on objects of that type."""
lyst = [2013, 61, 1973, 1973]
print("The list of items added is:", lyst)
s1 = setType(lyst)
print("Length, expect 3:", len(s1))
print("Expect the set's string:", s1)
print("2013 in s1, expect True:", 2013 in s1)
print("2012 in s1, expect False:", 2012 in s1)
print("Expect the items on separate lines:")
for item in s1:
print(item)
s1.clear()
print("Clearing, expect {}:", s1)
s1.add(25)
s1.remove(25)
print("Add and remove 25, expect {}:", s1)
s1 = setType(lyst)
s2 = setType(s1)
print (s1)
print (s2)
print("Clone with ==, expect True:", s1 == s2)
print("Clone with is, expect False:", s1 is s2)
s1.clear()
print("Removed each, expect {}:", s1)
print("Expect crash with KeyError:")
s1.remove(99)
def testSetSpecific(setType):
"""Expects a set type as an argument and runs some tests
on objects of that type with the |, &, and - operators."""
s1 = setType([2013, 61, 1973, 1973])
s2 = setType([61, 44, 2013])
print("s1:", s1, "s2:", s2)
print("s1 | s2:", s1 | s2)
print("s1 & s2:", s1 & s2)
print("s1 - s2:", s1 - s2)
print("s2 - s1:", s2 - s1)
def main():
"""Starting point for the application."""
# test(ArraySet)
# test(LinkedSet)
test(ArraySortedSet)
# testSetSpecific(ArraySet)
## testSetSpecific(LinkedSet)
## testSetSpecific(ArraySortedSet)
if __name__ == "__main__":
main()