Lumiera  0.pre.03
»edit your freedom«
random-test.cpp
Go to the documentation of this file.
1 /*
2  Random(Test) - verify framework for controlled random number generation
3 
4  Copyright (C) Lumiera.org
5  2024, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
29 #include "lib/test/run.hpp"
30 #include "lib/random.hpp"
31 
32 
33 namespace lib {
34 namespace test {
35 
36  /******************************************************************/
41  class Random_test : public Test
42  {
43 
44  virtual void
45  run (Arg)
46  {
47  simpleUsage();
49  }
50 
51 
53  void
55  {
56  int r1 = rani();
57  CHECK (0 <= r1 and r1 < RAND_MAX);
58 
59  int r2 = rani();
60  CHECK (0 <= r2 and r2 < RAND_MAX);
61  CHECK (r1 != r2);
62  }
63 
64 
73  void
75  {
76  class : public SeedNucleus
77  {
78  uint64_t getSeed() override { return 55; }
79  }
80  coreOfEvil;
81 
82  Random src1{coreOfEvil};
83 
84  int r1 = src1.i32();
85  uint64_t r2 = src1.u64();
86  double r3 = src1.uni();
87 
88  Random src2{coreOfEvil};
89  CHECK (r1 == src2.i32());
90  CHECK (r2 == src2.u64());
91  CHECK (r3 == src2.uni());
92 
93  src1.randomise(coreOfEvil);
94  CHECK (src1.i32() != src2.i32());
95 
96  src2.randomise(coreOfEvil);
97  CHECK (src1.i32() == src2.i32());
98  }
99  };
100 
101  LAUNCHER (Random_test, "unit common");
102 
103 
104 }} // namespace lib::test
void randomise(SeedNucleus &)
inject controlled randomisation
Definition: random.hpp:124
Access point to a selection of random number sources.
Definition: random.hpp:65
Definition: run.hpp:49
void verify_reproducibleSequence()
Definition: random-test.cpp:74
Implementation namespace for support and library code.
Simple test class runner.
Establishes a seed point for any instance or performance.
Definition: random.hpp:49
Generating (pseudo) random numbers with controlled seed.