Coverage for colour/difference/tests/test__init__.py: 100%

23 statements  

« 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.difference` module.""" 

2 

3from __future__ import annotations 

4 

5import numpy as np 

6 

7from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

8from colour.difference import delta_E 

9from colour.utilities import domain_range_scale 

10 

11__author__ = "Colour Developers" 

12__copyright__ = "Copyright 2013 Colour Developers" 

13__license__ = "BSD-3-Clause - https://opensource.org/licenses/BSD-3-Clause" 

14__maintainer__ = "Colour Developers" 

15__email__ = "colour-developers@colour-science.org" 

16__status__ = "Production" 

17 

18__all__ = [ 

19 "TestDelta_E", 

20] 

21 

22 

23class TestDelta_E: 

24 """Define :func:`colour.difference.delta_E` definition unit tests methods.""" 

25 

26 def test_domain_range_scale_delta_E(self) -> None: 

27 """ 

28 Test :func:`colour.difference.delta_E` definition domain and range 

29 scale support. 

30 """ 

31 

32 Lab_1 = np.array([48.99183622, -0.10561667, 400.65619925]) 

33 Lab_2 = np.array([50.65907324, -0.11671910, 402.82235718]) 

34 

35 m = ("CIE 1976", "CIE 1994", "CIE 2000", "CMC", "DIN99") 

36 v = [delta_E(Lab_1, Lab_2, method) for method in m] 

37 

38 d_r = (("reference", 1), ("1", 0.01), ("100", 1)) 

39 for method, value in zip(m, v, strict=True): 

40 for scale, factor in d_r: 

41 with domain_range_scale(scale): 

42 np.testing.assert_allclose( 

43 delta_E(Lab_1 * factor, Lab_2 * factor, method), 

44 value, 

45 atol=TOLERANCE_ABSOLUTE_TESTS, 

46 )