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

Unified Diff: base/rand_util_unittest.cc

Issue 1538743002: Switch to standard integer types in base/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DEPS roll too Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/rand_util_posix.cc ('k') | base/rand_util_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/rand_util_unittest.cc
diff --git a/base/rand_util_unittest.cc b/base/rand_util_unittest.cc
index 689b8ad3967eacb7a3bf6b1d5497cf73137aa6a3..ea803ee73f411e3efb8cfe3c3d25c65e15701f03 100644
--- a/base/rand_util_unittest.cc
+++ b/base/rand_util_unittest.cc
@@ -4,6 +4,9 @@
#include "base/rand_util.h"
+#include <stddef.h>
+#include <stdint.h>
+
#include <algorithm>
#include <limits>
@@ -67,7 +70,7 @@ TEST(RandUtilTest, RandBytesAsString) {
TEST(RandUtilTest, RandGeneratorForRandomShuffle) {
EXPECT_EQ(base::RandGenerator(1), 0U);
EXPECT_LE(std::numeric_limits<ptrdiff_t>::max(),
- std::numeric_limits<int64>::max());
+ std::numeric_limits<int64_t>::max());
}
TEST(RandUtilTest, RandGeneratorIsUniform) {
@@ -83,16 +86,17 @@ TEST(RandUtilTest, RandGeneratorIsUniform) {
// top half. A bit of calculus care of jar@ shows that the largest
// measurable delta is when the top of the range is 3/4ths of the
// way, so that's what we use in the test.
- const uint64 kTopOfRange = (std::numeric_limits<uint64>::max() / 4ULL) * 3ULL;
- const uint64 kExpectedAverage = kTopOfRange / 2ULL;
- const uint64 kAllowedVariance = kExpectedAverage / 50ULL; // +/- 2%
+ const uint64_t kTopOfRange =
+ (std::numeric_limits<uint64_t>::max() / 4ULL) * 3ULL;
+ const uint64_t kExpectedAverage = kTopOfRange / 2ULL;
+ const uint64_t kAllowedVariance = kExpectedAverage / 50ULL; // +/- 2%
const int kMinAttempts = 1000;
const int kMaxAttempts = 1000000;
double cumulative_average = 0.0;
int count = 0;
while (count < kMaxAttempts) {
- uint64 value = base::RandGenerator(kTopOfRange);
+ uint64_t value = base::RandGenerator(kTopOfRange);
cumulative_average = (count * cumulative_average + value) / (count + 1);
// Don't quit too quickly for things to start converging, or we may have
@@ -113,13 +117,13 @@ TEST(RandUtilTest, RandGeneratorIsUniform) {
TEST(RandUtilTest, RandUint64ProducesBothValuesOfAllBits) {
// This tests to see that our underlying random generator is good
// enough, for some value of good enough.
- uint64 kAllZeros = 0ULL;
- uint64 kAllOnes = ~kAllZeros;
- uint64 found_ones = kAllZeros;
- uint64 found_zeros = kAllOnes;
+ uint64_t kAllZeros = 0ULL;
+ uint64_t kAllOnes = ~kAllZeros;
+ uint64_t found_ones = kAllZeros;
+ uint64_t found_zeros = kAllOnes;
for (size_t i = 0; i < 1000; ++i) {
- uint64 value = base::RandUint64();
+ uint64_t value = base::RandUint64();
found_ones |= value;
found_zeros &= value;
@@ -139,7 +143,7 @@ TEST(RandUtilTest, DISABLED_RandBytesPerf) {
const int kTestIterations = 10;
const size_t kTestBufferSize = 1 * 1024 * 1024;
- scoped_ptr<uint8[]> buffer(new uint8[kTestBufferSize]);
+ scoped_ptr<uint8_t[]> buffer(new uint8_t[kTestBufferSize]);
const base::TimeTicks now = base::TimeTicks::Now();
for (int i = 0; i < kTestIterations; ++i)
base::RandBytes(buffer.get(), kTestBufferSize);
« no previous file with comments | « base/rand_util_posix.cc ('k') | base/rand_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698