OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 BucketTestUnsignedInterval(7, 100000, 1, 14, 3, &prng); | 191 BucketTestUnsignedInterval(7, 100000, 1, 14, 3, &prng); |
192 BucketTestUnsignedInterval(11, 100000, 1000, 1010, 3, &prng); | 192 BucketTestUnsignedInterval(11, 100000, 1000, 1010, 3, &prng); |
193 BucketTestUnsignedInterval(100, 100000, 0, 99, 3, &prng); | 193 BucketTestUnsignedInterval(100, 100000, 0, 99, 3, &prng); |
194 BucketTestUnsignedInterval(2, 100000, 0, 4294967295, 3, &prng); | 194 BucketTestUnsignedInterval(2, 100000, 0, 4294967295, 3, &prng); |
195 BucketTestUnsignedInterval(17, 100000, 455, 2147484110, 3, &prng); | 195 BucketTestUnsignedInterval(17, 100000, 455, 2147484110, 3, &prng); |
196 // 99.7% of all samples will be within 3 standard deviations of the mean, | 196 // 99.7% of all samples will be within 3 standard deviations of the mean, |
197 // but since we test 1000 buckets we allow an interval of 4 sigma. | 197 // but since we test 1000 buckets we allow an interval of 4 sigma. |
198 BucketTestUnsignedInterval(1000, 1000000, 0, 2147483999, 4, &prng); | 198 BucketTestUnsignedInterval(1000, 1000000, 0, 2147483999, 4, &prng); |
199 } | 199 } |
200 | 200 |
201 TEST(RandomNumberGeneratorTest, UniformSignedInterval) { | 201 // Disabled for UBSan: https://bugs.chromium.org/p/webrtc/issues/detail?id=5491 |
| 202 #ifdef UNDEFINED_SANITIZER |
| 203 #define MAYBE_UniformSignedInterval DISABLED_UniformSignedInterval |
| 204 #else |
| 205 #define MAYBE_UniformSignedInterval UniformSignedInterval |
| 206 #endif |
| 207 TEST(RandomNumberGeneratorTest, MAYBE_UniformSignedInterval) { |
202 Random prng(66260695729ull); | 208 Random prng(66260695729ull); |
203 BucketTestSignedInterval(2, 100000, 0, 1, 3, &prng); | 209 BucketTestSignedInterval(2, 100000, 0, 1, 3, &prng); |
204 BucketTestSignedInterval(7, 100000, -2, 4, 3, &prng); | 210 BucketTestSignedInterval(7, 100000, -2, 4, 3, &prng); |
205 BucketTestSignedInterval(11, 100000, 1000, 1010, 3, &prng); | 211 BucketTestSignedInterval(11, 100000, 1000, 1010, 3, &prng); |
206 BucketTestSignedInterval(100, 100000, 0, 99, 3, &prng); | 212 BucketTestSignedInterval(100, 100000, 0, 99, 3, &prng); |
207 BucketTestSignedInterval(2, 100000, std::numeric_limits<int32_t>::min(), | 213 BucketTestSignedInterval(2, 100000, std::numeric_limits<int32_t>::min(), |
208 std::numeric_limits<int32_t>::max(), 3, &prng); | 214 std::numeric_limits<int32_t>::max(), 3, &prng); |
209 BucketTestSignedInterval(17, 100000, -1073741826, 1073741829, 3, &prng); | 215 BucketTestSignedInterval(17, 100000, -1073741826, 1073741829, 3, &prng); |
210 // 99.7% of all samples will be within 3 standard deviations of the mean, | 216 // 99.7% of all samples will be within 3 standard deviations of the mean, |
211 // but since we test 1000 buckets we allow an interval of 4 sigma. | 217 // but since we test 1000 buckets we allow an interval of 4 sigma. |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 double f_mid = kScale * exp((n - kMean) * (n - kMean) / kDiv); | 299 double f_mid = kScale * exp((n - kMean) * (n - kMean) / kDiv); |
294 double f_right = kScale * exp((n - kMean + 0.5) * (n - kMean + 0.5) / kDiv); | 300 double f_right = kScale * exp((n - kMean + 0.5) * (n - kMean + 0.5) / kDiv); |
295 double normal_dist = (f_left + 4 * f_mid + f_right) / 6; | 301 double normal_dist = (f_left + 4 * f_mid + f_right) / 6; |
296 // Expect the number of samples to be within 3 standard deviations | 302 // Expect the number of samples to be within 3 standard deviations |
297 // (rounded up) of the expected number of samples in the bucket. | 303 // (rounded up) of the expected number of samples in the bucket. |
298 EXPECT_NEAR(buckets[n], kN * normal_dist, 3 * sqrt(kN * normal_dist) + 1); | 304 EXPECT_NEAR(buckets[n], kN * normal_dist, 3 * sqrt(kN * normal_dist) + 1); |
299 } | 305 } |
300 } | 306 } |
301 | 307 |
302 } // namespace webrtc | 308 } // namespace webrtc |
OLD | NEW |