diff options
| author | Bicker <bickerkards@tuta.io> | 2019-05-22 17:45:37 +0200 |
|---|---|---|
| committer | Bicker <bickerkards@tuta.io> | 2019-05-22 17:45:37 +0200 |
| commit | 25314fd2aed81aa5281bc3d93dbcc7919368ebe1 (patch) | |
| tree | 1995521ee652e419926de5fced0f2e3b655e70fb /ql/ast/checkers/question_checker.py | |
Diffstat (limited to 'ql/ast/checkers/question_checker.py')
| -rw-r--r-- | ql/ast/checkers/question_checker.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/ql/ast/checkers/question_checker.py b/ql/ast/checkers/question_checker.py new file mode 100644 index 0000000..5b255d8 --- /dev/null +++ b/ql/ast/checkers/question_checker.py @@ -0,0 +1,33 @@ +class QuestionChecker: + def __init__(self, questions): + self.__errors = [] + self.__warnings = [] + self.__check_questions(questions) + + @property + def errors(self): + return self.__errors + + @property + def warnings(self): + return self.__warnings + + def __check_questions(self, questions): + for question1 in questions: + for question2 in questions: + if question1 != question2: + equal_labels = question1['label'] == question2['label'] + equal_identifiers = question1['identifier'] == question2['identifier'] + different_types = question1['answer_type'] != question2['answer_type'] + + if all([equal_labels, equal_identifiers, different_types]): + self.__errors.append('Duplicate questions with different types found on lines {} and {}' + .format(question1['metadata'].line, question2['metadata'].line)) + + if equal_identifiers: + self.__errors.append('Duplicate question identifiers found on lines {} and {}' + .format(question1['metadata'].line, question2['metadata'].line)) + + if equal_labels: + self.__warnings.append('Duplicate question labels found on lines {} and {}' + .format(question1['metadata'].line, question2['metadata'].line)) |