blob: 41684b2b5c9d85e86682c3b0cefe5956d99fbce1 [file] [log] [blame]
Ilya Nikolaevskiyb9685752017-11-01 14:01:00 +01001/*
2 * Copyright 2017 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 "rtc_base/numerics/moving_median_filter.h"
Yves Gerey3e707812018-11-28 16:47:49 +010012
13#include <stdint.h>
14
Ilya Nikolaevskiyb9685752017-11-01 14:01:00 +010015#include "test/gtest.h"
16
17namespace webrtc {
18
19TEST(MovingMedianFilterTest, ProcessesNoSamples) {
20 MovingMedianFilter<int> filter(2);
21 EXPECT_EQ(0, filter.GetFilteredValue());
22}
23
24TEST(MovingMedianFilterTest, ReturnsMovingMedianWindow5) {
25 MovingMedianFilter<int> filter(5);
26 const int64_t kSamples[5] = {1, 5, 2, 3, 4};
27 const int64_t kExpectedFilteredValues[5] = {1, 1, 2, 2, 3};
28 for (int i = 0; i < 5; ++i) {
29 filter.Insert(kSamples[i]);
30 EXPECT_EQ(kExpectedFilteredValues[i], filter.GetFilteredValue());
31 }
32}
33
34TEST(MovingMedianFilterTest, ReturnsMovingMedianWindow3) {
35 MovingMedianFilter<int> filter(3);
36 const int64_t kSamples[5] = {1, 5, 2, 3, 4};
37 const int64_t kExpectedFilteredValues[5] = {1, 1, 2, 3, 3};
38 for (int i = 0; i < 5; ++i) {
39 filter.Insert(kSamples[i]);
40 EXPECT_EQ(kExpectedFilteredValues[i], filter.GetFilteredValue());
41 }
42}
43
44TEST(MovingMedianFilterTest, ReturnsMovingMedianWindow1) {
45 MovingMedianFilter<int> filter(1);
46 const int64_t kSamples[5] = {1, 5, 2, 3, 4};
47 const int64_t kExpectedFilteredValues[5] = {1, 5, 2, 3, 4};
48 for (int i = 0; i < 5; ++i) {
49 filter.Insert(kSamples[i]);
50 EXPECT_EQ(kExpectedFilteredValues[i], filter.GetFilteredValue());
51 }
52}
53
54} // namespace webrtc