diff options
author | Eliot Horowitz <eliot@10gen.com> | 2012-11-13 10:13:25 -0500 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2012-11-13 17:35:46 -0500 |
commit | 68a2023506a217e787e0cb50d7de60b36d4fa17f (patch) | |
tree | 7877ba21503746a3f76d06245b3f2815e4a1de8f /src/mongo/platform/random_test.cpp | |
parent | 93fdafcb4c4883d401a0726b67f2141404daa9ee (diff) | |
download | mongo-68a2023506a217e787e0cb50d7de60b36d4fa17f.tar.gz |
some Random tests and helpers
Diffstat (limited to 'src/mongo/platform/random_test.cpp')
-rw-r--r-- | src/mongo/platform/random_test.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/mongo/platform/random_test.cpp b/src/mongo/platform/random_test.cpp index 0752604c5ca..c8a5444638f 100644 --- a/src/mongo/platform/random_test.cpp +++ b/src/mongo/platform/random_test.cpp @@ -16,11 +16,14 @@ * limitations under the License. */ +#include <set> + #include "mongo/platform/random.h" #include "mongo/unittest/unittest.h" namespace mongo { + TEST( RandomTest, Seed1 ) { #ifndef _WIN32 PseudoRandom a( 12 ); @@ -32,6 +35,34 @@ namespace mongo { #endif } + TEST( RandomTest, Seed2 ) { + PseudoRandom a( 12 ); + PseudoRandom b( 12 ); + + for ( int i = 0; i < 100; i++ ) { + ASSERT_EQUALS( a.nextInt64(), b.nextInt64() ); + } + } + + TEST( RandomTest, R1 ) { + PseudoRandom a( 11 ); + std::set<int32_t> s; + for ( int i = 0; i < 100; i++ ) { + s.insert( a.nextInt32() ); + } + ASSERT_EQUALS( 100U, s.size() ); + } + + TEST( RandomTest, R2 ) { + PseudoRandom a( 11 ); + std::set<int64_t> s; + for ( int i = 0; i < 100; i++ ) { + s.insert( a.nextInt64() ); + } + ASSERT_EQUALS( 100U, s.size() ); + } + + TEST( RandomTest, Secure1 ) { SecureRandom* a = SecureRandom::create(); SecureRandom* b = SecureRandom::create(); |