OLD | NEW |
(Empty) | |
| 1 /* |
| 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 "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 #include "webrtc/modules/audio_processing/utility/block_mean_calculator.h" |
| 14 |
| 15 namespace webrtc { |
| 16 |
| 17 TEST(MeanCalculatorTest, Correctness) { |
| 18 const size_t kBlockLength = 10; |
| 19 BlockMeanCalculator mean_calculator(kBlockLength); |
| 20 size_t i = 0; |
| 21 float reference = 0.0; |
| 22 |
| 23 for (; i < kBlockLength - 1; ++i) { |
| 24 mean_calculator.AddValue(static_cast<float>(i)); |
| 25 EXPECT_FALSE(mean_calculator.EndOfBlock()); |
| 26 } |
| 27 mean_calculator.AddValue(static_cast<float>(i++)); |
| 28 EXPECT_TRUE(mean_calculator.EndOfBlock()); |
| 29 |
| 30 for (; i < 3 * kBlockLength; ++i) { |
| 31 const bool end_of_block = i % kBlockLength == 0; |
| 32 if (end_of_block) { |
| 33 // Sum of (i - kBlockLength) ... (i - 1) |
| 34 reference = i - 0.5 * (1 + kBlockLength); |
| 35 } |
| 36 EXPECT_EQ(mean_calculator.EndOfBlock(), end_of_block); |
| 37 EXPECT_EQ(reference, mean_calculator.GetLatestMean()); |
| 38 mean_calculator.AddValue(static_cast<float>(i)); |
| 39 } |
| 40 } |
| 41 |
| 42 TEST(MeanCalculatorTest, Reset) { |
| 43 const size_t kBlockLength = 10; |
| 44 BlockMeanCalculator mean_calculator(kBlockLength); |
| 45 for (size_t i = 0; i < kBlockLength - 1; ++i) { |
| 46 mean_calculator.AddValue(static_cast<float>(i)); |
| 47 } |
| 48 mean_calculator.Reset(); |
| 49 size_t i = 0; |
| 50 for (; i < kBlockLength - 1; ++i) { |
| 51 mean_calculator.AddValue(static_cast<float>(i)); |
| 52 EXPECT_FALSE(mean_calculator.EndOfBlock()); |
| 53 } |
| 54 mean_calculator.AddValue(static_cast<float>(i)); |
| 55 EXPECT_TRUE(mean_calculator.EndOfBlock()); |
| 56 EXPECT_EQ(mean_calculator.GetLatestMean(), 0.5 * (kBlockLength - 1)); |
| 57 } |
| 58 |
| 59 } // namespace webrtc |
OLD | NEW |