Coverage for graph/tests/test_common.py: 97%

38 statements  

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

2 

3from __future__ import annotations 

4 

5import unittest 

6 

7import numpy as np 

8 

9from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

10from colour.graph import colourspace_model_to_reference 

11from colour.models import COLOURSPACE_MODELS_DOMAIN_RANGE_SCALE_1_TO_REFERENCE 

12 

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" 

19 

20__all__ = [ 

21 "TestColourspaceModelToReference", 

22] 

23 

24 

25class TestColourspaceModelToReference(unittest.TestCase): 

26 """ 

27 Define :func:`colour.graph.common.colourspace_model_to_reference` 

28 definition unit tests methods. 

29 """ 

30 

31 def test_colourspace_model_to_reference(self) -> None: 

32 """ 

33 Test :func:`colour.graph.common.colourspace_model_to_reference` 

34 definition. 

35 """ 

36 

37 Lab_1 = np.array([0.41527875, 0.52638583, 0.26923179]) 

38 Lab_reference = colourspace_model_to_reference(Lab_1, "CIE Lab") 

39 np.testing.assert_allclose( 

40 Lab_reference, 

41 np.array([41.52787529, 52.63858304, 26.92317922]), 

42 atol=TOLERANCE_ABSOLUTE_TESTS, 

43 ) 

44 

45 Luv_1 = np.array([0.41527875, 0.52638583, 0.26923179]) 

46 Luv_reference = colourspace_model_to_reference(Luv_1, "CIE Luv") 

47 np.testing.assert_allclose( 

48 Luv_reference, 

49 np.array([41.52787529, 52.63858304, 26.92317922]), 

50 atol=TOLERANCE_ABSOLUTE_TESTS, 

51 ) 

52 

53 CAM02LCD_1 = np.array([0.5, 0.5, 0.5]) 

54 CAM02LCD_reference = colourspace_model_to_reference(CAM02LCD_1, "CAM02LCD") 

55 np.testing.assert_allclose( 

56 CAM02LCD_reference, 

57 np.array([50.0, 50.0, 50.0]), 

58 atol=TOLERANCE_ABSOLUTE_TESTS, 

59 ) 

60 

61 XYZ_1 = np.array([0.20654008, 0.12197225, 0.05136952]) 

62 XYZ_reference = colourspace_model_to_reference(XYZ_1, "CIE XYZ") 

63 np.testing.assert_allclose( 

64 XYZ_reference, 

65 np.array([0.20654008, 0.12197225, 0.05136952]), 

66 atol=TOLERANCE_ABSOLUTE_TESTS, 

67 ) 

68 

69 RGB_1 = np.array([0.5, 0.3, 0.8]) 

70 RGB_reference = colourspace_model_to_reference(RGB_1, "RGB") 

71 np.testing.assert_allclose( 

72 RGB_reference, 

73 np.array([0.5, 0.3, 0.8]), 

74 atol=TOLERANCE_ABSOLUTE_TESTS, 

75 ) 

76 

77 value_1 = np.array([0.5, 0.5, 0.5]) 

78 value_reference = colourspace_model_to_reference(value_1, "Invalid Model") 

79 np.testing.assert_allclose( 

80 value_reference, 

81 value_1, 

82 atol=TOLERANCE_ABSOLUTE_TESTS, 

83 ) 

84 

85 for model in COLOURSPACE_MODELS_DOMAIN_RANGE_SCALE_1_TO_REFERENCE: 

86 with self.subTest(model=model): 

87 np.testing.assert_allclose( 

88 colourspace_model_to_reference(value_1, model), 

89 value_1 

90 * COLOURSPACE_MODELS_DOMAIN_RANGE_SCALE_1_TO_REFERENCE[model], 

91 atol=TOLERANCE_ABSOLUTE_TESTS, 

92 err_msg=f"Mismatch for model: {model}", 

93 ) 

94 

95 

96if __name__ == "__main__": 

97 unittest.main()