Coverage for tests / tests_utils / test_math_utils.py: 100%
25 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 numpy as np
28import pytest
30import physioblocks.utils.math_utils as math_utils
33@pytest.fixture
34def a():
35 return 1.3
38@pytest.fixture
39def b(a: float):
40 return a + 1e-9
43class TestMathHelper:
44 def test_exp_diff(self, a: float, b: float):
45 exp_diff_expected = np.exp(a) - np.exp(b)
46 exp_diff = math_utils.exp_diff(a, b, a - b)
47 assert exp_diff == pytest.approx(exp_diff_expected, 1e-16)
49 def test_power_diff_n_pos(self, a: float, b: float):
50 power_diff_expected = np.pow(a, 4) - np.pow(b, 4)
51 power_diff = math_utils.power_diff(a, b, a - b, 4)
53 assert power_diff == pytest.approx(power_diff_expected, 1e-16)
55 def test_power_diff_n_neg(self, a: float, b: float):
56 power_diff_expected = np.pow(a, -3) - np.pow(b, -3)
57 power_diff = math_utils.power_diff(a, b, a - b, -3)
59 assert power_diff == pytest.approx(power_diff_expected, 1e-16)
61 def test_power_diff_n_nul(self, a: float, b: float):
62 power_diff = math_utils.power_diff(a, b, a - b, 0)
64 assert power_diff == pytest.approx(0.0, 1e-16)