Completed
Push — master ( fb6854...6f1632 )
by Ben
01:42
created

test()   F

Complexity

Conditions 13

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 13
c 1
b 0
f 0
dl 0
loc 23
rs 2.9787

How to fix   Complexity   

Complexity

Complex classes like test() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
from ne2001.utils import Class_Operation
2
3
4
class Foo(Class_Operation):
5
    """
6
    """
7
8
    def __init__(self, func, x):
9
        self.x = x
10
        self.func = func
11
12
def test():
13
    f1 = Foo(lambda x: 2*x, 1)
14
    f2 = Foo(lambda x: x**2, 2)
15
16
    f = f1 + f2
17
    assert f.x == f1.x + f2.x
18
    assert f.func(3) == f1.func(3) + f2.func(3)
19
20
    f = f1 - f2
21
    assert f.x == f1.x - f2.x
22
    assert f.func(3) == f1.func(3) - f2.func(3)
23
24
    f = f1 + f2
25
    assert f.x == f1.x + f2.x
26
    assert f.func(3) == f1.func(3) + f2.func(3)
27
28
    f = f1 * f2
29
    assert f.x == f1.x * f2.x
30
    assert f.func(3) == f1.func(3) * f2.func(3)
31
32
    f = max(f1, f2)
33
    assert f.x == max(f1.x, f2.x)
34
    assert f.func(3) == max(f1.func(3), f2.func(3))
35