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

18 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.cavity import SphericalCavityBlock 

32from physioblocks.simulation.state import State 

33from physioblocks.simulation.time_manager import Time 

34from physioblocks.utils.gradient_test_utils import gradient_test_from_expression 

35 

36 

37@pytest.fixture 

38def ref_block() -> SphericalCavityBlock: 

39 return SphericalCavityBlock( 

40 disp=Quantity(0.15), 

41 radius=Quantity(0.03), 

42 thickness=Quantity(0.001), 

43 time=Time(0.0), 

44 ) 

45 

46 

47class TestSphericalCavityBlock: 

48 def test_check_gradient(self, ref_block: SphericalCavityBlock): 

49 state = State() 

50 

51 state["disp"] = ref_block.disp 

52 

53 ref_block.time.update(0.001) 

54 magnitudes = np.array([0.01]) 

55 ref_block.initialize() 

56 

57 assert gradient_test_from_expression( 

58 SphericalCavityBlock.fluxes_expressions[1].expression, 

59 ref_block, 

60 state, 

61 magnitudes, 

62 )