Skip to content

Commit

Permalink
[Units][Tests] Handle plurality for trivia answers with parentheses
Browse files Browse the repository at this point in the history
  • Loading branch information
Harmon758 committed Jul 20, 2023
1 parent 9a6010e commit 222d756
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/test_trivia.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def test_plurality_with_partial_slash(self):
check_answer("Junior/Community Colleges", "junior college")
)

def test_plurality_with_parentheses(self):
self.assertTrue(check_answer("pigs (hogs)", "pig"))
self.assertTrue(check_answer("pigs (hogs)", "hog"))

def test_rearranged_list_with_following_word(self):
self.assertTrue(
check_answer(
Expand Down
3 changes: 3 additions & 0 deletions units/trivia.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ def add_optional_accepted(accepted, optional):
accepted.add(remove_preceding_words(item))
if response in accepted:
return True
with contextlib.suppress(pydantic.ValidationError):
if inflect_engine.plural(response) in accepted:
return True
# Check XX YY (or ZZ accepted)
matches = re.search(
r"(.+?)\s?\((?:or )?(?:a |an |the )?(.+?)(?: accepted)?\)",
Expand Down

0 comments on commit 222d756

Please sign in to comment.