Coverage for tests / tests_library / tests_functions / test_first_order_functions.py: 100%

33 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-09 16:40 +0100

1# SPDX-FileCopyrightText: Copyright INRIA 

2# 

3# SPDX-License-Identifier: LGPL-3.0-only 

4# 

5# Copyright INRIA 

6# 

7# This file is part of PhysioBlocks, a library mostly developed by the 

8# [Ananke project-team](https://team.inria.fr/ananke) at INRIA. 

9# 

10# Authors: 

11# - Colin Drieu 

12# - Dominique Chapelle 

13# - François Kimmig 

14# - Philippe Moireau 

15# 

16# PhysioBlocks is free software: you can redistribute it and/or modify it under the 

17# terms of the GNU Lesser General Public License as published by the Free Software 

18# Foundation, version 3 of the License. 

19# 

20# PhysioBlocks is distributed in the hope that it will be useful, but WITHOUT ANY 

21# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 

22# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 

23# 

24# You should have received a copy of the GNU Lesser General Public License along with 

25# PhysioBlocks. If not, see <https://www.gnu.org/licenses/>. 

26 

27import numpy as np 

28import pytest 

29 

30from physioblocks.library.functions.first_order import FirstOrder 

31 

32 

33@pytest.fixture 

34def times_start(): 

35 return np.array([1.0, 3.0]) 

36 

37 

38@pytest.fixture 

39def amplitudes(): 

40 return np.array([2.2, -1.7]) 

41 

42 

43@pytest.fixture 

44def time_constants(): 

45 return np.array([0.8, 1.6]) 

46 

47 

48@pytest.fixture 

49def baseline_value(): 

50 return 1.2 

51 

52 

53class TestFirstOrder: 

54 def test_eval(self, times_start, amplitudes, time_constants, baseline_value): 

55 function_ref = FirstOrder( 

56 times_start, amplitudes, time_constants, baseline_value 

57 ) 

58 assert function_ref.eval(0.0) == pytest.approx(1.2) 

59 assert function_ref.eval(1.0) == pytest.approx(1.2) 

60 assert function_ref.eval(2.0) == pytest.approx(2.7696894469075817) 

61 assert function_ref.eval(2.5) == pytest.approx(3.0626190729411578) 

62 assert function_ref.eval(3.0) == pytest.approx(3.219413003027423) 

63 assert function_ref.eval(4.0) == pytest.approx(2.558205387599064) 

64 assert function_ref.eval(8.0) == pytest.approx(1.7743441722445386) 

65 assert function_ref.eval(100.0) == pytest.approx(1.7) 

66 

67 def test_error(self): 

68 times_start = np.array([1.0, 3.0]) 

69 amplitudes = np.array([2.2, -1.7, 1.4]) 

70 time_constants = np.array([0.8, 1.6]) 

71 baseline_value = 1.2 

72 

73 with pytest.raises(ValueError): 

74 _ = FirstOrder(times_start, amplitudes, time_constants, baseline_value)