Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
|
hlundin-webrtc
2016/10/17 18:49:42
None of the tests in this file test the EchoDetect
ivoc
2016/10/18 15:20:20
Done.
| |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 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 | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "webrtc/modules/audio_processing/echo_detector/circular_buffer.h" | |
| 14 #include "webrtc/modules/audio_processing/echo_detector/mean_variance_estimator. h" | |
| 15 #include "webrtc/modules/audio_processing/echo_detector/normalized_covariance_es timator.h" | |
| 16 #include "webrtc/test/gtest.h" | |
| 17 | |
| 18 namespace webrtc { | |
| 19 | |
| 20 TEST(EchoDetectorTests, CircularBufferTest) { | |
|
hlundin-webrtc
2016/10/17 18:49:41
This tests the CircularBuffer class. Move to circu
ivoc
2016/10/18 15:20:19
Done.
| |
| 21 CircularBuffer test_buffer(3); | |
|
hlundin-webrtc
2016/10/17 18:49:43
Test a few other cases too, like reading from an e
| |
| 22 test_buffer.Insert(1.f); | |
| 23 test_buffer.Insert(2.f); | |
| 24 test_buffer.Insert(3.f); | |
| 25 test_buffer.Insert(4.f); | |
| 26 // Because the circular buffer has a size of 3, the first insert should have | |
| 27 // been forgotten. | |
| 28 EXPECT_EQ(2.f, test_buffer.GetValue()); | |
| 29 EXPECT_EQ(3.f, test_buffer.GetValue()); | |
| 30 EXPECT_EQ(4.f, test_buffer.GetValue()); | |
| 31 } | |
| 32 | |
| 33 TEST(EchoDetectorTests, MeanVarianceEstimatorInsertTwoValues) { | |
|
hlundin-webrtc
2016/10/17 18:49:42
Move to mean_variance_estimator_unittest.cc.
ivoc
2016/10/18 15:20:19
Done.
| |
| 34 MeanVarianceEstimator test_estimator; | |
| 35 // Insert two values. | |
| 36 test_estimator.UpdateEstimate(3.f); | |
| 37 test_estimator.UpdateEstimate(5.f); | |
| 38 | |
| 39 EXPECT_GT(test_estimator.mean(), 0.f); | |
|
hlundin-webrtc
2016/10/17 18:49:41
Can't you EXPECT_EQ instead?
ivoc
2016/10/18 15:20:19
I could, but then the value depends on the exact i
hlundin-webrtc
2016/10/18 20:52:21
This is fine.
| |
| 40 EXPECT_GT(test_estimator.std_deviation(), 0.f); | |
|
hlundin-webrtc
2016/10/17 18:49:43
And here.
| |
| 41 // Test Clear method | |
| 42 test_estimator.Clear(); | |
| 43 EXPECT_EQ(test_estimator.mean(), 0.f); | |
| 44 EXPECT_EQ(test_estimator.std_deviation(), 0.f); | |
| 45 } | |
| 46 | |
| 47 TEST(EchoDetectorTests, MeanVarianceEstimatorInsertZeroes) { | |
| 48 MeanVarianceEstimator test_estimator; | |
| 49 // Insert the same value many times. | |
| 50 for (int i = 0; i < 10000; i++) { | |
|
hlundin-webrtc
2016/10/17 18:49:42
size_t
Several places.
ivoc
2016/10/18 15:20:19
Done, but the style guide says not to use size_t e
hlundin-webrtc
2016/10/18 20:52:21
I think the restriction applies to the fixed-width
| |
| 51 test_estimator.UpdateEstimate(0.f); | |
| 52 } | |
| 53 EXPECT_EQ(test_estimator.mean(), 0.f); | |
| 54 EXPECT_EQ(test_estimator.std_deviation(), 0.f); | |
| 55 } | |
| 56 | |
| 57 TEST(EchoDetectorTests, MeanVarianceEstimatorConstantValueTest) { | |
| 58 MeanVarianceEstimator test_estimator; | |
| 59 for (int i = 0; i < 10000; i++) { | |
| 60 test_estimator.UpdateEstimate(3.f); | |
| 61 } | |
| 62 // The mean should be close to three, and the standard deviation should be | |
| 63 // close to zero. | |
| 64 EXPECT_LT(std::abs(test_estimator.mean() - 3.f), 0.01f); | |
|
hlundin-webrtc
2016/10/17 18:49:42
Use EXPECT_FLOAT_EQ if the values are close enough
ivoc
2016/10/18 15:20:20
Done.
| |
| 65 EXPECT_LT(std::abs(test_estimator.std_deviation()), 0.01f); | |
| 66 } | |
| 67 | |
| 68 TEST(EchoDetectorTests, MeanVarianceEstimatorAlternatingValueTest) { | |
| 69 MeanVarianceEstimator test_estimator; | |
| 70 for (int i = 0; i < 10000; i++) { | |
| 71 test_estimator.UpdateEstimate(1.f); | |
| 72 test_estimator.UpdateEstimate(-1.f); | |
| 73 } | |
| 74 // The mean should be close to zero, and the standard deviation should be | |
| 75 // close to one. | |
| 76 EXPECT_LT(std::abs(test_estimator.mean()), 0.01f); | |
| 77 EXPECT_LT(std::abs(test_estimator.std_deviation() - 1.f), 0.01f); | |
| 78 } | |
| 79 | |
| 80 TEST(EchoDetectorTests, NormalizedCovarianceEstimatorIdenticalSignalTest) { | |
|
hlundin-webrtc
2016/10/17 18:49:42
Move to normalized_covariance_estimator_unittests.
ivoc
2016/10/18 15:20:19
Done.
| |
| 81 MeanVarianceEstimator mean_variance_estimator; | |
|
hlundin-webrtc
2016/10/17 18:49:41
You don't need this object, right? The test will b
ivoc
2016/10/18 15:20:19
Ok, I can remove it and use the true values. This
| |
| 82 NormalizedCovarianceEstimator test_estimator; | |
| 83 for (int i = 0; i < 10000; i++) { | |
| 84 mean_variance_estimator.UpdateEstimate(1.f); | |
| 85 test_estimator.UpdateCovarianceEstimate( | |
| 86 1.f, mean_variance_estimator.mean(), | |
| 87 mean_variance_estimator.std_deviation(), 1.f, | |
| 88 mean_variance_estimator.mean(), | |
| 89 mean_variance_estimator.std_deviation()); | |
| 90 mean_variance_estimator.UpdateEstimate(-1.f); | |
| 91 test_estimator.UpdateCovarianceEstimate( | |
| 92 -1.f, mean_variance_estimator.mean(), | |
| 93 mean_variance_estimator.std_deviation(), -1.f, | |
| 94 mean_variance_estimator.mean(), | |
| 95 mean_variance_estimator.std_deviation()); | |
| 96 } | |
| 97 // A normalized covariance value close to 1 is expected. | |
| 98 EXPECT_LT(std::abs(test_estimator.normalized_cross_correlation() - 1.f), | |
| 99 0.01f); | |
| 100 test_estimator.Clear(); | |
| 101 EXPECT_EQ(0.f, test_estimator.normalized_cross_correlation()); | |
| 102 } | |
| 103 | |
| 104 TEST(EchoDetectorTests, NormalizedCovarianceEstimatorOppositeSignalTest) { | |
| 105 MeanVarianceEstimator mean_variance_estimator1; | |
| 106 MeanVarianceEstimator mean_variance_estimator2; | |
| 107 NormalizedCovarianceEstimator test_estimator; | |
|
hlundin-webrtc
2016/10/17 18:49:42
Same comments apply to this as to the previous tes
ivoc
2016/10/18 15:20:19
Done.
| |
| 108 // Insert the same value many times. | |
| 109 for (int i = 0; i < 10000; i++) { | |
| 110 mean_variance_estimator1.UpdateEstimate(1.f); | |
| 111 mean_variance_estimator2.UpdateEstimate(-1.f); | |
| 112 test_estimator.UpdateCovarianceEstimate( | |
| 113 1.f, mean_variance_estimator1.mean(), | |
| 114 mean_variance_estimator1.std_deviation(), -1.f, | |
| 115 mean_variance_estimator2.mean(), | |
| 116 mean_variance_estimator2.std_deviation()); | |
| 117 mean_variance_estimator1.UpdateEstimate(-1.f); | |
| 118 mean_variance_estimator2.UpdateEstimate(1.f); | |
| 119 test_estimator.UpdateCovarianceEstimate( | |
| 120 -1.f, mean_variance_estimator1.mean(), | |
| 121 mean_variance_estimator1.std_deviation(), 1.f, | |
| 122 mean_variance_estimator2.mean(), | |
| 123 mean_variance_estimator2.std_deviation()); | |
| 124 } | |
| 125 // A normalized covariance value close to -1 is expected. | |
| 126 EXPECT_LT(std::abs(test_estimator.normalized_cross_correlation() + 1.f), | |
| 127 0.01f); | |
| 128 } | |
| 129 | |
| 130 } // namespace webrtc | |
| OLD | NEW |