#include "test.h" #include #include // From https://www.mscs.dal.ca/~selinger/random/, 2020-05-25 static const int NUM_RANDOM_INTEGERS = 60; static const int GLIBC_SEED_1_RANDOM_INTEGERS[NUM_RANDOM_INTEGERS] = { 1804289383, 846930886, 1681692777, 1714636915, 1957747793, 424238335, 719885386, 1649760492, 596516649, 1189641421, 1025202362, 1350490027, 783368690, 1102520059, 2044897763, 1967513926, 1365180540, 1540383426, 304089172, 1303455736, 35005211, 521595368, 294702567, 1726956429, 336465782, 861021530, 278722862, 233665123, 2145174067, 468703135, 1101513929, 1801979802, 1315634022, 635723058, 1369133069, 1125898167, 1059961393, 2089018456, 628175011, 1656478042, 1131176229, 1653377373, 859484421, 1914544919, 608413784, 756898537, 1734575198, 1973594324, 149798315, 2038664370, 1129566413, 184803526, 412776091, 1424268980, 1911759956, 749241873, 137806862, 42999170, 982906996, 135497281, }; TEST(Prng, EqualsGlibc) { const int *EXPECTED = GLIBC_SEED_1_RANDOM_INTEGERS; CPrng Prng; Prng.Seed(1); for(int i = 0; i < NUM_RANDOM_INTEGERS; i++) { EXPECT_EQ(Prng.RandomInt(), EXPECTED[i]); } } TEST(Prng, Description) { CPrng Prng; EXPECT_STREQ(Prng.Description(), "glibc-rand-emu:unseeded"); Prng.Seed(0x01234567); EXPECT_STREQ(Prng.Description(), "glibc-rand-emu:01234567"); Prng.Seed(0xfedbca98); EXPECT_STREQ(Prng.Description(), "glibc-rand-emu:fedbca98"); }