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

Unified Diff: base/rand_util_unittest.cc

Issue 7685053: Fix variable names and comments in RandGenerator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: numeric_limits Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/rand_util.cc ('k') | no next file » | 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 b81e2efc7b4c92ea56e1d77d536b7b350b8ebfe9..a3474ba6948dc81f2d447058f985e5717bcd0241 100644
--- a/base/rand_util_unittest.cc
+++ b/base/rand_util_unittest.cc
@@ -4,6 +4,7 @@
#include "base/rand_util.h"
+#include <algorithm>
#include <limits>
#include "testing/gtest/include/gtest/gtest.h"
@@ -29,16 +30,14 @@ TEST(RandUtilTest, RandDouble) {
}
TEST(RandUtilTest, RandBytes) {
- const size_t buffer_size = 145;
+ const size_t buffer_size = 50;
char buffer[buffer_size];
memset(buffer, 0, buffer_size);
base::RandBytes(buffer, buffer_size);
- char accumulator = 0;
- for(size_t i = 0; i < buffer_size; ++i)
- accumulator |= buffer[i];
- // In theory this test can fail, but it won't before the universe dies of
- // heat death.
- EXPECT_NE(0, accumulator);
+ std::sort(buffer, buffer + buffer_size);
+ // Probability of occurrence of less than 25 unique bytes in 50 random bytes
+ // is below 10^-25.
+ EXPECT_GT(std::unique(buffer, buffer + buffer_size) - buffer, 25);
}
TEST(RandUtilTest, RandBytesAsString) {
« no previous file with comments | « base/rand_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698