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 "modules/audio_processing/echo_detector/mean_variance_estimator.h"
13
14 #include "test/gtest.h"
15
16 namespace webrtc {
17
TEST(MeanVarianceEstimatorTests,InsertTwoValues)18 TEST(MeanVarianceEstimatorTests, InsertTwoValues) {
19 MeanVarianceEstimator test_estimator;
20 // Insert two values.
21 test_estimator.Update(3.f);
22 test_estimator.Update(5.f);
23
24 EXPECT_GT(test_estimator.mean(), 0.f);
25 EXPECT_GT(test_estimator.std_deviation(), 0.f);
26 // Test Clear method
27 test_estimator.Clear();
28 EXPECT_EQ(test_estimator.mean(), 0.f);
29 EXPECT_EQ(test_estimator.std_deviation(), 0.f);
30 }
31
TEST(MeanVarianceEstimatorTests,InsertZeroes)32 TEST(MeanVarianceEstimatorTests, InsertZeroes) {
33 MeanVarianceEstimator test_estimator;
34 // Insert the same value many times.
35 for (size_t i = 0; i < 20000; i++) {
36 test_estimator.Update(0.f);
37 }
38 EXPECT_EQ(test_estimator.mean(), 0.f);
39 EXPECT_EQ(test_estimator.std_deviation(), 0.f);
40 }
41
TEST(MeanVarianceEstimatorTests,ConstantValueTest)42 TEST(MeanVarianceEstimatorTests, ConstantValueTest) {
43 MeanVarianceEstimator test_estimator;
44 for (size_t i = 0; i < 20000; i++) {
45 test_estimator.Update(3.f);
46 }
47 // The mean should be close to three, and the standard deviation should be
48 // close to zero.
49 EXPECT_NEAR(3.0f, test_estimator.mean(), 0.01f);
50 EXPECT_NEAR(0.0f, test_estimator.std_deviation(), 0.01f);
51 }
52
TEST(MeanVarianceEstimatorTests,AlternatingValueTest)53 TEST(MeanVarianceEstimatorTests, AlternatingValueTest) {
54 MeanVarianceEstimator test_estimator;
55 for (size_t i = 0; i < 20000; i++) {
56 test_estimator.Update(1.f);
57 test_estimator.Update(-1.f);
58 }
59 // The mean should be close to zero, and the standard deviation should be
60 // close to one.
61 EXPECT_NEAR(0.0f, test_estimator.mean(), 0.01f);
62 EXPECT_NEAR(1.0f, test_estimator.std_deviation(), 0.01f);
63 }
64
65 } // namespace webrtc
66