tests.model.test_correlation_math   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 60
dl 0
loc 76
rs 10
c 0
b 0
f 0
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A TestAffinityMatrix.test_jaccard() 0 6 1
A TestAffinityMatrix.test_read() 0 4 1
A TestAffinityMatrix.test_minkowski_2() 0 6 1
A TestAffinityMatrix.test_minkowski_1_1() 0 6 1
A TestAffinityMatrix.test_minkowski_0() 0 6 1
A TestAffinityMatrix.test_minkowski_inf() 0 8 1
A TestAffinityMatrix.test_non_self_pairs() 0 4 1
A TestAffinityMatrix.test_minkowski_1_2() 0 6 1
A TestAffinityMatrix.test_pairs() 0 7 1
1
import pytest
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
introduced by
Unable to import 'pytest'
Loading history...
2
import numpy as np
0 ignored issues
show
introduced by
Unable to import 'numpy'
Loading history...
3
4
from mandos.model.correlation_math import *
0 ignored issues
show
Coding Style introduced by
The usage of wildcard imports like mandos.model.correlation_math should generally be avoided.
Loading history...
Unused Code introduced by
logging was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
pd was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
logger was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
CompoundCompoundPair was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
T was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
Z was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
ConfusionMatrix was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
defaultdict was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
Sequence was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
Mapping was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
Set was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
TypeVar was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
Callable was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
SupportsFloat was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
Optional was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
Type was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
List was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
Tup was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
TypedDfs was imported with wildcard, but is not used.
Loading history...
Unused Code introduced by
TypedDf was imported with wildcard, but is not used.
Loading history...
5
6
from .. import get_test_resource
7
8
9
class TestAffinityMatrix:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
10
    def test_read(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
11
        df = AffinityMatrix.read_csv(get_test_resource("affinity_mx.csv"))
0 ignored issues
show
Coding Style Naming introduced by
Variable name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
12
        assert df.rows == ["cocaine", "gabapentin"]
13
        assert df.cols == ["cocaine", "gabapentin"]
14
15
    def test_jaccard(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
16
        items = {"cocaine": {"a", "b", "c"}, "gabapentin": {"a", "b"}}
17
        df = AffinityMatrix.from_function(items, AffinityFunctions.jaccard())
0 ignored issues
show
Coding Style Naming introduced by
Variable name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
18
        assert df.rows == ["cocaine", "gabapentin"]
19
        assert df.cols == ["cocaine", "gabapentin"]
20
        assert df.values.tolist() == [[1, 2 / 3], [2 / 3, 1]]
21
22
    def test_minkowski_1_1(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
23
        items = {"cocaine": [1, 2], "gabapentin": [1, 2]}
24
        df = AffinityMatrix.from_function(items, AffinityFunctions.negative_minkowski(1))
0 ignored issues
show
Coding Style Naming introduced by
Variable name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
25
        assert df.rows == ["cocaine", "gabapentin"]
26
        assert df.cols == ["cocaine", "gabapentin"]
27
        assert df.values.tolist() == [[0, 0], [0, 0]]
28
29
    def test_minkowski_1_2(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
30
        items = {"cocaine": [1, 2], "gabapentin": [2, 1]}
31
        df = AffinityMatrix.from_function(items, AffinityFunctions.negative_minkowski(1))
0 ignored issues
show
Coding Style Naming introduced by
Variable name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
32
        assert df.rows == ["cocaine", "gabapentin"]
33
        assert df.cols == ["cocaine", "gabapentin"]
34
        assert df.values.tolist() == [[0, -2], [-2, 0]]
35
36
    def test_minkowski_2(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
37
        items = {"cocaine": [1, 3], "gabapentin": [3, 1]}
38
        df = AffinityMatrix.from_function(items, AffinityFunctions.negative_minkowski(2))
0 ignored issues
show
Coding Style Naming introduced by
Variable name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
39
        assert df.rows == ["cocaine", "gabapentin"]
40
        assert df.cols == ["cocaine", "gabapentin"]
41
        assert df.values.tolist() == [[0, -np.sqrt(8)], [-np.sqrt(8), 0]]
42
43
    def test_minkowski_0(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
44
        items = {"cocaine": [1, 2], "gabapentin": [2, 1]}
45
        df = AffinityMatrix.from_function(items, AffinityFunctions.negative_minkowski(0))
0 ignored issues
show
Coding Style Naming introduced by
Variable name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
46
        assert df.rows == ["cocaine", "gabapentin"]
47
        assert df.cols == ["cocaine", "gabapentin"]
48
        assert df.values.tolist() == [[0, -2], [-2, 0]]
49
50
    def test_minkowski_inf(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
51
        items = {"cocaine": [1, 4], "gabapentin": [2, 1]}
52
        df = AffinityMatrix.from_function(
0 ignored issues
show
Coding Style Naming introduced by
Variable name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
53
            items, AffinityFunctions.negative_minkowski(float("infinity"))
54
        )
55
        assert df.rows == ["cocaine", "gabapentin"]
56
        assert df.cols == ["cocaine", "gabapentin"]
57
        assert df.values.tolist() == [[0, -3], [-3, 0]]
58
59
    def test_pairs(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
60
        df = AffinityMatrix.read_csv(get_test_resource("affinity_mx.csv"))
0 ignored issues
show
Coding Style Naming introduced by
Variable name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
61
        dct = df.all_pairs()
62
        assert dct == {
63
            ("cocaine", "cocaine"): 0.2,
64
            ("gabapentin", "gabapentin"): 0.2,
65
            ("cocaine", "gabapentin"): 0.1,
66
        }
67
68
    def test_non_self_pairs(self):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
69
        df = AffinityMatrix.read_csv(get_test_resource("affinity_mx.csv"))
0 ignored issues
show
Coding Style Naming introduced by
Variable name "df" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
70
        dct = df.non_self_pairs()
71
        assert dct == {("cocaine", "gabapentin"): 0.1}
72
73
74
if __name__ == "__main__":
75
    pytest.main()
76