tests.test_optimizers.test_large_search_space   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 36.21 %

Importance

Changes 0
Metric Value
eloc 38
dl 21
loc 58
rs 10
c 0
b 0
f 0
wmc 7

5 Functions

Rating   Name   Duplication   Size   Complexity  
A test_large_search_space_0() 10 10 1
A test_large_search_space_1() 11 11 1
A objective_function() 0 2 1
A test_large_search_space_2() 0 10 2
A test_large_search_space_3() 0 10 2

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
import pytest
2
import numpy as np
3
4
from ._parametrize import optimizers_noSBOM, optimizers_SBOM
5
6
7
def objective_function(para):
8
    return 1
9
10
11 View Code Duplication
@pytest.mark.parametrize(*optimizers_noSBOM)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
12
def test_large_search_space_0(Optimizer):
13
14
    search_space = {
15
        "x1": np.arange(0, 100000),
16
        "x2": np.arange(0, 100000),
17
        "x3": np.arange(0, 100000),
18
    }
19
    opt = Optimizer(search_space, initialize={"random": 10})
20
    opt.search(objective_function, n_iter=150, verbosity=False)
21
22
23 View Code Duplication
@pytest.mark.parametrize(*optimizers_noSBOM)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
24
def test_large_search_space_1(Optimizer):
25
26
    search_space = {
27
        "x1": np.arange(0, 100, 0.001),
28
        "x2": np.arange(0, 100, 0.001),
29
        "x3": np.arange(0, 100, 0.001),
30
    }
31
32
    opt = Optimizer(search_space, initialize={"random": 10})
33
    opt.search(objective_function, n_iter=150, verbosity=False)
34
35
36
@pytest.mark.parametrize(*optimizers_noSBOM)
37
def test_large_search_space_2(Optimizer):
38
39
    search_space = {}
40
    for i in range(33):
41
        key = "x" + str(i)
42
        search_space[key] = np.arange(0, 100)
43
44
    opt = Optimizer(search_space, initialize={"random": 34, "vertices": 34, "grid": 34})
45
    opt.search(objective_function, n_iter=1000, verbosity=False)
46
47
48
@pytest.mark.parametrize(*optimizers_SBOM)
49
def test_large_search_space_3(Optimizer):
50
51
    search_space = {}
52
    for i in range(10):
53
        key = "x" + str(i)
54
        search_space[key] = np.arange(0, 10)
55
56
    opt = Optimizer(search_space, initialize={"random": 1})
57
    opt.search(objective_function, n_iter=2, verbosity=False)
58