-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtest_functions.py
79 lines (55 loc) · 1.58 KB
/
test_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import numpy as np
def test_simple_functions():
from cec2017.simple import all_functions
assert len(all_functions) == 10
M = 2
dims = [2, 10, 20, 30, 50, 100]
for i, f in enumerate(all_functions):
assert f.__name__ == f"f{1 + i}"
for d in dims:
x = np.zeros((M, d))
y = f(x)
assert y.shape == (M,)
pass
def test_hybrid_functions():
from cec2017.hybrid import all_functions
assert len(all_functions) == 10
M = 2
dims = [10, 30, 50, 100]
for i, f in enumerate(all_functions):
assert f.__name__ == f"f{11 + i}"
for d in dims:
x = np.zeros((M, d))
y = f(x)
assert y.shape == (M,)
def test_composition_functions():
from cec2017.composition import all_functions
assert len(all_functions) == 10
M = 2
dims = [10, 30, 50, 100]
for i, f in enumerate(all_functions):
assert f.__name__ == f"f{21 + i}"
for d in dims:
x = np.zeros((M, d))
y = f(x)
assert y.shape == (M,)
def test_all_functions():
from cec2017.functions import all_functions
assert len(all_functions) == 30
M = 2
D = 10
x = np.zeros((M, D))
for i, f in enumerate(all_functions):
assert f.__name__ == f"f{1 + i}"
y = f(x)
assert y.shape == (M,)
def test_list_inputs():
from cec2017.functions import all_functions
M = 2
D = 10
x = [0.0] * D
x = [x] * M
# functions should allow
for f in all_functions:
y = f(x)
assert y.shape == (M,)