blob: 3690a3939863962de296594eee017d6f241dfcbf [file] [log] [blame]
philipel5ab4c6d2016-03-08 03:36:15 -08001/*
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/video_coding/histogram.h"
Jonas Olssona4d87372019-07-05 19:08:33 +020012
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "test/gtest.h"
philipel5ab4c6d2016-03-08 03:36:15 -080014
15namespace webrtc {
16namespace video_coding {
17
18class TestHistogram : public ::testing::Test {
19 protected:
20 TestHistogram() : histogram_(5, 10) {}
21 Histogram histogram_;
22};
23
24TEST_F(TestHistogram, NumValues) {
25 EXPECT_EQ(0ul, histogram_.NumValues());
26 histogram_.Add(0);
27 EXPECT_EQ(1ul, histogram_.NumValues());
28}
29
30TEST_F(TestHistogram, InverseCdf) {
31 histogram_.Add(0);
32 histogram_.Add(1);
33 histogram_.Add(2);
34 histogram_.Add(3);
35 histogram_.Add(4);
36 EXPECT_EQ(5ul, histogram_.NumValues());
37 EXPECT_EQ(1ul, histogram_.InverseCdf(0.2f));
38 EXPECT_EQ(2ul, histogram_.InverseCdf(0.2000001f));
39 EXPECT_EQ(4ul, histogram_.InverseCdf(0.8f));
40
41 histogram_.Add(0);
42 EXPECT_EQ(6ul, histogram_.NumValues());
43 EXPECT_EQ(1ul, histogram_.InverseCdf(0.2f));
44 EXPECT_EQ(1ul, histogram_.InverseCdf(0.2000001f));
45}
46
47TEST_F(TestHistogram, ReplaceOldValues) {
48 histogram_.Add(0);
49 histogram_.Add(0);
50 histogram_.Add(0);
51 histogram_.Add(0);
52 histogram_.Add(0);
53 histogram_.Add(1);
54 histogram_.Add(1);
55 histogram_.Add(1);
56 histogram_.Add(1);
57 histogram_.Add(1);
58 EXPECT_EQ(10ul, histogram_.NumValues());
59 EXPECT_EQ(1ul, histogram_.InverseCdf(0.5f));
60 EXPECT_EQ(2ul, histogram_.InverseCdf(0.5000001f));
61
62 histogram_.Add(4);
63 histogram_.Add(4);
64 histogram_.Add(4);
65 histogram_.Add(4);
66 EXPECT_EQ(10ul, histogram_.NumValues());
67 EXPECT_EQ(1ul, histogram_.InverseCdf(0.1f));
68 EXPECT_EQ(2ul, histogram_.InverseCdf(0.5f));
69
70 histogram_.Add(20);
71 EXPECT_EQ(10ul, histogram_.NumValues());
72 EXPECT_EQ(2ul, histogram_.InverseCdf(0.5f));
73 EXPECT_EQ(5ul, histogram_.InverseCdf(0.5000001f));
74}
75
76} // namespace video_coding
77} // namespace webrtc