Coverage for colour/volume/tests/test_macadam_limits.py: 100%

32 statements  

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

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

2 

3from __future__ import annotations 

4 

5from itertools import product 

6 

7import numpy as np 

8 

9from colour.utilities import ignore_numpy_errors, is_scipy_installed 

10from colour.volume import is_within_macadam_limits 

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

21] 

22 

23 

24class TestIsWithinMacadamLimits: 

25 """ 

26 Define :func:`colour.volume.macadam_limits.is_within_macadam_limits` 

27 definition unit tests methods. 

28 """ 

29 

30 def test_is_within_macadam_limits(self) -> None: 

31 """ 

32 Test :func:`colour.volume.macadam_limits.is_within_macadam_limits` 

33 definition. 

34 """ 

35 

36 assert is_within_macadam_limits(np.array([0.3205, 0.4131, 0.5100]), "A") 

37 

38 assert not is_within_macadam_limits(np.array([0.0005, 0.0031, 0.0010]), "A") 

39 

40 assert is_within_macadam_limits(np.array([0.4325, 0.3788, 0.1034]), "C") 

41 

42 assert not is_within_macadam_limits(np.array([0.0025, 0.0088, 0.0340]), "C") 

43 

44 def test_n_dimensional_is_within_macadam_limits(self) -> None: 

45 """ 

46 Test :func:`colour.volume.macadam_limits.is_within_macadam_limits` 

47 definition n-dimensional arrays support. 

48 """ 

49 

50 if not is_scipy_installed(): # pragma: no cover 

51 return 

52 

53 a = np.array([0.3205, 0.4131, 0.5100]) 

54 b = is_within_macadam_limits(a, "A") 

55 

56 a = np.tile(a, (6, 1)) 

57 b = np.tile(b, 6) 

58 np.testing.assert_allclose(is_within_macadam_limits(a, "A"), b) 

59 

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

61 b = np.reshape(b, (2, 3)) 

62 np.testing.assert_allclose(is_within_macadam_limits(a, "A"), b) 

63 

64 @ignore_numpy_errors 

65 def test_nan_is_within_macadam_limits(self) -> None: 

66 """ 

67 Test :func:`colour.volume.macadam_limits.is_within_macadam_limits` 

68 definition nan support. 

69 """ 

70 

71 if not is_scipy_installed(): # pragma: no cover 

72 return 

73 

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

75 cases = np.array(list(set(product(cases, repeat=3)))) 

76 is_within_macadam_limits(cases, "A")