| Total Complexity | 4 |
| Total Lines | 30 |
| Duplicated Lines | 80 % |
| 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 | import unittest |
||
| 2 | |||
| 3 | from easy_unpack import easy_unpack |
||
| 4 | |||
| 5 | |||
| 6 | View Code Duplication | class Tests(unittest.TestCase): |
|
|
|
|||
| 7 | TESTS = { |
||
| 8 | "Basics": [ |
||
| 9 | {"input": [1, 2, 3, 4, 5, 6, 7, 9], "answer": (1, 3, 7)}, |
||
| 10 | {"input": [1, 1, 1, 1], "answer": (1, 1, 1)}, |
||
| 11 | {"input": [6, 3, 7], "answer": (6, 7, 3)}, |
||
| 12 | ], |
||
| 13 | "Extra": [ |
||
| 14 | {"input": [30, 40, 100], "answer": (30, 100, 40)}, |
||
| 15 | {"input": [5, 5, 5, 5, 5, 5], "answer": (5, 5, 5)}, |
||
| 16 | ], |
||
| 17 | } |
||
| 18 | |||
| 19 | def test_Basics(self): |
||
| 20 | for i in self.TESTS['Basics']: |
||
| 21 | assert easy_unpack(i['input']) == i['answer'] |
||
| 22 | |||
| 23 | def test_Extra(self): |
||
| 24 | for i in self.TESTS['Extra']: |
||
| 25 | assert easy_unpack(i['input']) == i['answer'] |
||
| 26 | |||
| 27 | |||
| 28 | if __name__ == "__main__": # pragma: no cover |
||
| 29 | unittest.main() |
||
| 30 |