-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlcg_tests.cpp
More file actions
51 lines (46 loc) · 1.75 KB
/
Copy pathlcg_tests.cpp
File metadata and controls
51 lines (46 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2019 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <test/lcg.h>
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE(lcg_tests)
BOOST_AUTO_TEST_CASE(lcg_testvalues) {
{
MMIXLinearCongruentialGenerator lcg;
// We want that the first iteration is 0 which is a helpful special
// case.
BOOST_CHECK_EQUAL(lcg.next(), 0x00000000);
for (int i = 0; i < 99; i++) {
lcg.next();
}
// Make sure the LCG is producing expected value after many iterations.
// This ensures mul and add overflows are acting as expected on this
// architecture.
BOOST_CHECK_EQUAL(lcg.next(), 0xf306b780);
}
{
MMIXLinearCongruentialGenerator lcg(42);
// This also should make first iteration as 0.
BOOST_CHECK_EQUAL(lcg.next(), 0x00000000);
for (int i = 0; i < 99; i++) {
lcg.next();
}
// Make sure the LCG is producing expected value after many iterations.
// This ensures mul and add overflows are acting as expected on this
// architecture.
BOOST_CHECK_EQUAL(lcg.next(), 0x3b96faf3);
}
{
// just some big seed
MMIXLinearCongruentialGenerator lcg(0xdeadbeef00000000);
BOOST_CHECK_EQUAL(lcg.next(), 0xdeadbeef);
for (int i = 0; i < 99; i++) {
lcg.next();
}
// Make sure the LCG is producing expected value after many iterations.
// This ensures mul and add overflows are acting as expected on this
// architecture.
BOOST_CHECK_EQUAL(lcg.next(), 0x6b00b1df);
}
}
BOOST_AUTO_TEST_SUITE_END()