| Total Complexity | 6 |
| Total Lines | 34 |
| Duplicated Lines | 100 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 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 | #!/usr/bin/env python3 |
||
| 11 | View Code Duplication | class TestElementNum(unittest.TestCase): |
|
|
|
|||
| 12 | """ElementNum module tests""" |
||
| 13 | |||
| 14 | def test_valid(self): |
||
| 15 | """Test field formats that are valid ElementNum elements.""" |
||
| 16 | |||
| 17 | test_fields = [ |
||
| 18 | ('a', '3b'), # 3 byte number: 0, 2^24-1 |
||
| 19 | ('b', 'H'), # unsigned short: 0, 65535 |
||
| 20 | ('c', '4Q'), # 32 signed byte number: (super big number) |
||
| 21 | ('d', 'l'), # signed long: -2^31, 2^31-1 |
||
| 22 | ] |
||
| 23 | |||
| 24 | for field in test_fields: |
||
| 25 | with self.subTest(field): # pylint: disable=no-member |
||
| 26 | out = ElementNum.valid(field) |
||
| 27 | self.assertTrue(out) |
||
| 28 | |||
| 29 | def test_not_valid(self): |
||
| 30 | """Test field formats that are not valid ElementNum elements.""" |
||
| 31 | |||
| 32 | test_fields = [ |
||
| 33 | ('a', '4x'), # 4 pad bytes |
||
| 34 | ('b', 'z'), # invalid |
||
| 35 | ('c', '1'), # invalid |
||
| 36 | ('d', '9S'), # invalid (must be lowercase) |
||
| 37 | ('e', '/'), # invalid |
||
| 38 | ('f', '?'), # invalid |
||
| 39 | ] |
||
| 40 | |||
| 41 | for field in test_fields: |
||
| 42 | with self.subTest(field): # pylint: disable=no-member |
||
| 43 | out = ElementNum.valid(field) |
||
| 44 | self.assertFalse(out) |
||
| 45 |