MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / main

Function main

tests/test_rng.cpp:7–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5using namespace OpenApoc;
6
7int main(int argc, char **argv)
8{
9 if (config().parseOptions(argc, argv))
10 {
11 return EXIT_FAILURE;
12 }
13 Xorshift128Plus<uint64_t> rng{};
14
15 uint64_t r1 = rng();
16 uint64_t r2 = rng();
17
18 uint64_t expected_r1 = 0x03aacfee1f751183;
19 uint64_t expected_r2 = 0xcb8aa3521c8fc259;
20 uint64_t expected_r3 = 0xdd420b258a17fa82;
21
22 if (r1 != expected_r1)
23 {
24 LogError("unexpected r1 0x%016x, expected 0x%016x", r1, expected_r1);
25 return EXIT_FAILURE;
26 }
27
28 if (r2 != expected_r2)
29 {
30 LogError("unexpected r2 0x%016x, expected 0x%016x", r2, expected_r2);
31 return EXIT_FAILURE;
32 }
33
34 // Reseed and check it matches
35 rng.seed(0);
36 r1 = rng();
37 r2 = rng();
38
39 if (r1 != expected_r1)
40 {
41 LogError("unexpected post-reseed r1 0x%016x, expected 0x%016x", r1, expected_r1);
42 return EXIT_FAILURE;
43 }
44
45 if (r2 != expected_r2)
46 {
47 LogError("unexpected post-reseed r2 0x%016x, expected 0x%016x", r2, expected_r2);
48 return EXIT_FAILURE;
49 }
50
51 // Save the state to another rng and check that result matches
52
53 uint64_t s[2];
54 Xorshift128Plus<uint64_t> rng2{};
55
56 rng.getState(s);
57 rng2.setState(s);
58
59 uint64_t r3 = rng2();
60 if (r3 != expected_r3)
61 {
62 LogError("unexpected r3 0x%016x, expected 0x%016x", r3, expected_r3);
63 return EXIT_FAILURE;
64 }

Callers

nothing calls this directly

Calls 5

randBoundsExclusiveFunction · 0.85
seedMethod · 0.80
parseOptionsMethod · 0.45
getStateMethod · 0.45
setStateMethod · 0.45

Tested by

no test coverage detected