Skip to content

allergies: Update test cases #463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions exercises/allergies/allergies_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

from allergies import Allergies

# Python 2/3 compatibility
if not hasattr(unittest.TestCase, 'assertCountEqual'):
unittest.TestCase.assertCountEqual = unittest.TestCase.assertItemsEqual

class AllergiesTests(unittest.TestCase):

# test cases adapted from `x-common//canonical-data.json` @ version: 1.0.0

class AllergiesTests():
def test_no_allergies_means_not_allergic(self):
allergies = Allergies(0)
self.assertFalse(allergies.is_allergic_to('peanuts'))
Expand All @@ -13,7 +19,7 @@ def test_no_allergies_means_not_allergic(self):
def test_is_allergic_to_eggs(self):
self.assertTrue(Allergies(1).is_allergic_to('eggs'))

def test_has_the_right_allergies(self):
def test_allergic_to_eggs_in_addition_to_other_stuff(self):
allergies = Allergies(5)
self.assertTrue(allergies.is_allergic_to('eggs'))
self.assertTrue(allergies.is_allergic_to('shellfish'))
Expand All @@ -22,19 +28,43 @@ def test_has_the_right_allergies(self):
def test_no_allergies_at_all(self):
self.assertEqual(Allergies(0).lst, [])

def test_allergic_to_just_eggs(self):
self.assertEqual(Allergies(1).lst, ['eggs'])

def test_allergic_to_just_peanuts(self):
self.assertEqual(Allergies(2).lst, ['peanuts'])

def test_allergic_to_just_strawberries(self):
self.assertEqual(Allergies(8).lst, ['strawberries'])

def test_allergic_to_eggs_and_peanuts(self):
self.assertCountEqual(Allergies(3).lst, ['eggs', 'peanuts'])

def test_allergic_to_more_than_eggs_but_not_peanuts(self):
self.assertCountEqual(Allergies(5).lst, ['eggs', 'shellfish'])

def test_allergic_to_lots_of_stuff(self):
self.assertCountEqual(
Allergies(248).lst,
['strawberries', 'tomatoes', 'chocolate', 'pollen', 'cats'])

def test_allergic_to_everything(self):
self.assertEqual(
sorted(Allergies(255).lst),
sorted(('eggs peanuts shellfish strawberries tomatoes '
'chocolate pollen cats').split()))
self.assertCountEqual(
Allergies(255).lst, [
'eggs', 'peanuts', 'shellfish', 'strawberries', 'tomatoes',
'chocolate', 'pollen', 'cats'
])

@unittest.skip('Extra Credit: Passes with a specific type of solution')
def test_ignore_non_allergen_score_parts(self):
def test_ignore_non_allergen_score_parts_only_eggs(self):
self.assertEqual(Allergies(257).lst, ['eggs'])

def test_ignore_non_allergen_score_parts(self):
self.assertCountEqual(
Allergies(509).lst, [
'eggs', 'shellfish', 'strawberries', 'tomatoes', 'chocolate',
'pollen', 'cats'
])


if __name__ == '__main__':
unittest.main()