aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/src/base/utils
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2014-10-10 14:49:02 +0400
committerFedor Indutny <fedor@indutny.com>2014-10-10 14:49:02 +0400
commit6bcea4ff932144a5fd02affefd45164fbf471e67 (patch)
treea8e078c679b12f0daebe10ed254239cb0d79e146 /deps/v8/src/base/utils
parent4fae2356d105e394115188a814097c4a95ae0c5d (diff)
downloadandroid-node-v8-6bcea4ff932144a5fd02affefd45164fbf471e67.tar.gz
android-node-v8-6bcea4ff932144a5fd02affefd45164fbf471e67.tar.bz2
android-node-v8-6bcea4ff932144a5fd02affefd45164fbf471e67.zip
deps: update v8 to 3.29.93.1
Diffstat (limited to 'deps/v8/src/base/utils')
-rw-r--r--deps/v8/src/base/utils/random-number-generator-unittest.cc53
-rw-r--r--deps/v8/src/base/utils/random-number-generator.cc3
-rw-r--r--deps/v8/src/base/utils/random-number-generator.h15
3 files changed, 64 insertions, 7 deletions
diff --git a/deps/v8/src/base/utils/random-number-generator-unittest.cc b/deps/v8/src/base/utils/random-number-generator-unittest.cc
new file mode 100644
index 0000000000..7c533db4f0
--- /dev/null
+++ b/deps/v8/src/base/utils/random-number-generator-unittest.cc
@@ -0,0 +1,53 @@
+// 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
diff --git a/deps/v8/src/base/utils/random-number-generator.cc b/deps/v8/src/base/utils/random-number-generator.cc
index be79811171..a1ec9d7184 100644
--- a/deps/v8/src/base/utils/random-number-generator.cc
+++ b/deps/v8/src/base/utils/random-number-generator.cc
@@ -79,7 +79,7 @@ RandomNumberGenerator::RandomNumberGenerator() {
int RandomNumberGenerator::NextInt(int max) {
- DCHECK_LE(0, max);
+ DCHECK_LT(0, max);
// Fast path if max is a power of 2.
if (IS_POWER_OF_TWO(max)) {
@@ -125,6 +125,7 @@ int RandomNumberGenerator::Next(int bits) {
void RandomNumberGenerator::SetSeed(int64_t seed) {
+ initial_seed_ = seed;
seed_ = (seed ^ kMultiplier) & kMask;
}
diff --git a/deps/v8/src/base/utils/random-number-generator.h b/deps/v8/src/base/utils/random-number-generator.h
index 5955d66597..479423d658 100644
--- a/deps/v8/src/base/utils/random-number-generator.h
+++ b/deps/v8/src/base/utils/random-number-generator.h
@@ -25,7 +25,7 @@ namespace base {
// https://code.google.com/p/v8/issues/detail?id=2905
// This class is neither reentrant nor threadsafe.
-class RandomNumberGenerator V8_FINAL {
+class RandomNumberGenerator FINAL {
public:
// EntropySource is used as a callback function when V8 needs a source of
// entropy.
@@ -40,7 +40,7 @@ class RandomNumberGenerator V8_FINAL {
// that one int value is pseudorandomly generated and returned.
// All 2^32 possible integer values are produced with (approximately) equal
// probability.
- V8_INLINE int NextInt() V8_WARN_UNUSED_RESULT {
+ V8_INLINE int NextInt() WARN_UNUSED_RESULT {
return Next(32);
}
@@ -50,14 +50,14 @@ class RandomNumberGenerator V8_FINAL {
// one int value in the specified range is pseudorandomly generated and
// returned. All max possible int values are produced with (approximately)
// equal probability.
- int NextInt(int max) V8_WARN_UNUSED_RESULT;
+ int NextInt(int max) WARN_UNUSED_RESULT;
// Returns the next pseudorandom, uniformly distributed boolean value from
// this random number generator's sequence. The general contract of
// |NextBoolean()| is that one boolean value is pseudorandomly generated and
// returned. The values true and false are produced with (approximately) equal
// probability.
- V8_INLINE bool NextBool() V8_WARN_UNUSED_RESULT {
+ V8_INLINE bool NextBool() WARN_UNUSED_RESULT {
return Next(1) != 0;
}
@@ -66,7 +66,7 @@ class RandomNumberGenerator V8_FINAL {
// The general contract of |NextDouble()| is that one double value, chosen
// (approximately) uniformly from the range 0.0 (inclusive) to 1.0
// (exclusive), is pseudorandomly generated and returned.
- double NextDouble() V8_WARN_UNUSED_RESULT;
+ double NextDouble() WARN_UNUSED_RESULT;
// Fills the elements of a specified array of bytes with random numbers.
void NextBytes(void* buffer, size_t buflen);
@@ -74,13 +74,16 @@ class RandomNumberGenerator V8_FINAL {
// Override the current ssed.
void SetSeed(int64_t seed);
+ int64_t initial_seed() const { return initial_seed_; }
+
private:
static const int64_t kMultiplier = V8_2PART_UINT64_C(0x5, deece66d);
static const int64_t kAddend = 0xb;
static const int64_t kMask = V8_2PART_UINT64_C(0xffff, ffffffff);
- int Next(int bits) V8_WARN_UNUSED_RESULT;
+ int Next(int bits) WARN_UNUSED_RESULT;
+ int64_t initial_seed_;
int64_t seed_;
};