tests.test_obj_func_arg.test_argument_0()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 22
rs 9.65
c 0
b 0
f 0
cc 1
nop 0
1
"""Test module for objective function argument functionality."""
2
3
import numpy as np
4
5
from hyperactive import Hyperactive
6
7
search_space = {
8
    "x1": list(np.arange(0, 100, 1)),
9
}
10
11
12
def test_argument_0():
13
    """Test objective function arguments with pass_through parameter."""
14
15
    def objective_function(para):
16
        print("\npara.nth_iter", para.nth_iter)
17
        print("nth_iter_local", para.pass_through["nth_iter_local"])
18
19
        assert para.nth_iter == para.pass_through["nth_iter_local"]
20
21
        para.pass_through["nth_iter_local"] += 1
22
23
        return 0
24
25
    hyper = Hyperactive()
26
    hyper.add_search(
27
        objective_function,
28
        search_space,
29
        n_iter=100,
30
        pass_through={"nth_iter_local": 0},
31
        memory=False,
32
    )
33
    hyper.run()
34