| Index: webrtc/modules/audio_processing/utility/block_fraction_calculator_unittest.cc
|
| diff --git a/webrtc/modules/audio_processing/utility/block_fraction_calculator_unittest.cc b/webrtc/modules/audio_processing/utility/block_fraction_calculator_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..005ab3bc43bbe3ce055837be0e7bceb1047eb495
|
| --- /dev/null
|
| +++ b/webrtc/modules/audio_processing/utility/block_fraction_calculator_unittest.cc
|
| @@ -0,0 +1,52 @@
|
| +/*
|
| + * 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/block_fraction_calculator.h"
|
| +
|
| +namespace webrtc {
|
| +
|
| +TEST(BlockFractionCalculatorTest, Correctness) {
|
| + const size_t kBlockLength = 9; // This has to be an odd number.
|
| + BlockFractionCalculator fraction_calculator(kBlockLength);
|
| + float reference = -1.0;
|
| +
|
| + for (size_t i = 1; i < 3 * kBlockLength; ++i) {
|
| + EXPECT_EQ(reference, fraction_calculator.GetLatestFraction());
|
| + fraction_calculator.AddObservation(i % 2);
|
| +
|
| + const bool end_of_block = i % kBlockLength == 0;
|
| + if (end_of_block) {
|
| + const float old_reference = reference;
|
| + // Fraction of even numbers in (i - kBlockLength + 1) ... i
|
| + reference = static_cast<float>((kBlockLength + (i % 2 ? 1 : 0)) / 2) /
|
| + kBlockLength;
|
| + // kBlockLength has to be an odd number to make fraction alternating.
|
| + EXPECT_NE(reference, old_reference);
|
| + }
|
| + }
|
| +}
|
| +
|
| +TEST(BlockFractionCalculatorTest, Reset) {
|
| + const size_t kBlockLength = 9;
|
| + BlockFractionCalculator fraction_calculator(kBlockLength);
|
| + for (size_t i = 1; i < kBlockLength; ++i) {
|
| + fraction_calculator.AddObservation(i % 2);
|
| + }
|
| + fraction_calculator.Reset();
|
| + for (size_t i = 0; i < kBlockLength; ++i) {
|
| + fraction_calculator.AddObservation(i % 2);
|
| + }
|
| + EXPECT_EQ(fraction_calculator.GetLatestFraction(),
|
| + static_cast<float>(kBlockLength / 2) / kBlockLength);
|
| +}
|
| +
|
| +} // namespace webrtc
|
|
|