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

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

2

3 from __future__ import annotations

4

5 import numpy as np

6

7 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

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

23 class 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

50 class 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 )