MCPcopy Create free account
hub / github.com/apache/brpc / TEST

Function TEST

test/rand_util_unittest.cc:23–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21} // namespace
22
23TEST(RandUtilTest, Sanity) {
24 EXPECT_EQ(butil::RandInt(0, 0), 0);
25 EXPECT_EQ(butil::RandInt(kIntMin, kIntMin), kIntMin);
26 EXPECT_EQ(butil::RandInt(kIntMax, kIntMax), kIntMax);
27
28 for (int i = 0; i < 10; ++i) {
29 uint64_t value = butil::fast_rand_in(
30 (uint64_t)0, std::numeric_limits<uint64_t>::max());
31 if (value != std::numeric_limits<uint64_t>::min() &&
32 value != std::numeric_limits<uint64_t>::max()) {
33 break;
34 } else {
35 EXPECT_NE(9, i) << "Never meet random except min/max of uint64";
36 }
37 }
38 for (int i = 0; i < 10; ++i) {
39 int64_t value = butil::fast_rand_in(
40 std::numeric_limits<int64_t>::min(),
41 std::numeric_limits<int64_t>::max());
42 if (value != std::numeric_limits<int64_t>::min() &&
43 value != std::numeric_limits<int64_t>::max()) {
44 break;
45 } else {
46 EXPECT_NE(9, i) << "Never meet random except min/max of int64";
47 }
48 }
49 EXPECT_EQ(butil::fast_rand_in(-1, -1), -1);
50 EXPECT_EQ(butil::fast_rand_in(1, 1), 1);
51 EXPECT_EQ(butil::fast_rand_in(0, 0), 0);
52 EXPECT_EQ(butil::fast_rand_in(std::numeric_limits<int64_t>::min(),
53 std::numeric_limits<int64_t>::min()),
54 std::numeric_limits<int64_t>::min());
55 EXPECT_EQ(butil::fast_rand_in(std::numeric_limits<int64_t>::max(),
56 std::numeric_limits<int64_t>::max()),
57 std::numeric_limits<int64_t>::max());
58 EXPECT_EQ(butil::fast_rand_in(std::numeric_limits<uint64_t>::min(),
59 std::numeric_limits<uint64_t>::min()),
60 std::numeric_limits<uint64_t>::min());
61 EXPECT_EQ(butil::fast_rand_in(std::numeric_limits<uint64_t>::max(),
62 std::numeric_limits<uint64_t>::max()),
63 std::numeric_limits<uint64_t>::max());
64}
65
66TEST(RandUtilTest, RandDouble) {
67 // Force 64-bit precision, making sure we're not in a 80-bit FPU register.

Callers

nothing calls this directly

Calls 15

RandIntFunction · 0.85
fast_rand_inFunction · 0.85
RandDoubleFunction · 0.85
fast_rand_doubleFunction · 0.85
RandBytesFunction · 0.85
RandBytesAsStringFunction · 0.85
RandGeneratorFunction · 0.85
fast_rand_less_thanFunction · 0.85
RandUint64Function · 0.85
fast_randFunction · 0.85
InMicrosecondsMethod · 0.80
n_elapsedMethod · 0.80

Tested by

no test coverage detected