Passed
Push — master ( bac9d4...455948 )
by Simon
04:25
created

tests.test_optimizers.test_parameter._base_para_test   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 2

2 Functions

Rating   Name   Duplication   Size   Complexity  
A objective_function() 0 3 1
A _base_para_test_func() 0 14 1
1
# Author: Simon Blanke
2
# Email: [email protected]
3
# License: MIT License
4
5
import numpy as np
6
7
8
def objective_function(para):
9
    score = -para["x1"] * para["x1"]
10
    return score
11
12
13
search_space = {"x1": np.arange(-100, 101, 1)}
14
15
16
def _base_para_test_func(opt_para, optimizer):
17
    opt = optimizer(search_space, **opt_para)
18
    opt.search(
19
        objective_function,
20
        n_iter=30,
21
        memory=False,
22
        verbosity=False,
23
        initialize={"vertices": 1},
24
    )
25
26
    para_key = list(opt_para.keys())[0]
27
    para_value = getattr(opt, para_key)
28
29
    assert para_value == opt_para[para_key]
30