|
1 | | -from windpowerlib.tools import smallest_difference |
| 1 | +from windpowerlib.tools import smallest_difference, linear_extra_interpolation |
2 | 2 | import pandas as pd |
| 3 | +from pandas.util.testing import assert_series_equal |
3 | 4 |
|
4 | 5 |
|
5 | 6 | class TestTools: |
@@ -27,3 +28,32 @@ def test_smallest_difference(self): |
27 | 28 | expected_output = (100, 4.0) |
28 | 29 | parameters['comp_value'] = 90 |
29 | 30 | assert smallest_difference(**parameters) == expected_output |
| 31 | + |
| 32 | + def test_linear_extra_interpolation(self): |
| 33 | + weather = pd.DataFrame(data={'v_wind': [4.0, 5.0, 6.0]}, |
| 34 | + index=[100, 150, 200]) |
| 35 | + weather_pd_series = pd.DataFrame(data={'v_wind': [ |
| 36 | + pd.Series(data=[4.0, 5.0, 6.0]), |
| 37 | + pd.Series(data=[8.0, 10.0, 14.0]), |
| 38 | + pd.Series(data=[16.0, 20.0, 28.0])]}, index=[100, 150, 200]) |
| 39 | + # TODO: test v_wind as np.array |
| 40 | + |
| 41 | + # Entries in column v_wind are float |
| 42 | + expected_output = 4.0 |
| 43 | + assert (linear_extra_interpolation(weather, 100, 'v_wind') == |
| 44 | + expected_output) |
| 45 | + expected_output = 5.5 |
| 46 | + assert (linear_extra_interpolation(weather, 175, 'v_wind') == |
| 47 | + expected_output) |
| 48 | + expected_output = 7.0 |
| 49 | + assert (linear_extra_interpolation(weather, 250, 'v_wind') == |
| 50 | + expected_output) |
| 51 | + expected_output = 3.0 |
| 52 | + assert (linear_extra_interpolation(weather, 50, 'v_wind') == |
| 53 | + expected_output) |
| 54 | + |
| 55 | + # Entries in column v_wind are pd.Series |
| 56 | + expected_output = pd.Series(data=[4.0, 5.0, 6.0]) |
| 57 | + assert_series_equal(linear_extra_interpolation(weather_pd_series, |
| 58 | + 100, 'v_wind'), |
| 59 | + expected_output) |
0 commit comments