Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2015 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/mean_calculator.h" | |
| 14 | |
| 15 namespace webrtc { | |
| 16 | |
| 17 TEST(MeanCalculatorTest, Fullness) { | |
|
peah-webrtc
2016/03/14 09:12:53
There should also be a test that checks that the c
minyue-webrtc
2016/03/14 14:51:42
renamed the test
peah-webrtc
2016/03/15 09:18:41
I think you should have a separate test that tests
| |
| 18 const size_t kWindowLength = 10; | |
| 19 MeanCalculator mean_calculator(kWindowLength); | |
| 20 size_t i = 0; | |
| 21 for (; i < kWindowLength; ++i) { | |
| 22 EXPECT_FALSE(mean_calculator.IsWindowFull()) << i; | |
| 23 EXPECT_FALSE(mean_calculator.GetMean()); | |
| 24 mean_calculator.AddSample(static_cast<float>(i)); | |
| 25 } | |
| 26 for (; i < 3 * kWindowLength; ++i) { | |
| 27 EXPECT_TRUE(mean_calculator.IsWindowFull()); | |
| 28 // (i - kWindowLength) ... (i - 1) | |
| 29 EXPECT_EQ(i - 0.5 * (1 + kWindowLength), *mean_calculator.GetMean()); | |
| 30 mean_calculator.AddSample(static_cast<float>(i)); | |
| 31 } | |
| 32 } | |
| 33 | |
| 34 TEST(MeanCalculatorTest, Flush) { | |
| 35 const size_t kWindowLength = 10; | |
| 36 MeanCalculator mean_calculator(kWindowLength); | |
| 37 for (size_t i = 0; i < kWindowLength; ++i) { | |
| 38 mean_calculator.AddSample(static_cast<float>(i)); | |
| 39 } | |
| 40 EXPECT_TRUE(mean_calculator.IsWindowFull()); | |
| 41 mean_calculator.Flush(); | |
| 42 | |
| 43 for (size_t i = 0; i < kWindowLength; ++i) { | |
| 44 EXPECT_FALSE(mean_calculator.IsWindowFull()); | |
| 45 EXPECT_FALSE(mean_calculator.GetMean()); | |
| 46 mean_calculator.AddSample(static_cast<float>(i)); | |
| 47 } | |
| 48 EXPECT_TRUE(mean_calculator.IsWindowFull()); | |
| 49 EXPECT_EQ(0.5 * (kWindowLength - 1), *mean_calculator.GetMean()); | |
| 50 } | |
| 51 | |
| 52 } // namespace webrt | |
| OLD | NEW |