Index: test/cctest/test-random-number-generator.cc |
diff --git a/test/cctest/test-cpu.cc b/test/cctest/test-random-number-generator.cc |
similarity index 52% |
copy from test/cctest/test-cpu.cc |
copy to test/cctest/test-random-number-generator.cc |
index 06966c68c86296e510edb8899f4d7deb0343f108..d9fadfacb8fa1bd3e26e8b9ed9aed93dd7920fc3 100644 |
--- a/test/cctest/test-cpu.cc |
+++ b/test/cctest/test-random-number-generator.cc |
@@ -28,28 +28,65 @@ |
#include "v8.h" |
#include "cctest.h" |
-#include "cpu.h" |
+#include "utils/random-number-generator.h" |
using namespace v8::internal; |
-TEST(FeatureImplications) { |
- // Test for features implied by other features. |
- CPU cpu; |
+static const int kMaxRuns = 12345; |
+static const int kRandomSeeds[] = { |
+ -1, 1, 42, 100, 1234567890, 987654321, 0xdeadbeef |
+}; |
- // ia32 and x64 features |
- CHECK(!cpu.has_sse() || cpu.has_mmx()); |
- CHECK(!cpu.has_sse2() || cpu.has_sse()); |
- CHECK(!cpu.has_sse3() || cpu.has_sse2()); |
- CHECK(!cpu.has_ssse3() || cpu.has_sse3()); |
- CHECK(!cpu.has_sse41() || cpu.has_sse3()); |
- CHECK(!cpu.has_sse42() || cpu.has_sse41()); |
- // arm features |
- CHECK(!cpu.has_vfp3_d32() || cpu.has_vfp3()); |
+TEST(NextIntWithMaxValue) { |
+ for (unsigned n = 0; n < ARRAY_SIZE(kRandomSeeds); ++n) { |
+ RandomNumberGenerator rng(kRandomSeeds[n]); |
+ for (int max = 1; max <= kMaxRuns; ++max) { |
+ int n = rng.NextInt(max); |
+ CHECK_LE(0, n); |
+ CHECK_LT(n, max); |
+ } |
+ } |
} |
-TEST(NumberOfProcessorsOnline) { |
- CHECK_GT(CPU::NumberOfProcessorsOnline(), 0); |
+TEST(NextBoolReturnsBooleanValue) { |
+ for (unsigned n = 0; n < ARRAY_SIZE(kRandomSeeds); ++n) { |
+ RandomNumberGenerator rng(kRandomSeeds[n]); |
+ for (int k = 0; k < kMaxRuns; ++k) { |
+ bool b = rng.NextBool(); |
+ CHECK(b == false || b == true); |
+ } |
+ } |
+} |
+ |
+ |
+TEST(NextDoubleRange) { |
+ for (unsigned n = 0; n < ARRAY_SIZE(kRandomSeeds); ++n) { |
+ RandomNumberGenerator rng(kRandomSeeds[n]); |
+ for (int k = 0; k < kMaxRuns; ++k) { |
+ double d = rng.NextDouble(); |
+ CHECK_LE(0.0, d); |
+ CHECK_LT(d, 1.0); |
+ } |
+ } |
+} |
+ |
+ |
+TEST(RandomSeedFlagIsUsed) { |
+ for (unsigned n = 0; n < ARRAY_SIZE(kRandomSeeds); ++n) { |
+ FLAG_random_seed = kRandomSeeds[n]; |
+ RandomNumberGenerator rng1; |
+ RandomNumberGenerator rng2(kRandomSeeds[n]); |
+ for (int k = 1; k <= kMaxRuns; ++k) { |
+ int64_t i1, i2; |
+ rng1.NextBytes(&i1, sizeof(i1)); |
+ rng2.NextBytes(&i2, sizeof(i2)); |
+ CHECK_EQ(i2, i1); |
+ CHECK_EQ(rng2.NextInt(), rng1.NextInt()); |
+ CHECK_EQ(rng2.NextInt(k), rng1.NextInt(k)); |
+ CHECK_EQ(rng2.NextDouble(), rng1.NextDouble()); |
+ } |
+ } |
} |