Coverage for geometry/tests/test__init__.py: 94%

1"""Define the unit tests for the :mod:`colour.geometry` 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.geometry import (

9 primitive,

10 primitive_cube,

11 primitive_grid,

12 primitive_vertices,

13 primitive_vertices_cube_mpl,

14 primitive_vertices_grid_mpl,

15 primitive_vertices_quad_mpl,

16 primitive_vertices_sphere,

17)

18

19 __author__ = "Colour Developers"

20 __copyright__ = "Copyright 2013 Colour Developers"

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

22 __maintainer__ = "Colour Developers"

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

24 __status__ = "Production"

25

26 __all__ = [

27 "TestPrimitive",

28 "TestPrimitiveVertices",

29]

30

31

32 class TestPrimitive:

33 """

34 Define :func:`colour.geometry.primitive` definition

35 unit tests methods.

36 """

37

38 def test_primitive(self) -> None:

39 """Test :func:`colour.geometry.primitive` definition."""

40

41 # Test Grid method

42 grid_result = primitive("Grid")

43 grid_expected = primitive_grid()

44 assert len(grid_result) == len(grid_expected)

45 for i in range(len(grid_result)):

46 np.testing.assert_array_equal(grid_result[i], grid_expected[i])

47

48 # Test Cube method

49 cube_result = primitive("Cube")

50 cube_expected = primitive_cube()

51 assert len(cube_result) == len(cube_expected)

52 for i in range(len(cube_result)):

53 if isinstance(cube_result[i], dict):

54 for key in cube_result[i]:

55 np.testing.assert_array_equal(

56 cube_result[i][key], cube_expected[i][key]

57 )

58 else:

59 np.testing.assert_array_equal(cube_result[i], cube_expected[i])

60

61

62 class TestPrimitiveVertices:

63 """

64 Define :func:`colour.geometry.primitive_vertices` definition

65 unit tests methods.

66 """

67

68 def test_primitive_vertices(self) -> None:

69 """Test :func:`colour.geometry.primitive_vertices` definition."""

70

71 np.testing.assert_allclose(

72 primitive_vertices("Quad MPL"),

73 primitive_vertices_quad_mpl(),

74 atol=TOLERANCE_ABSOLUTE_TESTS,

75 )

76

77 np.testing.assert_allclose(

78 primitive_vertices("Grid MPL"),

79 primitive_vertices_grid_mpl(),

80 atol=TOLERANCE_ABSOLUTE_TESTS,

81 )

82

83 np.testing.assert_allclose(

84 primitive_vertices("Cube MPL"),

85 primitive_vertices_cube_mpl(),

86 atol=TOLERANCE_ABSOLUTE_TESTS,

87 )

88

89 np.testing.assert_allclose(

90 primitive_vertices("Sphere"),

91 primitive_vertices_sphere(),

92 atol=TOLERANCE_ABSOLUTE_TESTS,

93 )