-
Notifications
You must be signed in to change notification settings - Fork 29
/
test_functions.py
45 lines (39 loc) · 1.76 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
import numpy as np
import psyneulink as pnl
import pytest
import psyneulink.core.components.functions.transferfunctions
@pytest.mark.parametrize(
'output_type, variable, expected_output',
[
(pnl.FunctionOutputType.RAW_NUMBER, 1, 1.),
(pnl.FunctionOutputType.RAW_NUMBER, [1], 1.),
(pnl.FunctionOutputType.RAW_NUMBER, [[1]], 1.),
(pnl.FunctionOutputType.RAW_NUMBER, [[[1]]], 1.),
(pnl.FunctionOutputType.NP_1D_ARRAY, 1, np.array([1.])),
(pnl.FunctionOutputType.NP_1D_ARRAY, [1], np.array([1.])),
(pnl.FunctionOutputType.NP_1D_ARRAY, [[1]], np.array([1.])),
(pnl.FunctionOutputType.NP_1D_ARRAY, [[[1]]], np.array([1.])),
(pnl.FunctionOutputType.NP_2D_ARRAY, 1, np.array([[1.]])),
(pnl.FunctionOutputType.NP_2D_ARRAY, [1], np.array([[1.]])),
(pnl.FunctionOutputType.NP_2D_ARRAY, [[1]], np.array([[1.]])),
(pnl.FunctionOutputType.NP_2D_ARRAY, [[[1]]], np.array([[1.]])),
]
)
def test_output_type_conversion(output_type, variable, expected_output):
f = psyneulink.core.components.functions.transferfunctions.Linear()
f.output_type = output_type
f.enable_output_type_conversion = True
assert f.execute(variable) == expected_output
@pytest.mark.parametrize(
'output_type, variable',
[
(pnl.FunctionOutputType.RAW_NUMBER, [1, 1]),
(pnl.FunctionOutputType.RAW_NUMBER, [[1, 1]]),
(pnl.FunctionOutputType.RAW_NUMBER, [[[1], [1, 1]]]),
(pnl.FunctionOutputType.NP_1D_ARRAY, [[1, 1], [1, 1]]),
]
)
def test_output_type_conversion_failure(output_type, variable):
with pytest.raises(pnl.FunctionError):
f = psyneulink.core.components.functions.transferfunctions.Linear()
f.convert_output_type(variable, output_type=output_type)