You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #include "modules/video_coding/histogram.h"
  11. #include "test/gtest.h"
  12. namespace webrtc {
  13. namespace video_coding {
  14. class TestHistogram : public ::testing::Test {
  15. protected:
  16. TestHistogram() : histogram_(5, 10) {}
  17. Histogram histogram_;
  18. };
  19. TEST_F(TestHistogram, NumValues) {
  20. EXPECT_EQ(0ul, histogram_.NumValues());
  21. histogram_.Add(0);
  22. EXPECT_EQ(1ul, histogram_.NumValues());
  23. }
  24. TEST_F(TestHistogram, InverseCdf) {
  25. histogram_.Add(0);
  26. histogram_.Add(1);
  27. histogram_.Add(2);
  28. histogram_.Add(3);
  29. histogram_.Add(4);
  30. EXPECT_EQ(5ul, histogram_.NumValues());
  31. EXPECT_EQ(1ul, histogram_.InverseCdf(0.2f));
  32. EXPECT_EQ(2ul, histogram_.InverseCdf(0.2000001f));
  33. EXPECT_EQ(4ul, histogram_.InverseCdf(0.8f));
  34. histogram_.Add(0);
  35. EXPECT_EQ(6ul, histogram_.NumValues());
  36. EXPECT_EQ(1ul, histogram_.InverseCdf(0.2f));
  37. EXPECT_EQ(1ul, histogram_.InverseCdf(0.2000001f));
  38. }
  39. TEST_F(TestHistogram, ReplaceOldValues) {
  40. histogram_.Add(0);
  41. histogram_.Add(0);
  42. histogram_.Add(0);
  43. histogram_.Add(0);
  44. histogram_.Add(0);
  45. histogram_.Add(1);
  46. histogram_.Add(1);
  47. histogram_.Add(1);
  48. histogram_.Add(1);
  49. histogram_.Add(1);
  50. EXPECT_EQ(10ul, histogram_.NumValues());
  51. EXPECT_EQ(1ul, histogram_.InverseCdf(0.5f));
  52. EXPECT_EQ(2ul, histogram_.InverseCdf(0.5000001f));
  53. histogram_.Add(4);
  54. histogram_.Add(4);
  55. histogram_.Add(4);
  56. histogram_.Add(4);
  57. EXPECT_EQ(10ul, histogram_.NumValues());
  58. EXPECT_EQ(1ul, histogram_.InverseCdf(0.1f));
  59. EXPECT_EQ(2ul, histogram_.InverseCdf(0.5f));
  60. histogram_.Add(20);
  61. EXPECT_EQ(10ul, histogram_.NumValues());
  62. EXPECT_EQ(2ul, histogram_.InverseCdf(0.5f));
  63. EXPECT_EQ(5ul, histogram_.InverseCdf(0.5000001f));
  64. }
  65. } // namespace video_coding
  66. } // namespace webrtc