summaryrefslogtreecommitdiff
path: root/src/mongo/platform/random_test.cpp
diff options
context:
space:
mode:
authorCharlie Swanson <charlie.swanson@mongodb.com>2015-08-07 16:10:23 -0400
committerCharlie Swanson <charlie.swanson@mongodb.com>2015-08-27 13:01:51 -0400
commitd88cb83e39b4cdddc9bdcf98f667f6cabdadc8ec (patch)
tree6a3ee70ea056ddab3a5801a783d009cd925724de /src/mongo/platform/random_test.cpp
parent843fd8ae34d06ed73f824c124cd2d9ef7d23b814 (diff)
downloadmongo-d88cb83e39b4cdddc9bdcf98f667f6cabdadc8ec.tar.gz
SERVER-19182 Integrate storage engine optimizations into $sample stage
Diffstat (limited to 'src/mongo/platform/random_test.cpp')
-rw-r--r--src/mongo/platform/random_test.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/mongo/platform/random_test.cpp b/src/mongo/platform/random_test.cpp
index 3aecfb2e98b..c4e214f1af9 100644
--- a/src/mongo/platform/random_test.cpp
+++ b/src/mongo/platform/random_test.cpp
@@ -98,6 +98,52 @@ TEST(RandomTest, R2) {
ASSERT_EQUALS(100U, s.size());
}
+/**
+ * Test that if two PsuedoRandom's have the same seed, then subsequent calls to
+ * nextCanonicalDouble() will return the same value.
+ */
+TEST(RandomTest, NextCanonicalSameSeed) {
+ PseudoRandom a(12);
+ PseudoRandom b(12);
+ for (int i = 0; i < 100; i++) {
+ ASSERT_EQUALS(a.nextCanonicalDouble(), b.nextCanonicalDouble());
+ }
+}
+
+/**
+ * Test that if two PsuedoRandom's have different seeds, then nextCanonicalDouble() will return
+ * different values.
+ */
+TEST(RandomTest, NextCanonicalDifferentSeeds) {
+ PseudoRandom a(12);
+ PseudoRandom b(11);
+ ASSERT_NOT_EQUALS(a.nextCanonicalDouble(), b.nextCanonicalDouble());
+}
+
+/**
+ * Test that nextCanonicalDouble() avoids returning a value soon after it has previously returned
+ * that value.
+ */
+TEST(RandomTest, NextCanonicalDistinctValues) {
+ PseudoRandom a(11);
+ std::set<double> s;
+ for (int i = 0; i < 100; i++) {
+ s.insert(a.nextCanonicalDouble());
+ }
+ ASSERT_EQUALS(100U, s.size());
+}
+
+/**
+ * Test that nextCanonicalDouble() always returns values between 0 and 1.
+ */
+TEST(RandomTest, NextCanonicalWithinRange) {
+ PseudoRandom prng(10);
+ for (int i = 0; i < 100; i++) {
+ double next = prng.nextCanonicalDouble();
+ ASSERT_LTE(0.0, next);
+ ASSERT_LT(next, 1.0);
+ }
+}
TEST(RandomTest, Secure1) {
SecureRandom* a = SecureRandom::create();