v8/test/unittests/base/utils/random-number-generator-unittest.cc
bmeurer@chromium.org bfd37ab267 Move unit tests to test/unittests.
As per discussion on the V8 team, this is the place we want them to live,
not following the Chrome Style Guide for this.

BUG=v8:3489
LOG=y
R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/615393002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24350 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-10-01 08:34:25 +00:00

54 lines
1.3 KiB
C++

// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <climits>
#include "src/base/utils/random-number-generator.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
namespace base {
class RandomNumberGeneratorTest : public ::testing::TestWithParam<int> {};
static const int kMaxRuns = 12345;
TEST_P(RandomNumberGeneratorTest, NextIntWithMaxValue) {
RandomNumberGenerator rng(GetParam());
for (int max = 1; max <= kMaxRuns; ++max) {
int n = rng.NextInt(max);
EXPECT_LE(0, n);
EXPECT_LT(n, max);
}
}
TEST_P(RandomNumberGeneratorTest, NextBooleanReturnsFalseOrTrue) {
RandomNumberGenerator rng(GetParam());
for (int k = 0; k < kMaxRuns; ++k) {
bool b = rng.NextBool();
EXPECT_TRUE(b == false || b == true);
}
}
TEST_P(RandomNumberGeneratorTest, NextDoubleReturnsValueBetween0And1) {
RandomNumberGenerator rng(GetParam());
for (int k = 0; k < kMaxRuns; ++k) {
double d = rng.NextDouble();
EXPECT_LE(0.0, d);
EXPECT_LT(d, 1.0);
}
}
INSTANTIATE_TEST_CASE_P(RandomSeeds, RandomNumberGeneratorTest,
::testing::Values(INT_MIN, -1, 0, 1, 42, 100,
1234567890, 987654321, INT_MAX));
} // namespace base
} // namespace v8