Skip to content

Commit 0000ea3

Browse files
author
MarcoFalke
committed
test: Add test for GetRandMillis and GetRandMicros
1 parent fa0e5b8 commit 0000ea3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/test/random_tests.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ BOOST_AUTO_TEST_CASE(fastrandom_tests)
2828
for (int i = 10; i > 0; --i) {
2929
BOOST_CHECK_EQUAL(GetRand(std::numeric_limits<uint64_t>::max()), uint64_t{10393729187455219830U});
3030
BOOST_CHECK_EQUAL(GetRandInt(std::numeric_limits<int>::max()), int{769702006});
31+
BOOST_CHECK_EQUAL(GetRandMicros(std::chrono::hours{1}).count(), 2917185654);
32+
BOOST_CHECK_EQUAL(GetRandMillis(std::chrono::hours{1}).count(), 2144374);
3133
}
3234
BOOST_CHECK_EQUAL(ctx1.rand32(), ctx2.rand32());
3335
BOOST_CHECK_EQUAL(ctx1.rand32(), ctx2.rand32());
@@ -47,6 +49,8 @@ BOOST_AUTO_TEST_CASE(fastrandom_tests)
4749
for (int i = 10; i > 0; --i) {
4850
BOOST_CHECK(GetRand(std::numeric_limits<uint64_t>::max()) != uint64_t{10393729187455219830U});
4951
BOOST_CHECK(GetRandInt(std::numeric_limits<int>::max()) != int{769702006});
52+
BOOST_CHECK(GetRandMicros(std::chrono::hours{1}) != std::chrono::microseconds{2917185654});
53+
BOOST_CHECK(GetRandMillis(std::chrono::hours{1}) != std::chrono::milliseconds{2144374});
5054
}
5155
{
5256
FastRandomContext ctx3, ctx4;
@@ -87,7 +91,7 @@ BOOST_AUTO_TEST_CASE(stdrandom_test)
8791
BOOST_CHECK(x >= 3);
8892
BOOST_CHECK(x <= 9);
8993

90-
std::vector<int> test{1,2,3,4,5,6,7,8,9,10};
94+
std::vector<int> test{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
9195
std::shuffle(test.begin(), test.end(), ctx);
9296
for (int j = 1; j <= 10; ++j) {
9397
BOOST_CHECK(std::find(test.begin(), test.end(), j) != test.end());
@@ -97,7 +101,6 @@ BOOST_AUTO_TEST_CASE(stdrandom_test)
97101
BOOST_CHECK(std::find(test.begin(), test.end(), j) != test.end());
98102
}
99103
}
100-
101104
}
102105

103106
/** Test that Shuffle reaches every permutation with equal probability. */

0 commit comments

Comments
 (0)