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/normalized_covariance_estimator.h"
13 
14 #include "test/gtest.h"
15 
16 namespace webrtc {
17 
TEST(NormalizedCovarianceEstimatorTests,IdenticalSignalTest)18 TEST(NormalizedCovarianceEstimatorTests, IdenticalSignalTest) {
19   NormalizedCovarianceEstimator test_estimator;
20   for (size_t i = 0; i < 10000; i++) {
21     test_estimator.Update(1.f, 0.f, 1.f, 1.f, 0.f, 1.f);
22     test_estimator.Update(-1.f, 0.f, 1.f, -1.f, 0.f, 1.f);
23   }
24   // A normalized covariance value close to 1 is expected.
25   EXPECT_NEAR(1.f, test_estimator.normalized_cross_correlation(), 0.01f);
26   test_estimator.Clear();
27   EXPECT_EQ(0.f, test_estimator.normalized_cross_correlation());
28 }
29 
TEST(NormalizedCovarianceEstimatorTests,OppositeSignalTest)30 TEST(NormalizedCovarianceEstimatorTests, OppositeSignalTest) {
31   NormalizedCovarianceEstimator test_estimator;
32   // Insert the same value many times.
33   for (size_t i = 0; i < 10000; i++) {
34     test_estimator.Update(1.f, 0.f, 1.f, -1.f, 0.f, 1.f);
35     test_estimator.Update(-1.f, 0.f, 1.f, 1.f, 0.f, 1.f);
36   }
37   // A normalized covariance value close to -1 is expected.
38   EXPECT_NEAR(-1.f, test_estimator.normalized_cross_correlation(), 0.01f);
39 }
40 
41 }  // namespace webrtc
42