@@ -88,7 +88,7 @@ def test_plots(mock_show, func_from_csv):
88
88
89
89
90
90
def test_interpolation_methods (linear_func ):
91
- """Test some of the interpolation methods of the Function class. Methods
91
+ """Tests some of the interpolation methods of the Function class. Methods
92
92
not tested here are already being called in other tests.
93
93
94
94
Parameters
@@ -97,12 +97,17 @@ def test_interpolation_methods(linear_func):
97
97
A Function object created from a list of values.
98
98
"""
99
99
# Test Akima
100
+ assert isinstance (linear_func .set_interpolation ("akima" ), Function )
100
101
linear_func .set_interpolation ("akima" )
102
+ assert isinstance (linear_func .get_interpolation_method (), str )
101
103
assert linear_func .get_interpolation_method () == "akima"
102
104
assert np .isclose (linear_func .get_value (0 ), 0.0 , atol = 1e-6 )
103
105
104
106
# Test polynomial
107
+
108
+ assert isinstance (linear_func .set_interpolation ("polynomial" ), Function )
105
109
linear_func .set_interpolation ("polynomial" )
110
+ assert isinstance (linear_func .get_interpolation_method (), str )
106
111
assert linear_func .get_interpolation_method () == "polynomial"
107
112
assert np .isclose (linear_func .get_value (0 ), 0.0 , atol = 1e-6 )
108
113
@@ -122,12 +127,16 @@ def test_extrapolation_methods(linear_func):
122
127
assert np .isclose (linear_func .get_value (- 1 ), 0 , atol = 1e-6 )
123
128
124
129
# Test constant
130
+ assert isinstance (linear_func .set_extrapolation ("constant" ), Function )
125
131
linear_func .set_extrapolation ("constant" )
132
+ assert isinstance (linear_func .get_extrapolation_method (), str )
126
133
assert linear_func .get_extrapolation_method () == "constant"
127
134
assert np .isclose (linear_func .get_value (- 1 ), 0 , atol = 1e-6 )
128
135
129
136
# Test natural
137
+ assert isinstance (linear_func .set_extrapolation ("natural" ), Function )
130
138
linear_func .set_extrapolation ("natural" )
139
+ assert isinstance (linear_func .get_extrapolation_method (), str )
131
140
assert linear_func .get_extrapolation_method () == "natural"
132
141
assert np .isclose (linear_func .get_value (- 1 ), - 1 , atol = 1e-6 )
133
142
@@ -143,6 +152,7 @@ def test_integral_linear_interpolation(linearly_interpolated_func, a, b):
143
152
A Function object created from a list of values.
144
153
"""
145
154
# Test integral
155
+ assert isinstance (linearly_interpolated_func .integral (a , b , numerical = True ), float )
146
156
assert np .isclose (
147
157
linearly_interpolated_func .integral (a , b , numerical = False ),
148
158
linearly_interpolated_func .integral (a , b , numerical = True ),
@@ -175,6 +185,75 @@ def test_integral_spline_interpolation(request, func, a, b):
175
185
)
176
186
177
187
188
+ def test_differentiate ():
189
+ """Tests the differentiation method of the Function class.
190
+ Both with respect to return instances and expected behaviour.
191
+ """
192
+ func = Function (1 )
193
+ assert isinstance (func .differentiate (0 ), float )
194
+ assert np .isclose (func .differentiate (5 ), 0 )
195
+
196
+ func_x = Function (lambda x : x )
197
+ assert isinstance (func_x .differentiate (0 ), float )
198
+ assert np .isclose (func_x .differentiate (0 ), 1 )
199
+
200
+ f_square = Function (lambda x : x ** 2 )
201
+ assert isinstance (f_square .differentiate (1 ), float )
202
+ assert np .isclose (f_square .differentiate (1 ), 2 )
203
+
204
+
205
+ def test_get_value ():
206
+ """Tests the get_value method of the Function class.
207
+ Both with respect to return instances and expected behaviour.
208
+ """
209
+ func = Function (lambda x : 2 * x )
210
+ assert isinstance (func .get_value (1 ), int or float )
211
+
212
+
213
+ def test_identity_function ():
214
+ """Tests the identity_function method of the Function class.
215
+ Both with respect to return instances and expected behaviour.
216
+ """
217
+
218
+ func = Function (lambda x : x ** 2 )
219
+ assert isinstance (func .identity_function (), Function )
220
+
221
+
222
+ def test_derivative_function ():
223
+ """Tests the derivative_function method of the Function class.
224
+ Both with respect to return instances and expected behaviour.
225
+ """
226
+ square = Function (lambda x : x ** 2 )
227
+ assert isinstance (square .derivative_function (), Function )
228
+
229
+
230
+ def test_integral ():
231
+ """Tests the integral method of the Function class.
232
+ Both with respect to return instances and expected behaviour.
233
+ """
234
+
235
+ zero_func = Function (0 )
236
+ assert isinstance (zero_func .integral (2 , 4 , numerical = True ), float )
237
+ assert zero_func .integral (2 , 4 , numerical = True ) == 0
238
+
239
+ square = Function (lambda x : x ** 2 )
240
+ assert isinstance
241
+ assert square .integral (2 , 4 , numerical = True ) == - square .integral (
242
+ 4 , 2 , numerical = True
243
+ )
244
+ assert square .integral (2 , 4 , numerical = False ) == - square .integral (
245
+ 4 , 2 , numerical = False
246
+ )
247
+
248
+
249
+ def test_integral_function ():
250
+ """Tests the integral_function method of the Function class.
251
+ Both with respect to return instances and expected behaviour.
252
+ """
253
+ zero_func = Function (0 )
254
+ assert isinstance (zero_func , Function )
255
+
256
+
178
257
@pytest .mark .parametrize ("a" , [- 1 , 0 , 1 ])
179
258
@pytest .mark .parametrize ("b" , [- 1 , 0 , 1 ])
180
259
def test_multivariable_dataset (a , b ):
0 commit comments