Coverage for tests / tests_config / tests_simulation / test_config_solvers.py: 100%
24 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-09 16:40 +0100
« 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/>.
27import pytest
29from physioblocks.configuration import Configuration
30from physioblocks.configuration.constants import ITERATION_MAX_VAL_ID, TOLERANCE_VAL_ID
31from physioblocks.configuration.functions import load, save
32from physioblocks.registers.type_register import get_registered_type
33from physioblocks.simulation.solvers import NEWTON_SOLVER_TYPE_ID, NewtonSolver
36@pytest.fixture
37def ref_solver_config() -> Configuration:
38 config = Configuration(NEWTON_SOLVER_TYPE_ID)
39 config[TOLERANCE_VAL_ID] = 1e-12
40 config[ITERATION_MAX_VAL_ID] = 2
41 return config
44@pytest.fixture
45def ref_newton_solver() -> NewtonSolver:
46 return NewtonSolver(tolerance=1e-12, iteration_max=2)
49def test_get_solver_config(
50 ref_newton_solver: NewtonSolver, ref_solver_config: Configuration
51):
52 configuration = save(ref_newton_solver)
53 assert ref_solver_config == configuration
56def test_load_solver(ref_solver_config: Configuration):
57 solver_type = get_registered_type(ref_solver_config.label)
58 assert solver_type == NewtonSolver
60 solver: NewtonSolver = load(ref_solver_config)
61 assert solver.iteration_max == 2
62 assert solver.tolerance == pytest.approx(1e-12)