Coverage for utilities/tests/test_metrics.py: 100%

27 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.utilities.metrics` module.""" 

2 

3from __future__ import annotations 

4 

5import numpy as np 

6 

7from colour.constants import TOLERANCE_ABSOLUTE_TESTS 

8from colour.utilities import metric_mse, metric_psnr 

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

19 "TestMetricPsnr", 

20] 

21 

22 

23class TestMetricMse: 

24 """ 

25 Define :func:`colour.utilities.metrics.metric_mse` definition unit tests 

26 methods. 

27 """ 

28 

29 def test_metric_mse(self) -> None: 

30 """Test :func:`colour.utilities.metrics.metric_mse` definition.""" 

31 

32 a = np.array([0.48222001, 0.31654775, 0.22070353]) 

33 assert metric_mse(a, a) == 0 

34 

35 b = a * 0.9 

36 np.testing.assert_allclose( 

37 metric_mse(a, b), 

38 0.0012714955474297446, 

39 atol=TOLERANCE_ABSOLUTE_TESTS, 

40 ) 

41 

42 b = a * 1.1 

43 np.testing.assert_allclose( 

44 metric_mse(a, b), 

45 0.0012714955474297446, 

46 atol=TOLERANCE_ABSOLUTE_TESTS, 

47 ) 

48 

49 

50class TestMetricPsnr: 

51 """ 

52 Define :func:`colour.utilities.metrics.metric_psnr` definition unit tests 

53 methods. 

54 """ 

55 

56 def test_metric_psnr(self) -> None: 

57 """Test :func:`colour.utilities.metrics.metric_psnr` definition.""" 

58 

59 a = np.array([0.48222001, 0.31654775, 0.22070353]) 

60 assert metric_psnr(a, a) == 0 

61 

62 b = a * 0.9 

63 np.testing.assert_allclose( 

64 metric_psnr(a, b), 

65 28.956851563141299, 

66 atol=TOLERANCE_ABSOLUTE_TESTS, 

67 ) 

68 

69 b = a * 1.1 

70 np.testing.assert_allclose( 

71 metric_psnr(a, b), 

72 28.956851563141296, 

73 atol=TOLERANCE_ABSOLUTE_TESTS, 

74 )