aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/core/test/firebase/firestore/util/secure_random_test.cc
diff options
context:
space:
mode:
authorGravatar zxu <zxu@google.com>2018-01-27 17:53:27 -0500
committerGravatar Gil <mcg@google.com>2018-01-27 14:53:27 -0800
commitaf6976a907b0d2a9fadbb14d7258bab44f075364 (patch)
tree62918ca2d8da0696967e3003e495ba11cd56bf33 /Firestore/core/test/firebase/firestore/util/secure_random_test.cc
parent7226b4adf38e4732dfb9a840d25f86d3e5533bdb (diff)
normalize and port the rest of Firebase/Port code (#713)
* normalize bits * normalize ordered_code
Diffstat (limited to 'Firestore/core/test/firebase/firestore/util/secure_random_test.cc')
-rw-r--r--Firestore/core/test/firebase/firestore/util/secure_random_test.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/Firestore/core/test/firebase/firestore/util/secure_random_test.cc b/Firestore/core/test/firebase/firestore/util/secure_random_test.cc
index ee2ae00..0b7a51b 100644
--- a/Firestore/core/test/firebase/firestore/util/secure_random_test.cc
+++ b/Firestore/core/test/firebase/firestore/util/secure_random_test.cc
@@ -30,3 +30,28 @@ TEST(SecureRandomTest, ResultsAreBounded) {
EXPECT_LE(value, rng.max());
}
}
+
+TEST(SecureRandomTest, Uniform) {
+ SecureRandom rng;
+ int count[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+
+ for (int i = 0; i < 1000; i++) {
+ count[rng.Uniform(10)]++;
+ }
+ for (int i = 0; i < 10; i++) {
+ // Practically, each count should be close to 100.
+ EXPECT_LT(50, count[i]) << count[i];
+ }
+}
+
+TEST(SecureRandomTest, OneIn) {
+ SecureRandom rng;
+ int count = 0;
+
+ for (int i = 0; i < 1000; i++) {
+ if (rng.OneIn(10)) count++;
+ }
+ // Practically, count should be close to 100.
+ EXPECT_LT(50, count) << count;
+ EXPECT_GT(150, count) << count;
+}