Index: webrtc/modules/audio_processing/utility/mean_calculator_unittest.cc |
diff --git a/webrtc/modules/audio_processing/utility/mean_calculator_unittest.cc b/webrtc/modules/audio_processing/utility/mean_calculator_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ca7b3075168c5e9cd542ab0bfc56df158ba083ce |
--- /dev/null |
+++ b/webrtc/modules/audio_processing/utility/mean_calculator_unittest.cc |
@@ -0,0 +1,55 @@ |
+/* |
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+#include "webrtc/modules/audio_processing/utility/mean_calculator.h" |
+ |
+namespace webrtc { |
+ |
+TEST(MeanCalculatorTest, Correctness) { |
+ const size_t kWindowLength = 10; |
+ MeanCalculator mean_calculator(kWindowLength); |
+ size_t i = 0; |
+ float reference = 0.0; |
+ |
+ for (; i < kWindowLength; ++i) { |
+ EXPECT_EQ(mean_calculator.GetNumberNewSamples(), i % kWindowLength); |
+ mean_calculator.AddSample(static_cast<float>(i)); |
+ } |
+ for (; i < 3 * kWindowLength; ++i) { |
+ const size_t new_samples = i % kWindowLength; |
+ if (new_samples == 0) { |
+ // Sum of (i - kWindowLength) ... (i - 1) |
+ reference = i - 0.5 * (1 + kWindowLength); |
+ } |
+ EXPECT_EQ(mean_calculator.GetNumberNewSamples(), new_samples); |
+ EXPECT_EQ(reference, mean_calculator.GetLatestMean()); |
+ mean_calculator.AddSample(static_cast<float>(i)); |
+ } |
+} |
+ |
+TEST(MeanCalculatorTest, Reset) { |
+ const size_t kWindowLength = 10; |
+ MeanCalculator mean_calculator(kWindowLength); |
+ for (size_t i = 0; i < kWindowLength - 1; ++i) { |
+ mean_calculator.AddSample(static_cast<float>(i)); |
+ } |
+ EXPECT_EQ(mean_calculator.GetNumberNewSamples(), kWindowLength - 1); |
+ mean_calculator.Reset(); |
+ for (size_t i = 0; i < kWindowLength; ++i) { |
+ EXPECT_EQ(mean_calculator.GetNumberNewSamples(), i); |
+ mean_calculator.AddSample(static_cast<float>(i)); |
+ } |
+ EXPECT_EQ(mean_calculator.GetNumberNewSamples(), 0u); |
+ EXPECT_EQ(mean_calculator.GetLatestMean(), 0.5 * (kWindowLength - 1)); |
+} |
+ |
+} // namespace webrtc |