Coverage for models/rgb/tests/test_prismatic.py: 100%

63 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.models.rgb.prismatic` module.""" 

2 

3from __future__ import annotations 

4 

5from itertools import product 

6 

7import numpy as np 

8 

9from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

10from colour.models.rgb import Prismatic_to_RGB, RGB_to_Prismatic 

11from colour.utilities import domain_range_scale, ignore_numpy_errors 

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 "TestRGB_to_Prismatic", 

22 "TestPrismatic_to_RGB", 

23] 

24 

25 

26class TestRGB_to_Prismatic: 

27 """ 

28 Define :func:`colour.models.rgb.prismatic.TestRGB_to_Prismatic` definition 

29 unit tests methods. 

30 """ 

31 

32 def test_RGB_to_Prismatic(self) -> None: 

33 """Test :func:`colour.models.rgb.prismatic.RGB_to_Prismatic` definition.""" 

34 

35 np.testing.assert_allclose( 

36 RGB_to_Prismatic(np.array([0.0, 0.0, 0.0])), 

37 np.array([0.0, 0.0, 0.0, 0.0]), 

38 atol=TOLERANCE_ABSOLUTE_TESTS, 

39 ) 

40 

41 np.testing.assert_allclose( 

42 RGB_to_Prismatic(np.array([0.25, 0.50, 0.75])), 

43 np.array([0.7500000, 0.1666667, 0.3333333, 0.5000000]), 

44 atol=TOLERANCE_ABSOLUTE_TESTS, 

45 ) 

46 

47 def test_n_dimensional_RGB_to_Prismatic(self) -> None: 

48 """ 

49 Test :func:`colour.models.rgb.prismatic.RGB_to_Prismatic` definition 

50 n-dimensional support. 

51 """ 

52 

53 RGB = np.array([0.25, 0.50, 0.75]) 

54 Lrgb = RGB_to_Prismatic(RGB) 

55 

56 RGB = np.tile(RGB, (6, 1)) 

57 Lrgb = np.tile(Lrgb, (6, 1)) 

58 np.testing.assert_allclose( 

59 RGB_to_Prismatic(RGB), Lrgb, atol=TOLERANCE_ABSOLUTE_TESTS 

60 ) 

61 

62 RGB = np.reshape(RGB, (2, 3, 3)) 

63 Lrgb = np.reshape(Lrgb, (2, 3, 4)) 

64 np.testing.assert_allclose( 

65 RGB_to_Prismatic(RGB), Lrgb, atol=TOLERANCE_ABSOLUTE_TESTS 

66 ) 

67 

68 def test_domain_range_scale_RGB_to_Prismatic(self) -> None: 

69 """ 

70 Test :func:`colour.models.rgb.prismatic.RGB_to_Prismatic` definition 

71 domain and range scale support. 

72 """ 

73 

74 RGB = np.array([0.25, 0.50, 0.75]) 

75 Lrgb = RGB_to_Prismatic(RGB) 

76 

77 d_r = (("reference", 1), ("1", 1), ("100", 100)) 

78 for scale, factor in d_r: 

79 with domain_range_scale(scale): 

80 np.testing.assert_allclose( 

81 RGB_to_Prismatic(RGB * factor), 

82 Lrgb * factor, 

83 atol=TOLERANCE_ABSOLUTE_TESTS, 

84 ) 

85 

86 @ignore_numpy_errors 

87 def test_nan_RGB_to_Prismatic(self) -> None: 

88 """ 

89 Test :func:`colour.models.rgb.prismatic.RGB_to_Prismatic` definition 

90 nan support. 

91 """ 

92 

93 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] 

94 cases = np.array(list(set(product(cases, repeat=3)))) 

95 RGB_to_Prismatic(cases) 

96 

97 

98class TestPrismatic_to_RGB: 

99 """ 

100 Define :func:`colour.models.rgb.prismatic.Prismatic_to_RGB` definition 

101 unit tests methods. 

102 """ 

103 

104 def test_Prismatic_to_RGB(self) -> None: 

105 """Test :func:`colour.models.rgb.prismatic.Prismatic_to_RGB` definition.""" 

106 

107 np.testing.assert_allclose( 

108 Prismatic_to_RGB(np.array([0.0, 0.0, 0.0, 0.0])), 

109 np.array([0.0, 0.0, 0.0]), 

110 atol=TOLERANCE_ABSOLUTE_TESTS, 

111 ) 

112 

113 np.testing.assert_allclose( 

114 Prismatic_to_RGB(np.array([0.7500000, 0.1666667, 0.3333333, 0.5000000])), 

115 np.array([0.25, 0.50, 0.75]), 

116 atol=TOLERANCE_ABSOLUTE_TESTS, 

117 ) 

118 

119 def test_n_dimensional_Prismatic_to_RGB(self) -> None: 

120 """ 

121 Test :func:`colour.models.rgb.prismatic.Prismatic_to_RGB` definition 

122 n-dimensional support. 

123 """ 

124 

125 Lrgb = np.array([0.7500000, 0.1666667, 0.3333333, 0.5000000]) 

126 RGB = Prismatic_to_RGB(Lrgb) 

127 

128 Lrgb = np.tile(Lrgb, (6, 1)) 

129 RGB = np.tile(RGB, (6, 1)) 

130 np.testing.assert_allclose( 

131 Prismatic_to_RGB(Lrgb), RGB, atol=TOLERANCE_ABSOLUTE_TESTS 

132 ) 

133 

134 Lrgb = np.reshape(Lrgb, (2, 3, 4)) 

135 RGB = np.reshape(RGB, (2, 3, 3)) 

136 np.testing.assert_allclose( 

137 Prismatic_to_RGB(Lrgb), RGB, atol=TOLERANCE_ABSOLUTE_TESTS 

138 ) 

139 

140 def test_domain_range_scale_Prismatic_to_RGB(self) -> None: 

141 """ 

142 Test :func:`colour.models.rgb.prismatic.Prismatic_to_RGB` definition 

143 domain and range scale support. 

144 """ 

145 

146 Lrgb = np.array([0.7500000, 0.1666667, 0.3333333, 0.5000000]) 

147 RGB = Prismatic_to_RGB(Lrgb) 

148 

149 d_r = (("reference", 1), ("1", 1), ("100", 100)) 

150 for scale, factor in d_r: 

151 with domain_range_scale(scale): 

152 np.testing.assert_allclose( 

153 Prismatic_to_RGB(Lrgb * factor), 

154 RGB * factor, 

155 atol=TOLERANCE_ABSOLUTE_TESTS, 

156 ) 

157 

158 @ignore_numpy_errors 

159 def test_nan_Prismatic_to_RGB(self) -> None: 

160 """ 

161 Test :func:`colour.models.rgb.prismatic.Prismatic_to_RGB` definition 

162 nan support. 

163 """ 

164 

165 cases = [-1.0, 0.0, 1.0, -np.inf, np.inf, np.nan] 

166 cases = np.array(list(set(product(cases, repeat=3)))) 

167 Prismatic_to_RGB(cases)