OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2017 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 "webrtc/modules/audio_processing/echo_detector/moving_max.h" |
| 12 #include "webrtc/test/gtest.h" |
| 13 |
| 14 namespace webrtc { |
| 15 |
| 16 // Test if the maximum is correctly found. |
| 17 TEST(MovingMaxTests, SimpleTest) { |
| 18 MovingMax test_moving_max(5); |
| 19 test_moving_max.Update(1.0f); |
| 20 test_moving_max.Update(1.1f); |
| 21 test_moving_max.Update(1.9f); |
| 22 test_moving_max.Update(1.87f); |
| 23 test_moving_max.Update(1.89f); |
| 24 EXPECT_EQ(1.9f, test_moving_max.max()); |
| 25 } |
| 26 |
| 27 // Test if values fall out of the window when expected. |
| 28 TEST(MovingMaxTests, SlidingWindowTest) { |
| 29 MovingMax test_moving_max(5); |
| 30 test_moving_max.Update(1.0f); |
| 31 test_moving_max.Update(1.9f); |
| 32 test_moving_max.Update(1.7f); |
| 33 test_moving_max.Update(1.87f); |
| 34 test_moving_max.Update(1.89f); |
| 35 test_moving_max.Update(1.3f); |
| 36 test_moving_max.Update(1.2f); |
| 37 EXPECT_LT(test_moving_max.max(), 1.9f); |
| 38 } |
| 39 |
| 40 // Test if Clear() works as expected. |
| 41 TEST(MovingMaxTests, ClearTest) { |
| 42 MovingMax test_moving_max(5); |
| 43 test_moving_max.Update(1.0f); |
| 44 test_moving_max.Update(1.1f); |
| 45 test_moving_max.Update(1.9f); |
| 46 test_moving_max.Update(1.87f); |
| 47 test_moving_max.Update(1.89f); |
| 48 EXPECT_EQ(1.9f, test_moving_max.max()); |
| 49 test_moving_max.Clear(); |
| 50 EXPECT_EQ(0.f, test_moving_max.max()); |
| 51 } |
| 52 |
| 53 // Test the decay of the estimated maximum. |
| 54 TEST(MovingMaxTests, DecayTest) { |
| 55 MovingMax test_moving_max(1); |
| 56 test_moving_max.Update(1.0f); |
| 57 float previous_value = 1.0f; |
| 58 for (int i = 0; i < 500; i++) { |
| 59 test_moving_max.Update(0.0f); |
| 60 EXPECT_LT(test_moving_max.max(), previous_value); |
| 61 EXPECT_GT(test_moving_max.max(), 0.0f); |
| 62 previous_value = test_moving_max.max(); |
| 63 } |
| 64 EXPECT_LT(test_moving_max.max(), 0.01f); |
| 65 } |
| 66 |
| 67 } // namespace webrtc |
OLD | NEW |