Skip to content

Commit 31ced03

Browse files
authored
Modified test error messages and did some light docs cleanup. (#3536)
[no important files changed]
1 parent 375818c commit 31ced03

File tree

3 files changed

+128
-83
lines changed

3 files changed

+128
-83
lines changed

exercises/concept/chaitanas-colossal-coaster/.docs/hints.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# General
22

3-
Make sure you have a good understanding of how to create and update lists.
3+
- Make sure you have a good understanding of how to create and update lists.
4+
- The Python [documentation on `lists`][python lists] can be really helpful.
5+
- The Python [tutorial section on `lists`][more on lists] is also a good resource.
46

57
## 1. Add Me to the queue
68

7-
- You need to find the ticket type with an `if-else` statement.
8-
- You can `append()` the person to the queue based on the ticket type.
9+
- An `if-else` statement can help you find which ticket type you are dealing with.
10+
- You can then `append()` the person to the queue based on the ticket type.
911

1012
## 2. Where are my friends
1113

@@ -29,7 +31,9 @@ Make sure you have a good understanding of how to create and update lists.
2931

3032
## 7. Sort the Queue List
3133

32-
- Don't forget that You need to make a `copy()` of the queue to avoid mutating it and losing the original order.
34+
- Don't forget that You need to avoid mutating the queue and losing its original order.
3335
- Once you have a `copy()`, `sort()`-ing should be straightforward.
34-
- Order is alphabetical or _ascending_ sort.
36+
- We're looking for an _ascending_ sort, or _alphabetical from a-z_.
3537

38+
[python lists]: https://docs.python.org/3.11/library/stdtypes.html#list
39+
[more on lists]: https://docs.python.org/3.11/tutorial/datastructures.html#more-on-lists

exercises/concept/chaitanas-colossal-coaster/.meta/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"BethanyG"
55
],
66
"contributors": [
7+
"BethanyG",
78
"valentin-p",
89
"pranasziaukas"
910
],
Lines changed: 118 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import unittest
22
import pytest
3+
from copy import deepcopy
34

