| Total Complexity | 4 |
| Total Lines | 45 |
| Duplicated Lines | 77.78 % |
| 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 date_time_converter import date_time |
||
| 4 | |||
| 5 | |||
| 6 | View Code Duplication | class Tests(unittest.TestCase): |
|
|
|
|||
| 7 | TESTS = { |
||
| 8 | "Basics": [ |
||
| 9 | { |
||
| 10 | "input": '01.01.2000 00:00', |
||
| 11 | "answer": "1 January 2000 year 0 hours 0 minutes", |
||
| 12 | }, |
||
| 13 | { |
||
| 14 | "input": '09.05.1945 06:30', |
||
| 15 | "answer": "9 May 1945 year 6 hours 30 minutes", |
||
| 16 | }, |
||
| 17 | ], |
||
| 18 | "Extra": [ |
||
| 19 | { |
||
| 20 | "input": '20.11.1990 03:55', |
||
| 21 | "answer": "20 November 1990 year 3 hours 55 minutes", |
||
| 22 | }, |
||
| 23 | { |
||
| 24 | "input": '09.07.1995 16:50', |
||
| 25 | "answer": "9 July 1995 year 16 hours 50 minutes", |
||
| 26 | }, |
||
| 27 | { |
||
| 28 | "input": '11.04.1812 01:01', |
||
| 29 | "answer": "11 April 1812 year 1 hour 1 minute", |
||
| 30 | }, |
||
| 31 | ], |
||
| 32 | } |
||
| 33 | |||
| 34 | def test_Basics(self): |
||
| 35 | for i in self.TESTS['Basics']: |
||
| 36 | assert date_time(i['input']) == i['answer'] |
||
| 37 | |||
| 38 | def test_Extra(self): |
||
| 39 | for i in self.TESTS['Extra']: |
||
| 40 | assert date_time(i['input']) == i['answer'] |
||
| 41 | |||
| 42 | |||
| 43 | if __name__ == "__main__": # pragma: no cover |
||
| 44 | unittest.main() |
||
| 45 |