|
13 | 13 |
|
14 | 14 |
|
15 | 15 | class ListMethodsTest(unittest.TestCase): |
16 | | - |
17 | 16 | @pytest.mark.task(taskno=1) |
18 | | - def test_add_me_to_the_queue_set_normal_queue(self): |
19 | | - params = (["Tony", "Bruce"], ["RobotGuy", "WW"], 0, "HawkEye") |
20 | | - result = ["RobotGuy", "WW", "HawkEye"] |
21 | | - |
22 | | - self.assertListEqual( |
23 | | - add_me_to_the_queue(*params), result, |
24 | | - msg="The person was not added to the queue correctly" |
25 | | - ) |
| 17 | + 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 | + ] |
26 | 22 |
|
27 | | - @pytest.mark.task(taskno=1) |
28 | | - def test_add_me_to_the_queue_express_queue(self): |
29 | | - params = (["Tony", "Bruce"], ["RobotGuy", "WW"], 1, "RichieRich") |
30 | | - result = ["Tony", "Bruce", "RichieRich"] |
31 | | - |
32 | | - self.assertListEqual( |
33 | | - add_me_to_the_queue(*params), result, |
34 | | - msg="The person was not added to the queue correctly" |
35 | | - ) |
| 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) |
36 | 27 |
|
37 | 28 | @pytest.mark.task(taskno=2) |
38 | | - def test_find_my_friend_start_of_queue(self): |
39 | | - params = (["Natasha", "Steve", "Tchalla", "Wanda", "Rocket"], "Natasha") |
40 | | - result = 0 |
41 | | - |
42 | | - self.assertEqual( |
43 | | - find_my_friend(*params), result, |
44 | | - msg="The index of the friend to find is incorrect." |
45 | | - ) |
46 | | - |
47 | | - @pytest.mark.task(taskno=2) |
48 | | - def test_find_my_friend_middle_of_queue(self): |
49 | | - params = (["Natasha", "Steve", "Tchalla", "Wanda", "Rocket"], "Steve") |
50 | | - result = 1 |
51 | | - |
52 | | - self.assertIs( |
53 | | - find_my_friend(*params), result, |
54 | | - msg="The index of the friend to find is incorrect" |
55 | | - ) |
56 | | - |
57 | | - @pytest.mark.task(taskno=2) |
58 | | - def test_find_my_friend_end_of_queue(self): |
59 | | - params = (["Natasha", "Steve", "Tchalla", "Wanda", "Rocket"], "Rocket") |
60 | | - result = 4 |
61 | | - |
62 | | - self.assertIs( |
63 | | - find_my_friend(*params), result, |
64 | | - msg="The index of the friend to find is incorrect" |
65 | | - ) |
66 | | - |
67 | | - @pytest.mark.task(taskno=3) |
68 | | - def test_add_me_with_my_friends_start_of_queue(self): |
69 | | - params = (["Natasha", "Steve", "Tchalla", "Wanda", "Rocket"], 0, "Bucky") |
70 | | - result = ["Bucky", "Natasha", "Steve", "Tchalla", "Wanda", "Rocket"] |
71 | | - |
72 | | - self.assertListEqual( |
73 | | - add_me_with_my_friends(*params), result, |
74 | | - msg="The person was added to the wrong location in the queue or was not added at all", |
75 | | - ) |
76 | | - |
77 | | - @pytest.mark.task(taskno=3) |
78 | | - def test_add_me_with_my_friends_middle_of_queue(self): |
79 | | - params = (["Natasha", "Steve", "Tchalla", "Wanda", "Rocket"], 1, "Bucky") |
80 | | - result = ["Natasha", "Bucky", "Steve", "Tchalla", "Wanda", "Rocket"] |
81 | | - |
82 | | - self.assertListEqual( |
83 | | - add_me_with_my_friends(*params), result, |
84 | | - msg="The person was added to the wrong location in the queue or was not added at all" |
85 | | - ) |
| 29 | + 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 | + ] |
| 35 | + |
| 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) |
86 | 40 |
|
87 | 41 | @pytest.mark.task(taskno=3) |
88 | | - def test_add_me_with_my_friends_end_of_queue(self): |
89 | | - params = (["Natasha", "Steve", "Tchalla", "Wanda", "Rocket"], 5, "Bucky") |
90 | | - result = ["Natasha", "Steve", "Tchalla", "Wanda", "Rocket", "Bucky"] |
91 | | - |
92 | | - self.assertListEqual( |
93 | | - add_me_with_my_friends(*params), result, |
94 | | - msg="The person was added to the wrong location in the queue or was not added at all" |
95 | | - ) |
96 | | - |
97 | | - @pytest.mark.task(taskno=4) |
98 | | - def test_remove_the_mean_person_middle_of_queue(self): |
99 | | - params = (["Natasha", "Steve", "Ultron", "Wanda", "Rocket"], "Ultron") |
100 | | - result = ["Natasha", "Steve", "Wanda", "Rocket"] |
101 | | - |
102 | | - self.assertListEqual( |
103 | | - remove_the_mean_person(*params), result, |
104 | | - msg="The mean person was not removed properly" |
105 | | - ) |
| 42 | + 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 | + ( |
| 49 | + (['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 | + ] |
| 57 | + |
| 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) |
106 | 62 |
|
107 | 63 | @pytest.mark.task(taskno=4) |
108 | | - def test_remove_the_mean_person_end_of_queue(self): |
109 | | - params = (["Natasha", "Steve", "Wanda", "Rocket", "Ultron"], "Ultron") |
110 | | - result = ["Natasha", "Steve", "Wanda", "Rocket"] |
111 | | - |
112 | | - self.assertListEqual( |
113 | | - remove_the_mean_person(*params), result, |
114 | | - msg="The mean person was not removed properly" |
115 | | - ) |
116 | | - |
117 | | - @pytest.mark.task(taskno=4) |
118 | | - def test_remove_the_mean_person_start_of_queue(self): |
119 | | - params = (["Ultron", "Natasha", "Steve", "Wanda", "Rocket"], "Ultron") |
120 | | - result = ["Natasha", "Steve", "Wanda", "Rocket"] |
121 | | - |
122 | | - self.assertListEqual( |
123 | | - remove_the_mean_person(*params), result, |
124 | | - msg="The mean person was not removed properly" |
125 | | - ) |
| 64 | + 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 | + ), |
| 78 | + ] |
| 79 | + |
| 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) |
126 | 84 |
|
127 | 85 | @pytest.mark.task(taskno=5) |
128 | | - def test_how_many_namefellows_person_not_in_queue(self): |
129 | | - params = (["Natasha", "Steve", "Ultron", "Natasha", "Rocket"], "Bucky") |
130 | | - result = 0 |
131 | | - |
132 | | - self.assertIs( |
133 | | - how_many_namefellows(*params), result, |
134 | | - msg="The namefellow count is incorrect" |
135 | | - ) |
136 | | - |
137 | | - @pytest.mark.task(taskno=5) |
138 | | - def test_how_many_namefellows_only_one(self): |
139 | | - params = (["Natasha", "Steve", "Ultron", "Rocket"], "Natasha") |
140 | | - result = 1 |
141 | | - |
142 | | - self.assertIs( |
143 | | - how_many_namefellows(*params), result, |
144 | | - msg="The namefellow count is incorrect" |
145 | | - ) |
146 | | - |
147 | | - @pytest.mark.task(taskno=5) |
148 | | - def test_how_many_namefellows_more_than_one(self): |
149 | | - params = (["Natasha", "Steve", "Ultron", "Natasha", "Rocket"], "Natasha") |
150 | | - result = 2 |
151 | | - |
152 | | - self.assertIs( |
153 | | - how_many_namefellows(*params), result, |
154 | | - msg="The namefellow count is incorrect" |
155 | | - ) |
| 86 | + 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 | + ] |
| 92 | + |
| 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) |
156 | 97 |
|
157 | 98 | @pytest.mark.task(taskno=6) |
158 | 99 | def test_remove_the_last_person(self): |
159 | | - params = ["Natasha", "Steve", "Ultron", "Natasha", "Rocket"] |
160 | | - result = "Rocket" |
| 100 | + data = [ |
| 101 | + (['Natasha', 'Steve', 'Ultron', 'Natasha', 'Rocket'], 'Rocket'), |
| 102 | + ] |
161 | 103 |
|
162 | | - self.assertIs( |
163 | | - remove_the_last_person(params), result, |
164 | | - msg="The last person was not removed properly" |
165 | | - ) |
| 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) |
166 | 108 |
|
167 | 109 | @pytest.mark.task(taskno=7) |
168 | 110 | def test_sorted_names(self): |
169 | | - params = ["Steve", "Ultron", "Natasha", "Rocket"] |
170 | | - result = ["Natasha", "Rocket", "Steve", "Ultron"] |
171 | | - |
172 | | - self.assertListEqual( |
173 | | - sorted_names(params), result, |
174 | | - msg="The queue was not properly sorted" |
175 | | - ) |
| 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) |
0 commit comments