def test_no_match(self): """ If nothing matches it should return an empty list """ self.assertEqual(normalize_state('*'), []) self.assertEqual(normalize_state('fooBar'), []) self.assertEqual(normalize_state('Brazil'), []) self.assertEqual(normalize_state('Paris'), [])
def test_not_close_enough_match(self): """ When the input string is distorted too much it should return an empty list """ test_states = [ 'Lillyniose', 'Syiatammma', 'Cashmere and Jammu', 'Diddy Kong' ] for original in test_states: with self.subTest(original=original): self.assertEqual(normalize_state(original), [])
def test_close_match(self): """ Close matches to the states map should yield the correct state """ test_states = [('Ilinios', [('Illinois', 'United States')]), ('Saytama', [('Saitama', 'Japan')]), ('kashmir and jannu', [('Jammu and Kashmir', 'India')]), ('King Kong', [('Hong Kong', 'China')])] for original, expected in test_states: with self.subTest(original=original, expected=expected): self.assertEqual(normalize_state(original), expected)
def test_multiple_matches(self): """ Test input that is part of the states map that return multiple matches """ test_states = [('WA', [('Washington', 'United States'), ('Western Australia', 'Australia')]), ('AR', [('Arkansas', 'United States'), ('Arunachal Pradesh', 'India')]), ('nl', [('Nagaland', 'India'), ('Newfoundland and Labrador', 'Canada')])] for original, expected in test_states: with self.subTest(original=original, expected=expected): self.assertEqual(normalize_state(original), expected)
def test_multiple_close_matches(self): """ Close matches to the states map should yield all correct states """ test_states = [('Jiang', [('Jiangsu', 'China'), ('Jiangxi', 'China')]), ('oshima', [('Hiroshima', 'Japan'), ('Kagoshima', 'Japan'), ('Tokushima', 'Japan')]), ('VWA', [('Virginia', 'United States'), ('Washington', 'United States'), ('Western Australia', 'Australia')])] for original, expected in test_states: with self.subTest(original=original, expected=expected): self.assertEqual(normalize_state(original), expected)
def test_part_of_known_states(self): """ Test input that is part of the states map """ test_states = [ ('Queensland', [('Queensland', 'Australia')]), ('QLd', [('Queensland', 'Australia')]), ('Rio de Janeiro', [('Rio De Janeiro', 'Brazil')]), ('ON', [('Ontario', 'Canada')]), ('okinaWA', [('Okinawa', 'Japan')]), ('Georgia', [('Georgia', 'United States')]), ('NY', [('New York', 'United States')]), ] for original, expected in test_states: with self.subTest(original=original, expected=expected): self.assertEqual(normalize_state(original), expected)