45
from list_methods import (
56
add_me_to_the_queue,
@@ -15,107 +16,146 @@
1516
class ListMethodsTest(unittest.TestCase):
1617
@pytest.mark.task(taskno=1)
1718
def test_add_me_to_the_queue(self):
18-
data = [
19-
((['Tony', 'Bruce'], ['RobotGuy', 'WW'], 0, 'HawkEye'), ['RobotGuy', 'WW', 'HawkEye']),
20-
((['Tony', 'Bruce'], ['RobotGuy', 'WW'], 1, 'RichieRich'), ['Tony', 'Bruce', 'RichieRich']),
21-
]
19+
test_data = [(['Tony', 'Bruce'], ['RobotGuy', 'WW'], 0, 'HawkEye'),
20+
(['Tony', 'Bruce'], ['RobotGuy', 'WW'], 1, 'RichieRich')]
21+
result_data = [['RobotGuy', 'WW', 'HawkEye'],
22+
['Tony', 'Bruce', 'RichieRich']]
23+
24+
for variant, (params, expected) in enumerate(zip(test_data, result_data), start=1):
25+
26+
# Deepcopy() is needed here because the task expects the input lists to be mutated.
27+
# That mutation wrecks havoc with the verification and error messaging.
28+
express_queue, normal_queue, ticket_type, person_name = deepcopy(params)
29+
30+
with self.subTest(f'variation #{variant}',
31+
express_queue=express_queue,
32+
normal_queue=normal_queue,
33+
ticket_type=ticket_type,
34+
person_name=person_name,
35+
expected=expected):
2236

23-
error_message = 'The person was not added to the queue correctly.'
24-
for variant, (params, result) in enumerate(data, start=1):
25-
with self.subTest(f'variation #{variant}', input=params, output=result):
26-
self.assertListEqual(add_me_to_the_queue(*params), result, msg=error_message)
37+
actual_result = add_me_to_the_queue(*params)
38+
error_message = (f'Called add_me_to_the_queue{express_queue, normal_queue, ticket_type, person_name}. '
39+
f'The function returned {actual_result}, but '
40+
f'The tests expected {expected} when adding '
41+
f'{person_name} to the queue.')
42+
43+
self.assertListEqual(actual_result, expected, msg=error_message)
2744

2845
@pytest.mark.task(taskno=2)
2946
def test_find_my_friend(self):
30-
data = [
31-
((['Natasha', 'Steve', 'Tchalla', 'Wanda', 'Rocket'], 'Natasha'), 0),
32-
((['Natasha', 'Steve', 'Tchalla', 'Wanda', 'Rocket'], 'Steve'), 1),
33-
((['Natasha', 'Steve', 'Tchalla', 'Wanda', 'Rocket'], 'Rocket'), 4),
34-
]
47+
test_data = [(['Natasha', 'Steve', 'Tchalla', 'Wanda', 'Rocket'], 'Natasha'),
48+
(['Natasha', 'Steve', 'Tchalla', 'Wanda', 'Rocket'], 'Steve'),
49+
(['Natasha', 'Steve', 'Tchalla', 'Wanda', 'Rocket'], 'Rocket')]
50+
result_data = (0,1,4)
51+
52+
for variant, (params, expected) in enumerate(zip(test_data, result_data), start=1):
53+
with self.subTest(f'variation #{variant}', params=params, expected=expected):
54+
actual_result = find_my_friend(*params)
55+
error_message = (f'Called find_my_friend{params}. '
56+
f'The function returned {actual_result}, but '
57+
f'The tests expected {expected} when looking for '
58+
f'{params[-1]} in the queue.')
3559

36-
error_message = 'The index of the friend to find is incorrect.'
37-
for variant, (params, result) in enumerate(data, start=1):
38-
with self.subTest(f'variation #{variant}', input=params, output=result):
39-
self.assertIs(find_my_friend(*params), result, msg=error_message)
60+
self.assertIs(actual_result, expected, msg=error_message)
4061

4162
@pytest.mark.task(taskno=3)
4263
def test_add_me_with_my_friends(self):
43-
data = [
44-
(
45-
(['Natasha', 'Steve', 'Tchalla', 'Wanda', 'Rocket'], 0, 'Bucky'),
46-
['Bucky', 'Natasha', 'Steve', 'Tchalla', 'Wanda', 'Rocket']
47-
),
48-
(
64+
test_data = [(['Natasha', 'Steve', 'Tchalla', 'Wanda', 'Rocket'], 0, 'Bucky'),
4965
(['Natasha', 'Steve', 'Tchalla', 'Wanda', 'Rocket'], 1, 'Bucky'),
50-
['Natasha', 'Bucky', 'Steve', 'Tchalla', 'Wanda', 'Rocket']
51-
),
52-
(
53-
(['Natasha', 'Steve', 'Tchalla', 'Wanda', 'Rocket'], 5, 'Bucky'),
54-
['Natasha', 'Steve', 'Tchalla', 'Wanda', 'Rocket', 'Bucky']
55-
),
56-
]
66+
(['Natasha', 'Steve', 'Tchalla', 'Wanda', 'Rocket'], 5, 'Bucky')]
67+
68+
result_data = [['Bucky', 'Natasha', 'Steve', 'Tchalla', 'Wanda', 'Rocket'],
69+
['Natasha', 'Bucky', 'Steve', 'Tchalla', 'Wanda', 'Rocket'],
70+
['Natasha', 'Steve', 'Tchalla', 'Wanda', 'Rocket', 'Bucky']]
71+
72+
for variant, (params, expected) in enumerate(zip(test_data, result_data), start=1):
73+
74+
# Deepcopy() is needed here because the task expects the input lists to be mutated.
75+
# That mutation wrecks havoc with the verification and error messaging.
76+
queue, index, person_name = deepcopy(params)
77+
78+
with self.subTest(f'variation #{variant}',
79+
queue=queue,
80+
index=index,
81+
person_name=person_name,
82+
expected=expected):
83+
84+
actual_result = add_me_with_my_friends(*params)
85+
error_message = (f'Called add_me_with_my_friends{queue, index, person_name}. '
86+
f'The function returned {actual_result}, but '
87+
f'The tests expected {expected} when adding '
88+
f'{person_name} to position {index} in the queue.')
5789

58-
error_message = 'The person was added to the wrong location in the queue or was not added at all.'
59-
for variant, (params, result) in enumerate(data, start=1):
60-
with self.subTest(f'variation #{variant}', input=params, output=result):
61-
self.assertListEqual(add_me_with_my_friends(*params), result, error_message)
90+
self.assertListEqual(actual_result, expected, msg=error_message)
6291

6392
@pytest.mark.task(taskno=4)
6493
def test_remove_the_mean_person(self):
65-
data = [
66-
(
67-
(['Natasha', 'Steve', 'Ultron', 'Wanda', 'Rocket'], 'Ultron'),
68-
['Natasha', 'Steve', 'Wanda', 'Rocket']
69-
),
70-
(
71-
(['Natasha', 'Steve', 'Wanda', 'Rocket', 'Ultron'], 'Ultron'),
72-
['Natasha', 'Steve', 'Wanda', 'Rocket']
73-
),
74-
(
75-
(['Ultron', 'Natasha', 'Steve', 'Wanda', 'Rocket'], 'Ultron'),
76-
['Natasha', 'Steve', 'Wanda', 'Rocket']
77-
),
94+
test_data = [(['Natasha', 'Steve', 'Ultron', 'Wanda', 'Rocket'], 'Ultron'),
95+
(['Natasha', 'Steve', 'Wanda', 'Rocket', 'Ultron'], 'Ultron'),
96+
(['Ultron', 'Natasha', 'Steve', 'Wanda', 'Rocket'], 'Ultron'),
97+
7898
]
99+
result_data = [['Natasha', 'Steve', 'Wanda', 'Rocket'],
100+
['Natasha', 'Steve', 'Wanda', 'Rocket'],
101+
['Natasha', 'Steve', 'Wanda', 'Rocket']]
102+
103+
for variant, (params, expected) in enumerate(zip(test_data, result_data), start=1):
104+
105+
# Deepcopy() is needed here because the task expects the input lists to be mutated.
106+
# That mutation wrecks havoc with the verification and error messaging.
107+
queue, person_name = deepcopy(params)
79108

80-
error_message = 'The mean person was not removed properly.'
81-
for variant, (params, result) in enumerate(data, start=1):
82-
with self.subTest(f'variation #{variant}', input=params, output=result):
83-
self.assertListEqual(remove_the_mean_person(*params), result, msg=error_message)
109+
with self.subTest(f'variation #{variant}',
110+
queue=queue,
111+
person_name=person_name,
112+
expected=expected):
113+
114+
actual_result = remove_the_mean_person(*params)
115+
error_message = (f'Called remove_the_mean_person{queue, person_name}. '
116+
f'The function returned {actual_result}, but '
117+
f'The tests expected {expected} when removing '
118+
f'{person_name} from the queue.')
119+
120+
self.assertListEqual(actual_result, expected, msg=error_message)
84121

85122
@pytest.mark.task(taskno=5)
86123
def test_how_many_namefellows(self):
87-
data = [
88-
((['Natasha', 'Steve', 'Ultron', 'Natasha', 'Rocket'], 'Bucky'), 0),
89-
((['Natasha', 'Steve', 'Ultron', 'Rocket'], 'Natasha'), 1),
90-
((['Natasha', 'Steve', 'Ultron', 'Natasha', 'Rocket'], 'Natasha'), 2),
91-
]
124+
test_data = [(['Natasha', 'Steve', 'Ultron', 'Natasha', 'Rocket'], 'Bucky'),
125+
(['Natasha', 'Steve', 'Ultron', 'Rocket'], 'Natasha'),
126+
(['Natasha', 'Steve', 'Ultron', 'Natasha', 'Rocket'], 'Natasha')]
92127

93-
error_message = 'The namefellow count is incorrect.'
94-
for variant, (params, result) in enumerate(data, start=1):
95-
with self.subTest(f'variation #{variant}', input=params, output=result):
96-
self.assertIs(how_many_namefellows(*params), result, msg=error_message)
128+
result_data = (0,1,2)
129+
130+
for variant, (params, expected) in enumerate(zip(test_data, result_data), start=1):
131+
with self.subTest(f'variation #{variant}', params=params, expected=expected):
132+
actual_result = how_many_namefellows(*params)
133+
134+
error_message = (f'Called how_many_namefellows{params}. '
135+
f'The function returned {actual_result}, but '
136+
f'The tests expected {expected} when counting '
137+
f'namefellows in the queue for {params[-1]}.')
138+
139+
self.assertIs(actual_result, expected, msg=error_message)
97140

98141
@pytest.mark.task(taskno=6)
99142
def test_remove_the_last_person(self):
100-
data = [
101-
(['Natasha', 'Steve', 'Ultron', 'Natasha', 'Rocket'], 'Rocket'),
102-
]
143+
test_data = ['Natasha', 'Steve', 'Ultron', 'Natasha', 'Rocket']
144+
actual_result = remove_the_last_person(test_data)
145+
expected = 'Rocket'
146+
error_message = (f'Called remove_the_last_person({test_data}).'
147+
f'The function returned {actual_result}, but the tests '
148+
f'expected {expected} as the person who was removed.')
103149

104-
error_message = 'The last person was not removed properly.'
105-
for variant, (params, result) in enumerate(data, start=1):
106-
with self.subTest(f'variation #{variant}', input=params, output=result):
107-
self.assertIs(remove_the_last_person(params), result, msg=error_message)
150+
self.assertIs(actual_result, expected, msg=error_message)
108151

109152
@pytest.mark.task(taskno=7)
110153
def test_sorted_names(self):
111-
data = [
112-
(
113-
['Steve', 'Ultron', 'Natasha', 'Rocket'],
114-
['Natasha', 'Rocket', 'Steve', 'Ultron']
115-
),
116-
]
117-
118-
error_message = 'The queue was not properly sorted.'
119-
for variant, (params, result) in enumerate(data, start=1):
120-
with self.subTest(f'variation #{variant}', input=params, output=result):
121-
self.assertListEqual(sorted_names(params), result, msg=error_message)
154+
test_data = ['Steve', 'Ultron', 'Natasha', 'Rocket']
155+
expected = ['Natasha', 'Rocket', 'Steve', 'Ultron']
156+
actual_result = sorted_names(test_data)
157+
error_message = (f'Called sorted_names({test_data}).'
158+
f'The function returned {actual_result}, but the tests '
159+
f'expected {expected}.')
160+
161+
self.assertListEqual(actual_result, expected, msg=error_message)

0 commit comments

Comments
 (0)