TestElementNum   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 34
loc 34
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_not_valid() 16 16 3
A test_valid() 14 14 3

How to fix   Duplicated Code   

Duplicated Code

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
2
3
"""Tests for the elementbase class"""
4
5
import unittest
6
7
from starstruct.elementnum import ElementNum
8
9
10
# pylint: disable=line-too-long,invalid-name
11 View Code Duplication
class TestElementNum(unittest.TestCase):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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