| Total Complexity | 4 |
| Total Lines | 42 |
| Duplicated Lines | 76.19 % |
| 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 the_longest_palindromic import longest_palindromic |
||
| 4 | |||
| 5 | |||
| 6 | View Code Duplication | class Tests(unittest.TestCase): |
|
|
|
|||
| 7 | TESTS = { |
||
| 8 | "Basics": [ |
||
| 9 | {"input": "abc", "answer": "a"}, |
||
| 10 | {"input": "abacada", "answer": "aba"}, |
||
| 11 | {"input": "artrartrt", "answer": "rtrartr"}, |
||
| 12 | {"input": "aaaaa", "answer": "aaaaa"}, |
||
| 13 | ], |
||
| 14 | "Extra": [ |
||
| 15 | {"input": "so sad das-li", "answer": "sad das"}, |
||
| 16 | {"input": " a b c", "answer": " a "}, |
||
| 17 | {"input": "1", "answer": "1"}, |
||
| 18 | { |
||
| 19 | "input": "123abcba", |
||
| 20 | "answer": "abcba", |
||
| 21 | "explanation": "At the end of text", |
||
| 22 | }, |
||
| 23 | { |
||
| 24 | "input": "abcba123abcdcba", |
||
| 25 | "answer": "abcdcba", |
||
| 26 | "explanation": "Two palindromes in text", |
||
| 27 | }, |
||
| 28 | ], |
||
| 29 | } |
||
| 30 | |||
| 31 | def test_Basics(self): |
||
| 32 | for i in self.TESTS['Basics']: |
||
| 33 | assert longest_palindromic(i['input']) == i['answer'], i['input'] |
||
| 34 | |||
| 35 | def test_Extra(self): |
||
| 36 | for i in self.TESTS['Extra']: |
||
| 37 | assert longest_palindromic(i['input']) == i['answer'], i['input'] |
||
| 38 | |||
| 39 | |||
| 40 | if __name__ == "__main__": # pragma: no cover |
||
| 41 | unittest.main() |
||
| 42 |