|
2 | 2 |
|
3 | 3 | from allergies import Allergies
|
4 | 4 |
|
5 |
| -# Python 2/3 compatibility |
6 |
| -if not hasattr(unittest.TestCase, 'assertCountEqual'): |
7 |
| - unittest.TestCase.assertCountEqual = unittest.TestCase.assertItemsEqual |
8 |
| - |
9 |
| - |
10 | 5 | # Tests adapted from `problem-specifications//canonical-data.json` @ v2.0.0
|
11 | 6 |
|
12 |
| -class AllergiesTest(unittest.TestCase): |
13 | 7 |
|
| 8 | +class AllergiesTest(unittest.TestCase): |
14 | 9 | def test_eggs_not_allergic_to_anything(self):
|
15 | 10 | self.assertIs(Allergies(0).allergic_to("eggs"), False)
|
16 | 11 |
|
@@ -98,10 +93,10 @@ def test_allergic_to_chocolate_and_something_else(self):
|
98 | 93 | def test_allergic_to_something_but_not_chocolate(self):
|
99 | 94 | self.assertIs(Allergies(80).allergic_to("chocolate"), False)
|
100 | 95 |
|
101 |
| - def test_chocolate_alergic_to_everything(self): |
| 96 | + def test_chocolate_allergic_to_everything(self): |
102 | 97 | self.assertIs(Allergies(255).allergic_to("chocolate"), True)
|
103 | 98 |
|
104 |
| - def test_pollen_not_alergic_to_anything(self): |
| 99 | + def test_pollen_not_allergic_to_anything(self): |
105 | 100 | self.assertIs(Allergies(0).allergic_to("pollen"), False)
|
106 | 101 |
|
107 | 102 | def test_allergic_only_to_pollen(self):
|
@@ -129,45 +124,61 @@ def test_allergic_to_something_but_not_cats(self):
|
129 | 124 | self.assertIs(Allergies(64).allergic_to("cats"), False)
|
130 | 125 |
|
131 | 126 | def test_cats_allergic_to_everything(self):
|
132 |
| - self.assertIs(Allergies(255).allergic_to('cats'), True) |
| 127 | + self.assertIs(Allergies(255).allergic_to("cats"), True) |
133 | 128 |
|
134 | 129 | def test_no_allergies(self):
|
135 | 130 | self.assertEqual(Allergies(0).lst, [])
|
136 | 131 |
|
137 | 132 | def test_just_eggs(self):
|
138 |
| - self.assertEqual(Allergies(1).lst, ['eggs']) |
| 133 | + self.assertEqual(Allergies(1).lst, ["eggs"]) |
139 | 134 |
|
140 | 135 | def test_just_peanuts(self):
|
141 |
| - self.assertEqual(Allergies(2).lst, ['peanuts']) |
| 136 | + self.assertEqual(Allergies(2).lst, ["peanuts"]) |
142 | 137 |
|
143 | 138 | def test_just_strawberries(self):
|
144 |
| - self.assertEqual(Allergies(8).lst, ['strawberries']) |
| 139 | + self.assertEqual(Allergies(8).lst, ["strawberries"]) |
145 | 140 |
|
146 | 141 | def test_eggs_and_peanuts(self):
|
147 |
| - self.assertCountEqual(Allergies(3).lst, ['eggs', 'peanuts']) |
| 142 | + self.assertCountEqual(Allergies(3).lst, ["eggs", "peanuts"]) |
148 | 143 |
|
149 | 144 | def test_more_than_eggs_but_not_peanuts(self):
|
150 |
| - self.assertCountEqual(Allergies(5).lst, ['eggs', 'shellfish']) |
| 145 | + self.assertCountEqual(Allergies(5).lst, ["eggs", "shellfish"]) |
151 | 146 |
|
152 | 147 | def test_lots_of_stuff(self):
|
153 | 148 | self.assertCountEqual(
|
154 | 149 | Allergies(248).lst,
|
155 |
| - ['strawberries', 'tomatoes', 'chocolate', 'pollen', 'cats']) |
| 150 | + ["strawberries", "tomatoes", "chocolate", "pollen", "cats"], |
| 151 | + ) |
156 | 152 |
|
157 | 153 | def test_everything(self):
|
158 | 154 | self.assertCountEqual(
|
159 |
| - Allergies(255).lst, [ |
160 |
| - 'eggs', 'peanuts', 'shellfish', 'strawberries', 'tomatoes', |
161 |
| - 'chocolate', 'pollen', 'cats' |
162 |
| - ]) |
| 155 | + Allergies(255).lst, |
| 156 | + [ |
| 157 | + "eggs", |
| 158 | + "peanuts", |
| 159 | + "shellfish", |
| 160 | + "strawberries", |
| 161 | + "tomatoes", |
| 162 | + "chocolate", |
| 163 | + "pollen", |
| 164 | + "cats", |
| 165 | + ], |
| 166 | + ) |
163 | 167 |
|
164 | 168 | def test_no_allergen_score_parts(self):
|
165 | 169 | self.assertCountEqual(
|
166 |
| - Allergies(509).lst, [ |
167 |
| - 'eggs', 'shellfish', 'strawberries', 'tomatoes', 'chocolate', |
168 |
| - 'pollen', 'cats' |
169 |
| - ]) |
170 |
| - |
171 |
| - |
172 |
| -if __name__ == '__main__': |
| 170 | + Allergies(509).lst, |
| 171 | + [ |
| 172 | + "eggs", |
| 173 | + "shellfish", |
| 174 | + "strawberries", |
| 175 | + "tomatoes", |
| 176 | + "chocolate", |
| 177 | + "pollen", |
| 178 | + "cats", |
| 179 | + ], |
| 180 | + ) |
| 181 | + |
| 182 | + |
| 183 | +if __name__ == "__main__": |
173 | 184 | unittest.main()
|
0 commit comments