From 40eb8da4a65081ccadb516a8cb0751a2d263245a Mon Sep 17 00:00:00 2001 From: Leonardo Schwarz Date: Thu, 17 Oct 2024 09:21:44 +0200 Subject: [PATCH] modernize --- .../calibration/models/test_constant_model.py | 73 ++++++++++--------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/tests/unit/calibration/models/test_constant_model.py b/tests/unit/calibration/models/test_constant_model.py index 63fde0c..2e14000 100644 --- a/tests/unit/calibration/models/test_constant_model.py +++ b/tests/unit/calibration/models/test_constant_model.py @@ -1,50 +1,51 @@ -import unittest - import numpy as np +import pytest from depiction.calibration.models.constant_model import ConstantModel -class TestConstantModel(unittest.TestCase): - def test_coef(self) -> None: - np.testing.assert_array_equal(np.array([1234]), ConstantModel(value=1234).coef) +def test_coef() -> None: + np.testing.assert_array_equal(np.array([1234]), ConstantModel(value=1234).coef) + + +def test_value() -> None: + assert 1234 == ConstantModel(value=1234).value + + +def test_is_zero() -> None: + assert not ConstantModel(value=1234).is_zero + assert ConstantModel(value=0).is_zero + assert not ConstantModel(value=1e-12).is_zero + - def test_value(self) -> None: - self.assertEqual(1234, ConstantModel(value=1234).value) +def test_predict() -> None: + np.testing.assert_array_equal( + np.array([1234, 1234]), + ConstantModel(value=1234).predict([1, 2]), + ) - def test_is_zero(self) -> None: - self.assertFalse(ConstantModel(value=1234).is_zero) - self.assertTrue(ConstantModel(value=0).is_zero) - self.assertFalse(ConstantModel(value=1e-12).is_zero) - def test_predict(self) -> None: - np.testing.assert_array_equal( - np.array([1234, 1234]), - ConstantModel(value=1234).predict([1, 2]), - ) +def test_identity() -> None: + with pytest.raises(ValueError): + ConstantModel.identity() - def test_identity(self) -> None: - with self.assertRaises(ValueError): - ConstantModel.identity() - def test_zero(self) -> None: - np.testing.assert_array_equal( - np.array([0]), - ConstantModel.zero().coef, - ) +def test_zero() -> None: + np.testing.assert_array_equal( + np.array([0]), + ConstantModel.zero().coef, + ) - def test_fit_mean(self) -> None: - np.testing.assert_array_equal( - 50, - ConstantModel.fit_mean(np.array([1, 2]), np.array([10, 20, 120])).value, - ) - def test_fit_median(self) -> None: - np.testing.assert_array_equal( - 20, - ConstantModel.fit_median(np.array([1, 2]), np.array([10, 20, 120])).value, - ) +def test_fit_mean() -> None: + np.testing.assert_array_equal( + 50, + ConstantModel.fit_mean(np.array([1, 2]), np.array([10, 20, 120])).value, + ) -if __name__ == "__main__": - unittest.main() +def test_fit_median() -> None: + np.testing.assert_array_equal( + 20, + ConstantModel.fit_median(np.array([1, 2]), np.array([10, 20, 120])).value, + )