| Total Complexity | 6 |
| Total Lines | 43 |
| Duplicated Lines | 88.37 % |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | from src.moodle_to_vikwikiquiz.grading_types import GradingType |
||
| 2 | from src.moodle_to_vikwikiquiz.question_types import QuestionType |
||
| 3 | |||
| 4 | |||
| 5 | View Code Duplication | class Question: |
|
|
|
|||
| 6 | def __init__( |
||
| 7 | self, |
||
| 8 | q_type: QuestionType, |
||
| 9 | text: str, |
||
| 10 | illustration: bool, |
||
| 11 | answers: list[str], |
||
| 12 | correct_answers: list[int], |
||
| 13 | grading: GradingType | None = None, |
||
| 14 | ): |
||
| 15 | self.q_type = q_type |
||
| 16 | self.text = text |
||
| 17 | self.illustration = illustration |
||
| 18 | self.grading = grading |
||
| 19 | self.answers = answers |
||
| 20 | self.correct_answers = correct_answers |
||
| 21 | |||
| 22 | def __str__(self) -> str: |
||
| 23 | text = f"== {self.text} ==" |
||
| 24 | if self.illustration: |
||
| 25 | text += "\n[[Fájl:.png|bélyegkép]]" |
||
| 26 | text += f"\n\n{{{{kvízkérdés|típus={self.q_type.value}|válasz={",".join([str(answer) for answer in self.correct_answers])}" |
||
| 27 | if self.grading: |
||
| 28 | text += f"|pontozás={self.grading}" |
||
| 29 | text += "}}" |
||
| 30 | for answer in self.answers: |
||
| 31 | text += f"\n# {answer}" |
||
| 32 | return text |
||
| 33 | |||
| 34 | def __hash__(self) -> int: |
||
| 35 | return hash( |
||
| 36 | frozenset( |
||
| 37 | ( |
||
| 38 | self.q_type, |
||
| 39 | self.text, |
||
| 40 | self.answers.sort(), |
||
| 41 | self.correct_answers.sort(), |
||
| 42 | self.grading, |
||
| 43 | ) |
||
| 46 |