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

Side by Side Diff: webrtc/video/quality_threshold_unittest.cc

Issue 2474913002: Logging basic bad call detection (Closed)
Patch Set: Comments Created 4 years 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
« no previous file with comments | « webrtc/video/quality_threshold.cc ('k') | webrtc/video/receive_statistics_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "webrtc/video/quality_threshold.h"
12
13 #include "webrtc/test/gtest.h"
14
15 namespace webrtc {
16
17 TEST(QualityThresholdTest, BackAndForth) {
18 const int kLowThreshold = 0;
19 const int kHighThreshold = 1;
20 const float kFraction = 0.75f;
21 const int kMaxMeasurements = 10;
22
23 QualityThreshold thresh(kLowThreshold, kHighThreshold, kFraction,
24 kMaxMeasurements);
25
26 const int kNeededMeasurements =
27 static_cast<int>(kFraction * kMaxMeasurements + 1);
28 for (int i = 0; i < kNeededMeasurements; ++i) {
29 EXPECT_FALSE(thresh.IsHigh());
30 thresh.AddMeasurement(kLowThreshold);
31 }
32 ASSERT_TRUE(thresh.IsHigh());
33 for (int i = 0; i < kNeededMeasurements; ++i) {
34 EXPECT_FALSE(*thresh.IsHigh());
35 thresh.AddMeasurement(kHighThreshold);
36 }
37 EXPECT_TRUE(*thresh.IsHigh());
38
39 for (int i = 0; i < kNeededMeasurements; ++i) {
40 EXPECT_TRUE(*thresh.IsHigh());
41 thresh.AddMeasurement(kLowThreshold);
42 }
43 EXPECT_FALSE(*thresh.IsHigh());
44 }
45
46 TEST(QualityThresholdTest, Variance) {
47 const int kLowThreshold = 0;
48 const int kHighThreshold = 1;
49 const float kFraction = 0.8f;
50 const int kMaxMeasurements = 10;
51 const double kMaxError = 0.01;
52
53 // Previously randomly generated values...
54 int values[] = {51, 79, 80, 56, 19, 20, 48, 57, 48, 25, 2, 25, 38, 37, 25};
55 // ...with precomputed variances.
56 double variances[] = {476.9, 687.6, 552, 336.4, 278.767, 265.167};
57
58 QualityThreshold thresh(kLowThreshold, kHighThreshold, kFraction,
59 kMaxMeasurements);
60
61 for (int i = 0; i < kMaxMeasurements; ++i) {
62 EXPECT_FALSE(thresh.CalculateVariance());
63 thresh.AddMeasurement(values[i]);
64 }
65
66 ASSERT_TRUE(thresh.CalculateVariance());
67 EXPECT_NEAR(variances[0], *thresh.CalculateVariance(), kMaxError);
68 for (unsigned int i = 1; i < sizeof(variances) / sizeof(double); ++i) {
69 thresh.AddMeasurement(values[i + kMaxMeasurements - 1]);
70 EXPECT_NEAR(variances[i], *thresh.CalculateVariance(), kMaxError);
71 }
72
73 for (int i = 0; i < kMaxMeasurements; ++i) {
74 thresh.AddMeasurement(42);
75 }
76 EXPECT_NEAR(0, *thresh.CalculateVariance(), kMaxError);
77 }
78
79 TEST(QualityThresholdTest, BetweenThresholds) {
80 const int kLowThreshold = 0;
81 const int kHighThreshold = 2;
82 const float kFraction = 0.6f;
83 const int kMaxMeasurements = 10;
84
85 const int kBetweenThresholds = (kLowThreshold + kHighThreshold) / 2;
86
87 QualityThreshold thresh(kLowThreshold, kHighThreshold, kFraction,
88 kMaxMeasurements);
89
90 for (int i = 0; i < 2 * kMaxMeasurements; ++i) {
91 EXPECT_FALSE(thresh.IsHigh());
92 thresh.AddMeasurement(kBetweenThresholds);
93 }
94 EXPECT_FALSE(thresh.IsHigh());
95 }
96
97 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/quality_threshold.cc ('k') | webrtc/video/receive_statistics_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698