1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "src/base/utils/random-number-generator.h"
8 #include "testing/gtest/include/gtest/gtest.h"
13 class RandomNumberGeneratorTest : public ::testing::TestWithParam<int> {};
16 static const int kMaxRuns = 12345;
19 TEST_P(RandomNumberGeneratorTest, NextIntWithMaxValue) {
20 RandomNumberGenerator rng(GetParam());
21 for (int max = 1; max <= kMaxRuns; ++max) {
22 int n = rng.NextInt(max);
29 TEST_P(RandomNumberGeneratorTest, NextBooleanReturnsFalseOrTrue) {
30 RandomNumberGenerator rng(GetParam());
31 for (int k = 0; k < kMaxRuns; ++k) {
32 bool b = rng.NextBool();
33 EXPECT_TRUE(b == false || b == true);
38 TEST_P(RandomNumberGeneratorTest, NextDoubleReturnsValueBetween0And1) {
39 RandomNumberGenerator rng(GetParam());
40 for (int k = 0; k < kMaxRuns; ++k) {
41 double d = rng.NextDouble();
48 INSTANTIATE_TEST_CASE_P(RandomSeeds, RandomNumberGeneratorTest,
49 ::testing::Values(INT_MIN, -1, 0, 1, 42, 100,
50 1234567890, 987654321, INT_MAX));