Coverage for algebra/tests/test_prng.py: 100%

1"""

2 Define the unit tests for the :mod:`colour.algebra.prng` module.

3

4 References

5----------

6- :cite:`Laurent2012a` : Laurent. (2012). Reproducibility of python

7 pseudo-random numbers across systems and versions? Retrieved January 20,

8 2015, from

9 http://stackoverflow.com/questions/8786084/\

10 reproducibility-of-python-pseudo-random-numbers-across-systems-and-versions

11"""

12

13 from __future__ import annotations

14

15 import typing

16

17 import numpy as np

18

19 from colour.algebra import random_triplet_generator

20 from colour.constants import TOLERANCE_ABSOLUTE_TESTS

21

22 if typing.TYPE_CHECKING:

23 from colour.hints import NDArrayFloat

24

25 __author__ = "Colour Developers"

26 __copyright__ = "Copyright 2013 Colour Developers"

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

28 __maintainer__ = "Colour Developers"

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

30 __status__ = "Production"

31

32 __all__ = [

33 "RANDOM_TRIPLETS",

34 "TestRandomTripletGenerator",

35]

36

37 RANDOM_TRIPLETS: NDArrayFloat = np.array(

38 [

39 [0.96702984, 0.77938292, 0.43614665],

40 [0.54723225, 0.19768507, 0.94897731],

41 [0.97268436, 0.86299324, 0.78630599],

42 [0.71481599, 0.98340068, 0.86628930],

43 [0.69772882, 0.16384224, 0.17316542],

44 [0.21608950, 0.59733394, 0.07494859],

45 [0.97627445, 0.00898610, 0.60074272],

46 [0.00623026, 0.38657128, 0.16797218],

47 [0.25298236, 0.04416006, 0.73338017],

48 [0.43479153, 0.95665297, 0.40844386],

49 ]

50)

51

52

53 class TestRandomTripletGenerator:

54 """

55 Define :func:`colour.algebra.prng.random_triplet_generator` definition

56 unit tests methods.

57 """

58

59 def test_random_triplet_generator(self) -> None:

60 """

61 Test :func:`colour.algebra.prng.random_triplet_generator` definition.

62

63 Notes

64 -----

65 - The test is assuming that :func:`np.random.RandomState` definition

66 will return the same sequence no matter which *OS* or *Python*

67 version is used. There is however no formal promise about the

68 *prng* sequence reproducibility of either *Python* or *Numpy*

69 implementations, see :cite:`Laurent2012a`.

70 """

71

72 prng = np.random.RandomState(4)

73 np.testing.assert_allclose(

74 RANDOM_TRIPLETS,

75 random_triplet_generator(10, random_state=prng),

76 atol=TOLERANCE_ABSOLUTE_TESTS,

77 )