Coverage for colour/algebra/tests/test_prng.py: 100%
17 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-15 19:01 +1300
1"""
2Define the unit tests for the :mod:`colour.algebra.prng` module.
4References
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/\
10reproducibility-of-python-pseudo-random-numbers-across-systems-and-versions
11"""
13from __future__ import annotations
15import typing
17import numpy as np
19from colour.algebra import random_triplet_generator
20from colour.constants import TOLERANCE_ABSOLUTE_TESTS
22if typing.TYPE_CHECKING:
23 from colour.hints import NDArrayFloat
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"
32__all__ = [
33 "RANDOM_TRIPLETS",
34 "TestRandomTripletGenerator",
35]
37RANDOM_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)
53class TestRandomTripletGenerator:
54 """
55 Define :func:`colour.algebra.prng.random_triplet_generator` definition
56 unit tests methods.
57 """
59 def test_random_triplet_generator(self) -> None:
60 """
61 Test :func:`colour.algebra.prng.random_triplet_generator` definition.
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 """
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 )