Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: src/base/utils/random-number-generator-unittest.cc

Issue 615393002: Move unit tests to test/unittests. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: REBASE Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/base/sys-info-unittest.cc ('k') | src/compiler/arm/instruction-selector-arm-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include <climits>
6
7 #include "src/base/utils/random-number-generator.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace v8 {
11 namespace base {
12
13 class RandomNumberGeneratorTest : public ::testing::TestWithParam<int> {};
14
15
16 static const int kMaxRuns = 12345;
17
18
19 TEST_P(RandomNumberGeneratorTest, NextIntWithMaxValue) {
20 RandomNumberGenerator rng(GetParam());
21 for (int max = 1; max <= kMaxRuns; ++max) {
22 int n = rng.NextInt(max);
23 EXPECT_LE(0, n);
24 EXPECT_LT(n, max);
25 }
26 }
27
28
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);
34 }
35 }
36
37
38 TEST_P(RandomNumberGeneratorTest, NextDoubleReturnsValueBetween0And1) {
39 RandomNumberGenerator rng(GetParam());
40 for (int k = 0; k < kMaxRuns; ++k) {
41 double d = rng.NextDouble();
42 EXPECT_LE(0.0, d);
43 EXPECT_LT(d, 1.0);
44 }
45 }
46
47
48 INSTANTIATE_TEST_CASE_P(RandomSeeds, RandomNumberGeneratorTest,
49 ::testing::Values(INT_MIN, -1, 0, 1, 42, 100,
50 1234567890, 987654321, INT_MAX));
51
52 } // namespace base
53 } // namespace v8
OLDNEW
« no previous file with comments | « src/base/sys-info-unittest.cc ('k') | src/compiler/arm/instruction-selector-arm-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698