Coverage for volume/tests/test_macadam_limits.py: 100%
32 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-16 22:49 +1300
1"""Define the unit tests for the :mod:`colour.volume.macadam_limits` module."""
3from __future__ import annotations
5from itertools import product
7import numpy as np
9from colour.utilities import ignore_numpy_errors, is_scipy_installed
10from colour.volume import is_within_macadam_limits
12__author__ = "Colour Developers"
13__copyright__ = "Copyright 2013 Colour Developers"
14__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
15__maintainer__ = "Colour Developers"
16__email__ = "colour-developers@colour-science.org"
17__status__ = "Production"
19__all__ = [
20 "TestIsWithinMacadamLimits",
21]
24class TestIsWithinMacadamLimits:
25 """
26 Define :func:`colour.volume.macadam_limits.is_within_macadam_limits`
27 definition unit tests methods.
28 """
30 def test_is_within_macadam_limits(self) -> None:
31 """
32 Test :func:`colour.volume.macadam_limits.is_within_macadam_limits`
33 definition.
34 """
36 assert is_within_macadam_limits(np.array([0.3205, 0.4131, 0.5100]), "A")
38 assert not is_within_macadam_limits(np.array([0.0005, 0.0031, 0.0010]), "A")
40 assert is_within_macadam_limits(np.array([0.4325, 0.3788, 0.1034]), "C")
42 assert not is_within_macadam_limits(np.array([0.0025, 0.0088, 0.0340]), "C")
44 def test_n_dimensional_is_within_macadam_limits(self) -> None:
45 """
46 Test :func:`colour.volume.macadam_limits.is_within_macadam_limits`
47 definition n-dimensional arrays support.
48 """
50 if not is_scipy_installed(): # pragma: no cover
51 return
53 a = np.array([0.3205, 0.4131, 0.5100])
54 b = is_within_macadam_limits(a, "A")
56 a = np.tile(a, (6, 1))
57 b = np.tile(b, 6)
58 np.testing.assert_allclose(is_within_macadam_limits(a, "A"), b)
60 a = np.reshape(a, (2, 3, 3))
61 b = np.reshape(b, (2, 3))
62 np.testing.assert_allclose(is_within_macadam_limits(a, "A"), b)
64 @ignore_numpy_errors
65 def test_nan_is_within_macadam_limits(self) -> None:
66 """
67 Test :func:`colour.volume.macadam_limits.is_within_macadam_limits`
68 definition nan support.
69 """
71 if not is_scipy_installed(): # pragma: no cover
72 return
74 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
75 cases = np.array(list(set(product(cases, repeat=3))))
76 is_within_macadam_limits(cases, "A")