OLD | NEW |
(Empty) | |
| 1 |
| 2 /* |
| 3 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 4 * |
| 5 * Use of this source code is governed by a BSD-style license |
| 6 * that can be found in the LICENSE file in the root of the source |
| 7 * tree. An additional intellectual property rights grant can be found |
| 8 * in the file PATENTS. All contributing project authors may |
| 9 * be found in the AUTHORS file in the root of the source tree. |
| 10 */ |
| 11 |
| 12 #include "webrtc/modules/audio_processing/echo_detector/mean_variance_estimator.
h" |
| 13 #include "webrtc/test/gtest.h" |
| 14 |
| 15 namespace webrtc { |
| 16 |
| 17 TEST(MeanVarianceEstimatorTests, InsertTwoValues) { |
| 18 MeanVarianceEstimator test_estimator; |
| 19 // Insert two values. |
| 20 test_estimator.Update(3.f); |
| 21 test_estimator.Update(5.f); |
| 22 |
| 23 EXPECT_GT(test_estimator.mean(), 0.f); |
| 24 EXPECT_GT(test_estimator.std_deviation(), 0.f); |
| 25 // Test Clear method |
| 26 test_estimator.Clear(); |
| 27 EXPECT_EQ(test_estimator.mean(), 0.f); |
| 28 EXPECT_EQ(test_estimator.std_deviation(), 0.f); |
| 29 } |
| 30 |
| 31 TEST(MeanVarianceEstimatorTests, InsertZeroes) { |
| 32 MeanVarianceEstimator test_estimator; |
| 33 // Insert the same value many times. |
| 34 for (size_t i = 0; i < 10000; i++) { |
| 35 test_estimator.Update(0.f); |
| 36 } |
| 37 EXPECT_EQ(test_estimator.mean(), 0.f); |
| 38 EXPECT_EQ(test_estimator.std_deviation(), 0.f); |
| 39 } |
| 40 |
| 41 TEST(MeanVarianceEstimatorTests, ConstantValueTest) { |
| 42 MeanVarianceEstimator test_estimator; |
| 43 for (size_t i = 0; i < 10000; i++) { |
| 44 test_estimator.Update(3.f); |
| 45 } |
| 46 // The mean should be close to three, and the standard deviation should be |
| 47 // close to zero. |
| 48 EXPECT_NEAR(3.0f, test_estimator.mean(), 0.01f); |
| 49 EXPECT_NEAR(0.0f, test_estimator.std_deviation(), 0.01f); |
| 50 } |
| 51 |
| 52 TEST(MeanVarianceEstimatorTests, AlternatingValueTest) { |
| 53 MeanVarianceEstimator test_estimator; |
| 54 for (size_t i = 0; i < 10000; i++) { |
| 55 test_estimator.Update(1.f); |
| 56 test_estimator.Update(-1.f); |
| 57 } |
| 58 // The mean should be close to zero, and the standard deviation should be |
| 59 // close to one. |
| 60 EXPECT_NEAR(0.0f, test_estimator.mean(), 0.01f); |
| 61 EXPECT_NEAR(1.0f, test_estimator.std_deviation(), 0.01f); |
| 62 } |
| 63 |
| 64 } // namespace webrtc |
OLD | NEW |