-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_unit_1c_hw.py
166 lines (134 loc) · 4.91 KB
/
test_unit_1c_hw.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
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
'''
DO NOT EDIT THIS FILE UNLESS TOLD TO DO SO BY YOUR INSTRUCTOR
'''
import random
from unit_1c_hw import *
def test_assign_1():
assert assign_1() == 5, "X must be assigned to the integer 5"
def test_assign_2():
assert assign_2() == "Hello NC State", "X must be assigned the string 'Hello NC State'"
def test_list_1():
l = list_1()
assert len(l) == 3, "List must only have 3 elements"
assert l[0] == 3, "First index must have value 3"
assert l[1] == 4, "Second index must have value 4"
assert l[2] == 5, "Third Index must have value 5"
def test_list_slice_1():
l = list_slice_1()
assert len(l) == 3, "List must only have 3 elements"
assert l[0] == 4, "First index must have value 4"
assert l[1] == 7, "Second index must have value 7"
assert l[2] == 9, "Third Index must have value 9"
def test_list_slice_2():
l = list_slice_2()
assert len(l) == 3, "List must only have 3 elements"
assert l[0] == 4, "First index must have value 4"
assert l[1] == 3, "Second index must have value 3"
assert l[2] == 7, "Third Index must have value 7"
def test_list_slice_3():
l = list_slice_3()
assert l == [11, 10, 45, 40, 90, 100], "Slice was not correct"
def test_list_slice_4():
l = list_slice_4()
assert l == [0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 0, 0, 0, 0, 0, 0], f"List was not sliced correctly, your list: {l}"
def test_list_slice_5():
given = random.sample(range(0, 99), 15)
l = list_slice_5(given)
assert len(l) == 6, "Slice was not corrects"
for index, value in enumerate(l):
assert value == given[index]
def test_multi_dim_lists_1():
l = multi_dim_lists_1()
assert l == [9, 9], "Was not 3rd list"
def test_multi_dim_lists_2():
a = multi_dim_lists_2()
assert a == 10, "Grabbed the wrong value"
def test_multi_dim_list_3():
dim = [
[
random.randint(0, 99),
random.randint(0, 99),
random.randint(0, 99),
random.randint(0, 99),
],
[
random.randint(0, 99),
random.randint(0, 99),
random.randint(0, 99),
random.randint(0, 99),
],
[
random.randint(0, 99),
random.randint(0, 99),
random.randint(0, 99),
random.randint(0, 99),
],
[
random.randint(0, 99),
random.randint(0, 99),
random.randint(0, 99),
random.randint(0, 99),
],
]
value = multi_dim_lists_3(dim)
test = dim.pop() # If student uses this method they should be asked to find a 1-2 line solution
test = dim.pop()
test = dim.pop()
temp = test.pop()
temp = test.pop()
assert value == temp, "Grabbed wrong value"
def test_multi_dim_lists_4():
d = multi_dim_lists_4()
i = 0
assert len(d) == 3
assert len(d[0]) == 5
assert len(d[1]) == 4
assert len(d[2]) == 4
for l in d:
for value in l:
assert i == value
i += 1
def test_dict_1():
d = dict_1()
assert len(d) == 3, "Dictionary must have 3 keys"
assert d[0] == "A", "Key 0 must have value A"
assert d[1] == "B", "Key 1 must have value B"
assert d[2] == "C", "Key 2 must have value C"
def test_dict_2():
noise = dict_2()
assert noise == "meow", f"Noise was not the sounds of a cat: '{noise}'" # Note to instructor check this test manually as well, make sure student did not just pass in the string "meow"
def test_dict_3():
milk_tax = dict_3()
assert milk_tax == 0.25, f"Value was not the milk tax: '{milk_tax}" # Note to instructor, check this test manually as well, make sure student did not pass in the value 0.25
def test_dict_4():
value = random.randint(1, 100)
inventory = {
"butter" : {
"value" : 2.50,
"tax" : .10,
},
"milk" : {
"value" : 3.00,
"tax" : 0.25
},
"cheese" : {
"value" : value,
"tax" : .70
}
}
assert dict_4(inventory) == value, "Did not grab value of cheese"
def test_list_dict():
colors = list_dict()
assert "warm_colors" in colors, "warm_colors was not in the color dict "
assert "cool_colors" in colors, "cool_colors was not in the color dict"
warm_colors = colors["warm_colors"]
cool_colors = colors["cool_colors"]
assert len(colors) == 2, "You may have more than warm_colors and cool_colors as dict keys"
assert len(warm_colors) == 3, "You must have 3 colors in the warm_colors list"
assert len(cool_colors) == 3, "You must have 3 colors in teh cool_colors list"
assert "yellow" in warm_colors, "yellow was not in warm colors"
assert "orange" in warm_colors, "orange was not in warm colors"
assert "red" in warm_colors, "red was not in warm colors"
assert "green" in cool_colors, "green was not in cool colors"
assert "blue" in cool_colors, "blue was not in cool colors"
assert "purple" in cool_colors, "purple was not in cool colors"