Passed
Pull Request — master (#110)
by
unknown
01:35
created

tests_old.test_issues.test_issue_34   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 48
dl 0
loc 74
rs 10
c 0
b 0
f 0
wmc 4

4 Functions

Rating   Name   Duplication   Size   Complexity  
A test_mixed_type_search_space_3() 0 19 1
A test_mixed_type_search_space_0() 0 13 1
A test_mixed_type_search_space_1() 0 13 1
A test_mixed_type_search_space_2() 0 15 1
1
import numpy as np
2
from hyperactive import Hyperactive
3
4
""" --- test search spaces with mixed int/float types --- """
5
n_iter = 100
6
7
8
def test_mixed_type_search_space_0():
9
    def objective_function(para):
10
        assert isinstance(para["x1"], int)
11
12
        return 1
13
14
    search_space = {
15
        "x1": list(range(10, 20)),
16
    }
17
18
    hyper = Hyperactive()
19
    hyper.add_search(objective_function, search_space, n_iter=n_iter)
20
    hyper.run()
21
22
23
def test_mixed_type_search_space_1():
24
    def objective_function(para):
25
        assert isinstance(para["x2"], float)
26
27
        return 1
28
29
    search_space = {
30
        "x2": list(np.arange(1, 2, 0.1)),
31
    }
32
33
    hyper = Hyperactive()
34
    hyper.add_search(objective_function, search_space, n_iter=n_iter)
35
    hyper.run()
36
37
38
def test_mixed_type_search_space_2():
39
    def objective_function(para):
40
        assert isinstance(para["x1"], int)
41
        assert isinstance(para["x2"], float)
42
43
        return 1
44
45
    search_space = {
46
        "x1": list(range(10, 20)),
47
        "x2": list(np.arange(1, 2, 0.1)),
48
    }
49
50
    hyper = Hyperactive()
51
    hyper.add_search(objective_function, search_space, n_iter=n_iter)
52
    hyper.run()
53
54
55
def test_mixed_type_search_space_3():
56
    def objective_function(para):
57
        assert isinstance(para["x1"], int)
58
        assert isinstance(para["x2"], float)
59
        assert isinstance(para["x3"], float)
60
        assert isinstance(para["x4"], str)
61
62
        return 1
63
64
    search_space = {
65
        "x1": list(range(10, 20)),
66
        "x2": list(np.arange(1, 2, 0.1)),
67
        "x3": list(np.arange(1, 2, 0.1)),
68
        "x4": ["str1", "str2", "str3"],
69
    }
70
71
    hyper = Hyperactive()
72
    hyper.add_search(objective_function, search_space, n_iter=n_iter)
73
    hyper.run()
74