Skip to content

Commit e7c2d98

Browse files
committed
TST: Create Function.integral tests for splines
1 parent afa44d6 commit e7c2d98

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

tests/conftest.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,22 @@ def linear_func():
199199
)
200200

201201

202+
@pytest.fixture
203+
def spline_func():
204+
"""Create a spline interpolated function based on a list of points.
205+
206+
Returns
207+
-------
208+
Function
209+
Spline interpolated, with natural extrapolation
210+
"""
211+
return Function(
212+
[[0, 0], [1, 7], [2, -3], [3, -1], [4, 3]],
213+
interpolation="spline",
214+
extrapolation="natural",
215+
)
216+
217+
202218
@pytest.fixture
203219
def func_from_csv():
204220
func = Function(

tests/test_function.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def test_extrapolation_methods(linear_func):
134134
assert np.isclose(linear_func.getValue(-1), -1, atol=1e-6)
135135

136136

137-
def test_integral(linear_func):
137+
def test_integral_linear_interpolation(linear_func):
138138
"""Test the integral method of the Function class.
139139
140140
Parameters
@@ -144,3 +144,25 @@ def test_integral(linear_func):
144144
"""
145145
# Test integral
146146
assert np.isclose(linear_func.integral(0, 1), 0.5, atol=1e-6)
147+
148+
149+
@pytest.mark.parametrize("a", [-1, 0, 0.5, 1, 2, 2.5, 3.5, 4, 5])
150+
@pytest.mark.parametrize("b", [-1, 0, 0.5, 1, 2, 2.5, 3.5, 4, 5])
151+
def test_integral_spline_interpolation(spline_func, a, b):
152+
"""Test the integral method of the Function class.
153+
154+
Parameters
155+
----------
156+
spline_func : rocketpy.Function
157+
A Function object created from a list of values.
158+
a : float
159+
Lower limit of the integral.
160+
b : float
161+
Upper limit of the integral.
162+
"""
163+
# Test integral
164+
assert np.isclose(
165+
spline_func.integral(a, b, numerical=False),
166+
spline_func.integral(a, b, numerical=True),
167+
atol=1e-3,
168+
)

0 commit comments

Comments
 (0)