Completed
Push — master ( 8ebc53...375895 )
by Wojtek
6s
created

grortir.test.externals.pyswarm.myfunc()   A

Complexity

Conditions 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 12
rs 9.4285
1
"""Tests for pyswarm."""
2
from unittest import TestCase
3
from grortir.externals.pyswarm.pso import pso
4
5
6
class TestPso(TestCase):
7
    """Class for tests pyswarm."""
8
9
    def test_run_simple_pso(self):
10
        """Test running library."""
11
        lower_bound = [-3, -1]
12
        upper_bound = [2, 6]
13
14
        x_opt, f_opt = pso(myfunc, lower_bound, upper_bound)
0 ignored issues
show
Bug introduced by
The tuple unpacking with sequence defined at line 210 of grortir.externals.pyswarm.pso seems to be unbalanced; 2 value(s) for 4 label(s)

This happens when the amount of values does not equal the amount of labels:

a, b = ("a", "b", "c")  # only 2 labels for 3 values
Loading history...
Bug introduced by
The tuple unpacking with sequence defined at line 217 of grortir.externals.pyswarm.pso seems to be unbalanced; 2 value(s) for 4 label(s)

This happens when the amount of values does not equal the amount of labels:

a, b = ("a", "b", "c")  # only 2 labels for 3 values
Loading history...
Bug introduced by
The tuple unpacking with sequence defined at line 233 of grortir.externals.pyswarm.pso seems to be unbalanced; 2 value(s) for 4 label(s)

This happens when the amount of values does not equal the amount of labels:

a, b = ("a", "b", "c")  # only 2 labels for 3 values
Loading history...
15
        self.assertIsNotNone(x_opt)
16
        self.assertIsNotNone(f_opt)
17
18
19
def myfunc(input_vector):
20
    """Simple function for tests.
21
22
    Args:
23
        input_vector (list): input vector
24
25
    Returns:
26
        object : value of function
27
    """
28
    x_1 = input_vector[0]
29
    x_2 = input_vector[1]
30
    return x_1 ** 4 - 2 * x_2 * x_1 ** 2 + x_2 ** 2 + x_1 ** 2 - 2 * x_1 + 5
31