tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

histogram_unittest.cc (2135B)


      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 "modules/video_coding/histogram.h"
     12 
     13 #include "test/gtest.h"
     14 
     15 namespace webrtc {
     16 namespace video_coding {
     17 
     18 class TestHistogram : public ::testing::Test {
     19 protected:
     20  TestHistogram() : histogram_(5, 10) {}
     21  Histogram histogram_;
     22 };
     23 
     24 TEST_F(TestHistogram, NumValues) {
     25  EXPECT_EQ(0ul, histogram_.NumValues());
     26  histogram_.Add(0);
     27  EXPECT_EQ(1ul, histogram_.NumValues());
     28 }
     29 
     30 TEST_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 
     47 TEST_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