From af6976a907b0d2a9fadbb14d7258bab44f075364 Mon Sep 17 00:00:00 2001 From: zxu Date: Sat, 27 Jan 2018 17:53:27 -0500 Subject: normalize and port the rest of Firebase/Port code (#713) * normalize bits * normalize ordered_code --- .../firebase/firestore/util/secure_random_test.cc | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'Firestore/core/test/firebase/firestore/util/secure_random_test.cc') 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; +} -- cgit v1.2.3