TestCreditCallsGroupOptimizationStrategy   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 68
Duplicated Lines 48.53 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 33
loc 68
rs 10
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A get_basic_process() 0 10 2
A test_initialize_exception() 0 11 3
A test_initialize() 0 8 1
A test_should_continue_false_enough_quality() 11 11 1
A test_should_continue_false_not_safe_cost() 11 11 1
A test_should_continue_true() 11 11 1

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
from unittest import TestCase
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
from unittest.mock import Mock
3
4
from grortir.main.pso.credit_calls_group_optimization_strategy import \
5
    CreditCallsGroupOptimizationStrategy
6
7
8
class TestCreditCallsGroupOptimizationStrategy(TestCase):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
9
    def test_initialize(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
10
        process, stages = self.get_basic_process()
11
        tested_object = CreditCallsGroupOptimizationStrategy(stages, process)
12
13
        tested_object.initialize()
14
15
        self.assertEqual(tested_object.max_calls_for_group, 60)
16
        self.assertEqual(tested_object.expected_quality, 1)
17
18
    def get_basic_process(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

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...
19
        stages = []
20
        for i in range(1, 4):
21
            stages.append(Mock())
22
            stages[i - 1].get_cost.return_value = 0
23
            stages[i - 1].get_maximal_acceptable_cost.return_value = i * 10
24
            stages[i - 1].maximum_acceptable_quality = i
25
        process = Mock()
26
        process.nodes.return_value = stages
27
        return process, stages
28
29
    def test_initialize_exception(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
30
        stages = []
31
        for i in range(1, 4):
32
            stages.append(Mock())
33
            stages[i - 1].get_cost.return_value = 0
34
        process = Mock()
35
        process.nodes.return_value = stages
36
        stages[0].get_cost.return_value = 1
37
        tested_object = CreditCallsGroupOptimizationStrategy(stages, process)
38
        with self.assertRaises(ValueError):
39
            tested_object.initialize()
40
41 View Code Duplication
    def test_should_continue_true(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
42
        process, stages = self.get_basic_process()
43
        tested_object = CreditCallsGroupOptimizationStrategy(stages, process)
44
        tested_object.initialize()
45
        stages[0].get_cost.return_value = 20
46
        stages[1].get_cost.return_value = 20
47
        stages[2].get_cost.return_value = 20
48
        best_particle = Mock()
49
        best_particle.best_quality = 2
50
        result = tested_object.should_continue(best_particle)
51
        self.assertTrue(result)
52
53 View Code Duplication
    def test_should_continue_false_enough_quality(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style Naming introduced by
The name test_should_continue_false_enough_quality does not conform to the method naming conventions ([a-z_][a-z0-9_]{2,30}$).

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...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
54
        process, stages = self.get_basic_process()
55
        tested_object = CreditCallsGroupOptimizationStrategy(stages, process)
56
        tested_object.initialize()
57
        best_particle = Mock()
58
        stages[0].get_cost.return_value = 20
59
        stages[1].get_cost.return_value = 20
60
        stages[2].get_cost.return_value = 20
61
        best_particle.best_quality = 0.5
62
        result = tested_object.should_continue(best_particle)
63
        self.assertFalse(result)
64
65 View Code Duplication
    def test_should_continue_false_not_safe_cost(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
Coding Style Naming introduced by
The name test_should_continue_false_not_safe_cost does not conform to the method naming conventions ([a-z_][a-z0-9_]{2,30}$).

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...
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
66
        process, stages = self.get_basic_process()
67
        tested_object = CreditCallsGroupOptimizationStrategy(stages, process)
68
        tested_object.initialize()
69
        best_particle = Mock()
70
        best_particle.best_quality = 2
71
        stages[0].get_cost.return_value = 20
72
        stages[1].get_cost.return_value = 20
73
        stages[2].get_cost.return_value = 21
74
        result = tested_object.should_continue(best_particle)
75
        self.assertFalse(result)
76