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

1"""

2 Define the unit tests for the

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

4"""

5

6 import numpy as np

7

8 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

9 from colour.models.rgb.transfer_functions import linear_function

10 from 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

24 class TestLinearFunction:

25 """

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

27 linear_function` definition unit tests methods.

28 """

29

30 def test_linear_function(self) -> None:

31 """

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

33 linear_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.\

45 linear_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.\

73 linear_function` definition nan support.

74 """

75

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

77 linear_function(cases)