Coverage for tests/test_numerical.py: 0%

1 from hypothesis import given, strategies as st

2 import numpy as np

3

4 import swiift.lib.numerical as numerical

5 from tests.utils import float_kw

6

7

8@st.composite

9 def make_use_an_sol_params(

10 draw: st.DrawFn,

11) -> tuple[bool | None, float, tuple[np.ndarray, float] | None, bool | None]:

12 an_sol = draw(st.booleans() | st.none())

13 length = draw(st.floats(-100, 100, **float_kw))

14 _mean = draw(

15 st.lists(st.floats(-100, 100, **float_kw), min_size=1, max_size=5) | st.none()

16 )

17 if _mean is not None:

18 growth_params = np.array(_mean), 1.0 # value of std does not matter

19 else:

20 growth_params = None

21 linear_curvature = draw(st.booleans() | st.none())

22 return an_sol, length, growth_params, linear_curvature

23

24

25@given(params=make_use_an_sol_params())

26 def test_use_an_sol(params):

27 an_sol, length, growth_params, linear_curvature = params

28 use_an_sol = numerical._use_an_sol(*params)

29

30 if an_sol is not None:

31 assert use_an_sol == an_sol

32 else:

33 if growth_params is None:

34 if linear_curvature is None:

35 assert use_an_sol is True

36 else:

37 assert use_an_sol == linear_curvature

38 else:

39 if np.any(growth_params[0] < length):

40 assert use_an_sol is False

41 else:

42 if linear_curvature is None:

43 assert use_an_sol is True

44 else:

45 assert use_an_sol is linear_curvature