4
/* Copyright 2012 10gen Inc.
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
21
#include "mongo/platform/random.h"
23
#include "mongo/unittest/unittest.h"
27
TEST( RandomTest, Seed1 ) {
31
for ( int i = 0; i < 100; i++ ) {
32
ASSERT_EQUALS( a.nextInt32(), b.nextInt32() );
36
TEST( RandomTest, Seed2 ) {
40
for ( int i = 0; i < 100; i++ ) {
41
ASSERT_EQUALS( a.nextInt64(), b.nextInt64() );
45
TEST( RandomTest, Seed3 ) {
49
ASSERT_NOT_EQUALS( a.nextInt32(), b.nextInt32() );
52
TEST( RandomTest, Seed4 ) {
55
for ( int i = 0; i < 100; i++ ) {
56
s.insert( a.nextInt32() );
58
ASSERT_EQUALS( 100U, s.size() );
61
TEST( RandomTest, Seed5 ) {
62
const int64_t seed = 0xCC453456FA345FABLL;
65
for ( int i = 0; i < 100; i++ ) {
66
s.insert( a.nextInt32() );
68
ASSERT_EQUALS( 100U, s.size() );
71
TEST( RandomTest, R1 ) {
74
for ( int i = 0; i < 100; i++ ) {
75
s.insert( a.nextInt32() );
77
ASSERT_EQUALS( 100U, s.size() );
80
TEST( RandomTest, R2 ) {
83
for ( int i = 0; i < 100; i++ ) {
84
s.insert( a.nextInt64() );
86
ASSERT_EQUALS( 100U, s.size() );
90
TEST( RandomTest, Secure1 ) {
91
SecureRandom* a = SecureRandom::create();
92
SecureRandom* b = SecureRandom::create();
94
for ( int i = 0; i< 100; i++ ) {
95
ASSERT_NOT_EQUALS( a->nextInt64(), b->nextInt64() );