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

test_searches_2()   A

Complexity

Conditions 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nop 1
dl 10
loc 10
rs 10
c 0
b 0
f 0
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