mirror of https://github.com/dirtbags/moth.git
Adding unique answer validator
This commit is contained in:
parent
7701e98a2d
commit
ecb20713aa
|
@ -79,6 +79,22 @@ class MothValidator:
|
|||
if len(puzzle.answers) == 0:
|
||||
raise MothValidationError("No answers provided")
|
||||
|
||||
@staticmethod
|
||||
def check_unique_answers(puzzle):
|
||||
"""Check if puzzle answers are unique"""
|
||||
known_answers = []
|
||||
duplicate_answers = []
|
||||
|
||||
for answer in puzzle.answers:
|
||||
if answer not in known_answers:
|
||||
known_answers.append(answer)
|
||||
else:
|
||||
duplicate_answers.append(answer)
|
||||
|
||||
if len(duplicate_answers) > 0:
|
||||
raise MothValidationError("Duplicate answer(s) %s" % ", ".join(duplicate_answers))
|
||||
|
||||
|
||||
@staticmethod
|
||||
def check_has_authors(puzzle):
|
||||
"""Check if the puzzle has authors defined"""
|
||||
|
|
Loading…
Reference in New Issue