Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: webrtc/modules/audio_processing/utility/block_fraction_calculator_unittest.cc

Issue 1739993003: Adding fraction of filter divergence in AEC metrics. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: adding block_fraction_calculator and more Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_fraction_calculator.h"
14
15 namespace webrtc {
16
17 TEST(BlockFractionCalculatorTest, Correctness) {
18 const size_t kBlockLength = 9; // This has to be an odd number.
19 BlockFractionCalculator fraction_calculator(kBlockLength);
20 float reference = -1.0;
21
22 for (size_t i = 1; i < 3 * kBlockLength; ++i) {
23 EXPECT_EQ(reference, fraction_calculator.GetLatestFraction());
24 fraction_calculator.AddObservation(i % 2);
25
26 const bool end_of_block = i % kBlockLength == 0;
27 if (end_of_block) {
28 const float old_reference = reference;
29 // Fraction of even numbers in (i - kBlockLength + 1) ... i
30 reference = static_cast<float>((kBlockLength + (i % 2 ? 1 : 0)) / 2) /
31 kBlockLength;
32 // kBlockLength has to be an odd number to make fraction alternating.
33 EXPECT_NE(reference, old_reference);
34 }
35 }
36 }
37
38 TEST(BlockFractionCalculatorTest, Reset) {
39 const size_t kBlockLength = 9;
40 BlockFractionCalculator fraction_calculator(kBlockLength);
41 for (size_t i = 1; i < kBlockLength; ++i) {
42 fraction_calculator.AddObservation(i % 2);
43 }
44 fraction_calculator.Reset();
45 for (size_t i = 0; i < kBlockLength; ++i) {
46 fraction_calculator.AddObservation(i % 2);
47 }
48 EXPECT_EQ(fraction_calculator.GetLatestFraction(),
49 static_cast<float>(kBlockLength / 2) / kBlockLength);
50 }
51
52 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698