| 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 |
| 11 #include <math.h> | 11 #include <math.h> |
| 12 | 12 |
| 13 #include <limits> | 13 #include <limits> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "webrtc/base/mathutils.h" // unsigned difference | 16 #include "webrtc/base/mathutils.h" // unsigned difference |
| 17 #include "webrtc/base/random.h" | 17 #include "webrtc/base/random.h" |
| 18 #include "webrtc/test/gtest.h" | 18 #include "webrtc/test/gtest.h" |
| 19 | 19 |
| 20 namespace webrtc { | 20 namespace webrtc { |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 // Computes the positive remainder of x/n. | 23 // Computes the positive remainder of x/n. |
| 24 template <typename T> | 24 template <typename T> |
| 25 T fdiv_remainder(T x, T n) { | 25 T fdiv_remainder(T x, T n) { |
| 26 RTC_CHECK_GE(n, static_cast<T>(0)); | 26 RTC_CHECK_GE(n, 0); |
| 27 T remainder = x % n; | 27 T remainder = x % n; |
| 28 if (remainder < 0) | 28 if (remainder < 0) |
| 29 remainder += n; | 29 remainder += n; |
| 30 return remainder; | 30 return remainder; |
| 31 } | 31 } |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 // Sample a number of random integers of type T. Divide them into buckets | 34 // Sample a number of random integers of type T. Divide them into buckets |
| 35 // based on the remainder when dividing by bucket_count and check that each | 35 // based on the remainder when dividing by bucket_count and check that each |
| 36 // bucket gets roughly the expected number of elements. | 36 // bucket gets roughly the expected number of elements. |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 double f_mid = kScale * exp((n - kMean) * (n - kMean) / kDiv); | 300 double f_mid = kScale * exp((n - kMean) * (n - kMean) / kDiv); |
| 301 double f_right = kScale * exp((n - kMean + 0.5) * (n - kMean + 0.5) / kDiv); | 301 double f_right = kScale * exp((n - kMean + 0.5) * (n - kMean + 0.5) / kDiv); |
| 302 double normal_dist = (f_left + 4 * f_mid + f_right) / 6; | 302 double normal_dist = (f_left + 4 * f_mid + f_right) / 6; |
| 303 // Expect the number of samples to be within 3 standard deviations | 303 // Expect the number of samples to be within 3 standard deviations |
| 304 // (rounded up) of the expected number of samples in the bucket. | 304 // (rounded up) of the expected number of samples in the bucket. |
| 305 EXPECT_NEAR(buckets[n], kN * normal_dist, 3 * sqrt(kN * normal_dist) + 1); | 305 EXPECT_NEAR(buckets[n], kN * normal_dist, 3 * sqrt(kN * normal_dist) + 1); |
| 306 } | 306 } |
| 307 } | 307 } |
| 308 | 308 |
| 309 } // namespace webrtc | 309 } // namespace webrtc |
| OLD | NEW |