diff options
author | Abseil Team <absl-team@google.com> | 2019-11-21T18·30-0800 |
---|---|---|
committer | Gennadiy Civil <misterg@google.com> | 2019-11-22T16·35-0500 |
commit | 16d9fd58a51c6083234e2e9f8f50e49ed5ed02e4 (patch) | |
tree | c4d5da856d0ee16401bb6d9694c998e51b2f604c /absl/base/internal/exponential_biased_test.cc | |
parent | bcaae6009c0833b73c6fa7bdd972921d8081a724 (diff) |
Export of internal Abseil changes
-- db8dbd0e8a7b0125a4819dfc81c9bd2496849c71 by Abseil Team <absl-team@google.com>: Create GetSkipCount() and GetStride() methods and add rounding bias correction. PiperOrigin-RevId: 281780897 GitOrigin-RevId: db8dbd0e8a7b0125a4819dfc81c9bd2496849c71 Change-Id: I56a97288b1cb38a9357c065747f8d9bc4b187fee
Diffstat (limited to 'absl/base/internal/exponential_biased_test.cc')
-rw-r--r-- | absl/base/internal/exponential_biased_test.cc | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/absl/base/internal/exponential_biased_test.cc b/absl/base/internal/exponential_biased_test.cc index 09b511d14e70..af003239f8de 100644 --- a/absl/base/internal/exponential_biased_test.cc +++ b/absl/base/internal/exponential_biased_test.cc @@ -113,6 +113,35 @@ double AndersonDarlingTest(const std::vector<double>& random_sample) { return p; } +TEST(ExponentialBiasedTest, CoinTossDemoWithGetSkipCount) { + ExponentialBiased eb; + for (int runs = 0; runs < 10; ++runs) { + for (int flips = eb.GetSkipCount(1); flips > 0; --flips) { + printf("head..."); + } + printf("tail\n"); + } + int heads = 0; + for (int i = 0; i < 10000000; i += 1 + eb.GetSkipCount(1)) { + ++heads; + } + printf("Heads = %d (%f%%)\n", heads, 100.0 * heads / 10000000); +} + +TEST(ExponentialBiasedTest, SampleDemoWithStride) { + ExponentialBiased eb; + int stride = eb.GetStride(10); + int samples = 0; + for (int i = 0; i < 10000000; ++i) { + if (--stride == 0) { + ++samples; + stride = eb.GetStride(10); + } + } + printf("Samples = %d (%f%%)\n", samples, 100.0 * samples / 10000000); +} + + // Testing that NextRandom generates uniform random numbers. Applies the // Anderson-Darling test for uniformity TEST(ExponentialBiasedTest, TestNextRandom) { @@ -153,15 +182,15 @@ TEST(ExponentialBiasedTest, TestNextRandom) { // variable. TEST(ExponentialBiasedTest, InitializationModes) { ABSL_CONST_INIT static ExponentialBiased eb_static; - EXPECT_THAT(eb_static.Get(2), Ge(0)); + EXPECT_THAT(eb_static.GetSkipCount(2), Ge(0)); #if ABSL_HAVE_THREAD_LOCAL thread_local ExponentialBiased eb_thread; - EXPECT_THAT(eb_thread.Get(2), Ge(0)); + EXPECT_THAT(eb_thread.GetSkipCount(2), Ge(0)); #endif ExponentialBiased eb_stack; - EXPECT_THAT(eb_stack.Get(2), Ge(0)); + EXPECT_THAT(eb_stack.GetSkipCount(2), Ge(0)); } } // namespace base_internal |