-
-
Notifications
You must be signed in to change notification settings - Fork 262
Expand file tree
/
Copy pathtest_piecewise_function.py
More file actions
35 lines (30 loc) · 892 Bytes
/
Copy pathtest_piecewise_function.py
File metadata and controls
35 lines (30 loc) · 892 Bytes
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
import pytest
from rocketpy import PiecewiseFunction
@pytest.mark.parametrize(
"source",
[
((0, 4), lambda x: x),
{"0-4": lambda x: x},
{(0, 4): lambda x: x, (3, 5): lambda x: 2 * x},
],
)
def test_invalid_source(source):
"""Test an error is raised when the source parameter is invalid"""
with pytest.raises((TypeError, ValueError)):
PiecewiseFunction(source)
@pytest.mark.parametrize(
"source",
[
{(-1, 0): lambda x: -x, (0, 1): lambda x: x},
{
(0, 1): lambda x: x,
(1, 2): lambda x: 1,
(2, 3): lambda x: 3 - x,
},
],
)
@pytest.mark.parametrize("inputs", [None, "X"])
@pytest.mark.parametrize("outputs", [None, "Y"])
def test_new(source, inputs, outputs):
"""Test if PiecewiseFunction.__new__ runs correctly"""
PiecewiseFunction(source, inputs, outputs)