Coverage for difference/tests/test_din99.py: 100%
46 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.difference.din99` module."""
3from __future__ import annotations
5from itertools import product
7import numpy as np
9from colour.constants import TOLERANCE_ABSOLUTE_TESTS
10from colour.difference import delta_E_DIN99
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 "TestDelta_E_DIN99",
22]
25class TestDelta_E_DIN99:
26 """
27 Define :func:`colour.difference.din99.delta_E_DIN99` definition unit
28 tests methods.
29 """
31 def test_delta_E_DIN99(self) -> None:
32 """Test :func:`colour.difference.din99.delta_E_DIN99` definition."""
34 np.testing.assert_allclose(
35 delta_E_DIN99(
36 np.array([60.25740000, -34.00990000, 36.26770000]),
37 np.array([60.46260000, -34.17510000, 39.43870000]),
38 ),
39 1.177216620111552,
40 atol=TOLERANCE_ABSOLUTE_TESTS,
41 )
43 np.testing.assert_allclose(
44 delta_E_DIN99(
45 np.array([63.01090000, -31.09610000, -5.86630000]),
46 np.array([62.81870000, -29.79460000, -4.08640000]),
47 ),
48 0.987529977993114,
49 atol=TOLERANCE_ABSOLUTE_TESTS,
50 )
52 np.testing.assert_allclose(
53 delta_E_DIN99(
54 np.array([35.08310000, -44.11640000, 3.79330000]),
55 np.array([35.02320000, -40.07160000, 1.59010000]),
56 ),
57 1.535894757971742,
58 atol=TOLERANCE_ABSOLUTE_TESTS,
59 )
61 np.testing.assert_allclose(
62 delta_E_DIN99(
63 np.array([60.25740000, -34.00990000, 36.26770000]),
64 np.array([60.46260000, -34.17510000, 39.43870000]),
65 textiles=True,
66 ),
67 1.215652775586509,
68 atol=TOLERANCE_ABSOLUTE_TESTS,
69 )
71 np.testing.assert_allclose(
72 delta_E_DIN99(
73 np.array([63.01090000, -31.09610000, -5.86630000]),
74 np.array([62.81870000, -29.79460000, -4.08640000]),
75 textiles=True,
76 ),
77 1.025997138865984,
78 atol=TOLERANCE_ABSOLUTE_TESTS,
79 )
81 np.testing.assert_allclose(
82 delta_E_DIN99(
83 np.array([35.08310000, -44.11640000, 3.79330000]),
84 np.array([35.02320000, -40.07160000, 1.59010000]),
85 textiles=True,
86 ),
87 1.539922810033725,
88 atol=TOLERANCE_ABSOLUTE_TESTS,
89 )
91 def test_n_dimensional_delta_E_DIN99(self) -> None:
92 """
93 Test :func:`colour.difference.din99.delta_E_DIN99` definition
94 n-dimensional arrays support.
95 """
97 Lab_1 = np.array([60.25740000, -34.00990000, 36.26770000])
98 Lab_2 = np.array([60.46260000, -34.17510000, 39.43870000])
99 delta_E = delta_E_DIN99(Lab_1, Lab_2)
101 Lab_1 = np.tile(Lab_1, (6, 1))
102 Lab_2 = np.tile(Lab_2, (6, 1))
103 delta_E = np.tile(delta_E, 6)
104 np.testing.assert_allclose(
105 delta_E_DIN99(Lab_1, Lab_2), delta_E, atol=TOLERANCE_ABSOLUTE_TESTS
106 )
108 Lab_1 = np.reshape(Lab_1, (2, 3, 3))
109 Lab_2 = np.reshape(Lab_2, (2, 3, 3))
110 delta_E = np.reshape(delta_E, (2, 3))
111 np.testing.assert_allclose(
112 delta_E_DIN99(Lab_1, Lab_2), delta_E, atol=TOLERANCE_ABSOLUTE_TESTS
113 )
115 def test_domain_range_scale_delta_E_DIN99(self) -> None:
116 """
117 Test :func:`colour.difference.din99.delta_E_DIN99` definition
118 domain and range scale support.
119 """
121 Lab_1 = np.array([60.25740000, -34.00990000, 36.26770000])
122 Lab_2 = np.array([60.46260000, -34.17510000, 39.43870000])
123 delta_E = delta_E_DIN99(Lab_1, Lab_2)
125 d_r = (("reference", 1), ("1", 0.01), ("100", 1))
126 for scale, factor in d_r:
127 with domain_range_scale(scale):
128 np.testing.assert_allclose(
129 delta_E_DIN99(Lab_1 * factor, Lab_2 * factor),
130 delta_E,
131 atol=TOLERANCE_ABSOLUTE_TESTS,
132 )
134 @ignore_numpy_errors
135 def test_nan_delta_E_DIN99(self) -> None:
136 """
137 Test :func:`colour.difference.din99.delta_E_DIN99` definition nan
138 support.
139 """
141 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan]
142 cases = np.array(list(set(product(cases, repeat=3))))
143 delta_E_DIN99(cases, cases)