Coverage for tests / tests_library / tests_blocks / test_capacitances.py: 100%

40 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.computing.quantities import Quantity 

31from physioblocks.library.blocks.capacitances import CBlock, RCBlock, RCRBlock 

32from physioblocks.simulation.state import State 

33from physioblocks.simulation.time_manager import Time 

34from physioblocks.utils.gradient_test_utils import gradient_test_from_model 

35 

36 

37@pytest.fixture 

38def ref_c_block() -> CBlock: 

39 return CBlock( 

40 pressure=Quantity(4500), 

41 capacitance=Quantity(1.1e-3), 

42 time=Time(0.0), 

43 ) 

44 

45 

46class TestCBlock: 

47 def test_check_gradient(self, ref_c_block: CBlock): 

48 state = State() 

49 state["pressure"] = ref_c_block.pressure 

50 ref_c_block.time.update(0.001) 

51 magnitudes = np.array([1e5]) 

52 

53 assert gradient_test_from_model(ref_c_block, state, magnitudes) 

54 

55 

56@pytest.fixture 

57def ref_rc_block() -> RCBlock: 

58 return RCBlock( 

59 pressure_1=Quantity(5230), 

60 pressure_2=Quantity(4624), 

61 resistance=Quantity(1.5e3), 

62 capacitance=Quantity(2.3e-6), 

63 time=Time(0.0), 

64 ) 

65 

66 

67class TestRCBlock: 

68 def test_check_gradient(self, ref_rc_block: RCBlock): 

69 state = State() 

70 state["pressure_1"] = ref_rc_block.pressure_1 

71 state["pressure_2"] = ref_rc_block.pressure_2 

72 ref_rc_block.time.update(0.001) 

73 

74 magnitudes = np.array([1e5, 1e5]) 

75 

76 assert gradient_test_from_model(ref_rc_block, state, magnitudes) 

77 

78 

79@pytest.fixture 

80def ref_rcr_block() -> RCRBlock: 

81 return RCRBlock( 

82 pressure_1=Quantity(5230), 

83 pressure_mid=Quantity(4921), 

84 pressure_2=Quantity(4624), 

85 resistance_1=Quantity(1.5e7), 

86 resistance_2=Quantity(2.1e8), 

87 capacitance=Quantity(2.3e-8), 

88 time=Time(0.0), 

89 ) 

90 

91 

92class TestRCRBlock: 

93 def test_check_gradient(self, ref_rcr_block: RCRBlock): 

94 state = State() 

95 state["pressure_1"] = ref_rcr_block.pressure_1 

96 state["pressure_mid"] = ref_rcr_block.pressure_mid 

97 state["pressure_2"] = ref_rcr_block.pressure_2 

98 ref_rcr_block.time.update(0.001) 

99 

100 magnitudes = np.array([1e4, 1e4, 1e4]) 

101 

102 assert gradient_test_from_model(ref_rcr_block, state, magnitudes)