Coverage for colour/models/tests/test_igpgtg.py: 100%
65 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
1"""Define the unit tests for the :mod:`colour.models.igpgtg` module."""
3from __future__ import annotations
5from itertools import product
7import numpy as np
9from colour.constants import TOLERANCE_ABSOLUTE_TESTS
10from colour.models import IgPgTg_to_XYZ, XYZ_to_IgPgTg
11from colour.utilities import domain_range_scale, ignore_numpy_errors
13__author__ = "Colour Developers"
14__copyright__ = "Copyright 2013 Colour Developers"
15__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause"
16__maintainer__ = "Colour Developers"
17__email__ = "colour-developers@colour-science.org"
18__status__ = "Production"
20__all__ = [
21 "TestXYZ_to_IgPgTg",
22 "TestIgPgTg_to_XYZ",
23]
26class TestXYZ_to_IgPgTg:
27 """
28 Define :func:`colour.models.igpgtg.XYZ_to_IgPgTg` definition unit tests
29 methods.
30 """
32 def test_XYZ_to_IgPgTg(self) -> None:
33 """Test :func:`colour.models.igpgtg.XYZ_to_IgPgTg` definition."""
35 np.testing.assert_allclose(
36 XYZ_to_IgPgTg(np.array([0.20654008, 0.12197225, 0.05136952])),
37 np.array([0.42421258, 0.18632491, 0.10689223]),
38 atol=TOLERANCE_ABSOLUTE_TESTS,
39 )
41 np.testing.assert_allclose(
42 XYZ_to_IgPgTg(np.array([0.14222010, 0.23042768, 0.10495772])),
43 np.array([0.50912820, -0.14804331, 0.11921472]),
44 atol=TOLERANCE_ABSOLUTE_TESTS,
45 )
47 np.testing.assert_allclose(
48 XYZ_to_IgPgTg(np.array([0.07818780, 0.06157201, 0.28099326])),
49 np.array([0.29095152, -0.04057508, -0.18220795]),
50 atol=TOLERANCE_ABSOLUTE_TESTS,
51 )
53 def test_n_dimensional_XYZ_to_IgPgTg(self) -> None:
54 """
55 Test :func:`colour.models.igpgtg.XYZ_to_IgPgTg` definition
56 n-dimensional support.
57 """
59 XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
60 IgPgTg = XYZ_to_IgPgTg(XYZ)
62 XYZ = np.tile(XYZ, (6, 1))
63 IgPgTg = np.tile(IgPgTg, (6, 1))
64 np.testing.assert_allclose(
65 XYZ_to_IgPgTg(XYZ), IgPgTg, atol=TOLERANCE_ABSOLUTE_TESTS
66 )
68 XYZ = np.reshape(XYZ, (2, 3, 3))
69 IgPgTg = np.reshape(IgPgTg, (2, 3, 3))
70 np.testing.assert_allclose(
71 XYZ_to_IgPgTg(XYZ), IgPgTg, atol=TOLERANCE_ABSOLUTE_TESTS
72 )
74 def test_domain_range_scale_XYZ_to_IgPgTg(self) -> None:
75 """
76 Test :func:`colour.models.igpgtg.XYZ_to_IgPgTg` definition domain and
77 range scale support.
78 """
80 XYZ = np.array([0.20654008, 0.12197225, 0.05136952])
81 IgPgTg = XYZ_to_IgPgTg(XYZ)
83 d_r = (("reference", 1), ("1", 1), ("100", 100))
84 for scale, factor in d_r:
85 with domain_range_scale(scale):
86 np.testing.assert_allclose(
87 XYZ_to_IgPgTg(XYZ * factor),
88 IgPgTg * factor,
89 atol=TOLERANCE_ABSOLUTE_TESTS,
90 )
92 @ignore_numpy_errors
93 def test_nan_XYZ_to_IgPgTg(self) -> None:
94 """
95 Test :func:`colour.models.igpgtg.XYZ_to_IgPgTg` definition nan
96 support.
97 """
99 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
100 cases = np.array(list(set(product(cases, repeat=3))))
101 XYZ_to_IgPgTg(cases)
104class TestIgPgTg_to_XYZ:
105 """
106 Define :func:`colour.models.igpgtg.IgPgTg_to_XYZ` definition unit tests
107 methods.
108 """
110 def test_IgPgTg_to_XYZ(self) -> None:
111 """Test :func:`colour.models.igpgtg.IgPgTg_to_XYZ` definition."""
113 np.testing.assert_allclose(
114 IgPgTg_to_XYZ(np.array([0.42421258, 0.18632491, 0.10689223])),
115 np.array([0.20654008, 0.12197225, 0.05136952]),
116 atol=TOLERANCE_ABSOLUTE_TESTS,
117 )
119 np.testing.assert_allclose(
120 IgPgTg_to_XYZ(np.array([0.50912820, -0.14804331, 0.11921472])),
121 np.array([0.14222010, 0.23042768, 0.10495772]),
122 atol=TOLERANCE_ABSOLUTE_TESTS,
123 )
125 np.testing.assert_allclose(
126 IgPgTg_to_XYZ(np.array([0.29095152, -0.04057508, -0.18220795])),
127 np.array([0.07818780, 0.06157201, 0.28099326]),
128 atol=TOLERANCE_ABSOLUTE_TESTS,
129 )
131 def test_n_dimensional_IgPgTg_to_XYZ(self) -> None:
132 """
133 Test :func:`colour.models.igpgtg.IgPgTg_to_XYZ` definition
134 n-dimensional support.
135 """
137 IgPgTg = np.array([0.42421258, 0.18632491, 0.10689223])
138 XYZ = IgPgTg_to_XYZ(IgPgTg)
140 IgPgTg = np.tile(IgPgTg, (6, 1))
141 XYZ = np.tile(XYZ, (6, 1))
142 np.testing.assert_allclose(
143 IgPgTg_to_XYZ(IgPgTg), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS
144 )
146 IgPgTg = np.reshape(IgPgTg, (2, 3, 3))
147 XYZ = np.reshape(XYZ, (2, 3, 3))
148 np.testing.assert_allclose(
149 IgPgTg_to_XYZ(IgPgTg), XYZ, atol=TOLERANCE_ABSOLUTE_TESTS
150 )
152 def test_domain_range_scale_IgPgTg_to_XYZ(self) -> None:
153 """
154 Test :func:`colour.models.igpgtg.IgPgTg_to_XYZ` definition domain and
155 range scale support.
156 """
158 IgPgTg = np.array([0.42421258, 0.18632491, 0.10689223])
159 XYZ = IgPgTg_to_XYZ(IgPgTg)
161 d_r = (("reference", 1), ("1", 1), ("100", 100))
162 for scale, factor in d_r:
163 with domain_range_scale(scale):
164 np.testing.assert_allclose(
165 IgPgTg_to_XYZ(IgPgTg * factor),
166 XYZ * factor,
167 atol=TOLERANCE_ABSOLUTE_TESTS,
168 )
170 @ignore_numpy_errors
171 def test_nan_IgPgTg_to_XYZ(self) -> None:
172 """
173 Test :func:`colour.models.igpgtg.IgPgTg_to_XYZ` definition nan
174 support.
175 """
177 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
178 cases = np.array(list(set(product(cases, repeat=3))))
179 IgPgTg_to_XYZ(cases)