Passed
Push — master ( 417be6...1ebf23 )
by Simon
02:51
created

tests.test_optimizers.test_multiple_searches   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 69.33 %

Importance

Changes 0
Metric Value
eloc 49
dl 52
loc 75
rs 10
c 0
b 0
f 0
wmc 6

6 Functions

Rating   Name   Duplication   Size   Complexity  
A test_searches_4() 11 11 1
A test_searches_2() 10 10 1
A test_searches_0() 11 11 1
A test_searches_1() 10 10 1
A objective_function() 0 3 1
A test_searches_3() 10 10 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
import pytest
2
import numpy as np
3
4
from ._parametrize import optimizers
5
6
7
def objective_function(para):
8
    score = -para["x1"] * para["x1"]
9
    return score
10
11
12
search_space = {"x1": np.arange(-100, 1, 1)}
13
14
15 View Code Duplication
@pytest.mark.parametrize(*optimizers)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
16
def test_searches_0(Optimizer):
17
18
    initialize = {"warm_start": [{"x1": -100}]}
19
20
    opt = Optimizer(search_space, initialize=initialize)
21
    opt.search(objective_function, n_iter=1)
22
    opt.search(objective_function, n_iter=1)
23
24
    assert -100 in opt.results["x1"].values
25
    assert len(opt.results["x1"]) == 2
26
27
28 View Code Duplication
@pytest.mark.parametrize(*optimizers)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
29
def test_searches_1(Optimizer):
30
    initialize = {"warm_start": [{"x1": -100}]}
31
32
    opt = Optimizer(search_space, initialize=initialize)
33
    opt.search(objective_function, n_iter=1)
34
    opt.search(objective_function, n_iter=10)
35
36
    assert -100 in opt.results["x1"].values
37
    assert len(opt.results["x1"]) == 11
38
39
40 View Code Duplication
@pytest.mark.parametrize(*optimizers)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
41
def test_searches_2(Optimizer):
42
    initialize = {"warm_start": [{"x1": -100}]}
43
44
    opt = Optimizer(search_space, initialize=initialize)
45
    opt.search(objective_function, n_iter=1)
46
    opt.search(objective_function, n_iter=20)
47
48
    assert -100 in opt.results["x1"].values
49
    assert len(opt.results["x1"]) == 21
50
51
52 View Code Duplication
@pytest.mark.parametrize(*optimizers)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
53
def test_searches_3(Optimizer):
54
    initialize = {"warm_start": [{"x1": -100}]}
55
56
    opt = Optimizer(search_space, initialize=initialize)
57
    opt.search(objective_function, n_iter=10)
58
    opt.search(objective_function, n_iter=20)
59
60
    assert -100 in opt.results["x1"].values
61
    assert len(opt.results["x1"]) == 30
62
63
64 View Code Duplication
@pytest.mark.parametrize(*optimizers)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
65
def test_searches_4(Optimizer):
66
    initialize = {"warm_start": [{"x1": -100}]}
67
68
    opt = Optimizer(search_space, initialize=initialize)
69
    opt.search(objective_function, n_iter=10)
70
    opt.search(objective_function, n_iter=10)
71
    opt.search(objective_function, n_iter=10)
72
73
    assert -100 in opt.results["x1"].values
74
    assert len(opt.results["x1"]) == 30
75