-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
268deed
commit 40eb8da
Showing
1 changed file
with
37 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
) |