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

16 statements  

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

1"""Define the unit tests for the :mod:`colour.contrast` module.""" 

2 

3from __future__ import annotations 

4 

5import numpy as np 

6 

7from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

8from colour.contrast import contrast_sensitivity_function 

9 

10__author__ = "Colour Developers" 

11__copyright__ = "Copyright 2013 Colour Developers" 

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

13__maintainer__ = "Colour Developers" 

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

15__status__ = "Production" 

16 

17__all__ = [ 

18 "TestContrastSensitivityFunction", 

19] 

20 

21 

22class TestContrastSensitivityFunction: 

23 """ 

24 Define :func:`colour.contrast.contrast_sensitivity_function` definition 

25 unit tests methods. 

26 """ 

27 

28 def test_contrast_sensitivity_function(self) -> None: 

29 """Test :func:`colour.contrast.contrast_sensitivity_function` definition.""" 

30 

31 # Test default method (Barten 1999) 

32 np.testing.assert_allclose( 

33 contrast_sensitivity_function( 

34 u=4, 

35 sigma=0.01, 

36 E=65, 

37 X_0=60, 

38 X_max=12, 

39 Y_0=60, 

40 Y_max=12, 

41 p=1.2 * 10**6, 

42 ), 

43 352.761342126727020, 

44 atol=TOLERANCE_ABSOLUTE_TESTS, 

45 ) 

46 

47 # Test explicit Barten 1999 method with different parameters 

48 np.testing.assert_allclose( 

49 contrast_sensitivity_function( 

50 "Barten 1999", 

51 u=8, 

52 sigma=0.01, 

53 E=65, 

54 X_0=60, 

55 X_max=12, 

56 Y_0=60, 

57 Y_max=12, 

58 p=1.2 * 10**6, 

59 ), 

60 177.706338840717340, 

61 atol=TOLERANCE_ABSOLUTE_TESTS, 

62 ) 

63 

64 # Test with another set of parameters 

65 np.testing.assert_allclose( 

66 contrast_sensitivity_function( 

67 u=20, 

68 sigma=0.01, 

69 E=65, 

70 X_0=60, 

71 X_max=12, 

72 Y_0=60, 

73 Y_max=12, 

74 p=1.2 * 10**6, 

75 ), 

76 37.455090830648620, 

77 atol=TOLERANCE_ABSOLUTE_TESTS, 

78 )