Coverage for colour/models/rgb/transfer_functions/tests/test_linear.py: 100%

32 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-11-15 19:01 +1300

1""" 

2Define the unit tests for the 

3:mod:`colour.models.rgb.transfer_functions.linear` module. 

4""" 

5 

6import numpy as np 

7 

8from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

9from colour.models.rgb.transfer_functions import linear_function 

10from colour.utilities import ignore_numpy_errors 

11 

12__author__ = "Colour Developers" 

13__copyright__ = "Copyright 2013 Colour Developers" 

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

15__maintainer__ = "Colour Developers" 

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

17__status__ = "Production" 

18 

19__all__ = [ 

20 "TestLinearFunction", 

21] 

22 

23 

24class TestLinearFunction: 

25 """ 

26 Define :func:`colour.models.rgb.transfer_functions.linear.\ 

27linear_function` definition unit tests methods. 

28 """ 

29 

30 def test_linear_function(self) -> None: 

31 """ 

32 Test :func:`colour.models.rgb.transfer_functions.linear.\ 

33linear_function` definition. 

34 """ 

35 

36 assert linear_function(0.0) == 0.0 

37 

38 assert linear_function(0.18) == 0.18 

39 

40 assert linear_function(1.0) == 1.0 

41 

42 def test_n_dimensional_linear_function(self) -> None: 

43 """ 

44 Test :func:`colour.models.rgb.transfer_functions.linear.\ 

45linear_function` definition n-dimensional arrays support. 

46 """ 

47 

48 a = 0.18 

49 a_p = linear_function(a) 

50 

51 a = np.tile(a, 6) 

52 a_p = np.tile(a_p, 6) 

53 np.testing.assert_allclose( 

54 linear_function(a), a_p, atol=TOLERANCE_ABSOLUTE_TESTS 

55 ) 

56 

57 a = np.reshape(a, (2, 3)) 

58 a_p = np.reshape(a_p, (2, 3)) 

59 np.testing.assert_allclose( 

60 linear_function(a), a_p, atol=TOLERANCE_ABSOLUTE_TESTS 

61 ) 

62 

63 a = np.reshape(a, (2, 3, 1)) 

64 a_p = np.reshape(a_p, (2, 3, 1)) 

65 np.testing.assert_allclose( 

66 linear_function(a), a_p, atol=TOLERANCE_ABSOLUTE_TESTS 

67 ) 

68 

69 @ignore_numpy_errors 

70 def test_nan_linear_function(self) -> None: 

71 """ 

72 Test :func:`colour.models.rgb.transfer_functions.linear.\ 

73linear_function` definition nan support. 

74 """ 

75 

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

77 linear_function(cases)