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

Side by Side Diff: webrtc/modules/congestion_controller/trendline_estimator_unittest.cc

Issue 2489323002: Add a new overuse estimator for the delay based BWE behind experiment. (Closed)
Patch Set: Rebase Created 4 years, 1 month 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
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/test/gtest.h"
12 #include "webrtc/base/random.h"
13 #include "webrtc/modules/congestion_controller/trendline_estimator.h"
14
15 namespace webrtc {
16
17 namespace {
18 constexpr size_t kWindowSize = 15;
19 constexpr double kSmoothing = 0.0;
20 constexpr double kGain = 1;
21 constexpr int64_t kAvgTimeBetweenPackets = 10;
22 } // namespace
23
24 TEST(TrendlineEstimator, PerfectLineSlopeOneHalf) {
25 TrendlineEstimator estimator(kWindowSize, kSmoothing, kGain);
26 Random rand(0x1234567);
27 double now_ms = rand.Rand<double>() * 10000;
28 for (size_t i = 1; i < 2 * kWindowSize; i++) {
29 double send_delta = rand.Rand<double>() * 2 * kAvgTimeBetweenPackets;
30 double recv_delta = 2 * send_delta;
31 now_ms += recv_delta;
32 estimator.Update(recv_delta, send_delta, now_ms);
33 if (i < kWindowSize)
34 EXPECT_NEAR(estimator.trendline_slope(), 0, 0.001);
35 else
36 EXPECT_NEAR(estimator.trendline_slope(), 0.5, 0.001);
37 }
38 }
39
40 TEST(TrendlineEstimator, PerfectLineSlopeMinusOne) {
41 TrendlineEstimator estimator(kWindowSize, kSmoothing, kGain);
42 Random rand(0x1234567);
43 double now_ms = rand.Rand<double>() * 10000;
44 for (size_t i = 1; i < 2 * kWindowSize; i++) {
45 double send_delta = rand.Rand<double>() * 2 * kAvgTimeBetweenPackets;
46 double recv_delta = 0.5 * send_delta;
47 now_ms += recv_delta;
48 estimator.Update(recv_delta, send_delta, now_ms);
49 if (i < kWindowSize)
50 EXPECT_NEAR(estimator.trendline_slope(), 0, 0.001);
51 else
52 EXPECT_NEAR(estimator.trendline_slope(), -1, 0.001);
53 }
54 }
55
56 TEST(TrendlineEstimator, PerfectLineSlopeZero) {
57 TrendlineEstimator estimator(kWindowSize, kSmoothing, kGain);
58 Random rand(0x1234567);
59 double now_ms = rand.Rand<double>() * 10000;
60 for (size_t i = 1; i < 2 * kWindowSize; i++) {
61 double send_delta = rand.Rand<double>() * 2 * kAvgTimeBetweenPackets;
62 double recv_delta = send_delta;
63 now_ms += recv_delta;
64 estimator.Update(recv_delta, send_delta, now_ms);
65 EXPECT_NEAR(estimator.trendline_slope(), 0, 0.001);
66 }
67 }
68
69 TEST(TrendlineEstimator, JitteryLineSlopeOneHalf) {
70 TrendlineEstimator estimator(kWindowSize, kSmoothing, kGain);
71 Random rand(0x1234567);
72 double now_ms = rand.Rand<double>() * 10000;
73 for (size_t i = 1; i < 2 * kWindowSize; i++) {
74 double send_delta = rand.Rand<double>() * 2 * kAvgTimeBetweenPackets;
75 double recv_delta = 2 * send_delta + rand.Gaussian(0, send_delta / 3);
76 now_ms += recv_delta;
77 estimator.Update(recv_delta, send_delta, now_ms);
78 if (i < kWindowSize)
79 EXPECT_NEAR(estimator.trendline_slope(), 0, 0.001);
80 else
81 EXPECT_NEAR(estimator.trendline_slope(), 0.5, 0.1);
82 }
83 }
84
85 TEST(TrendlineEstimator, JitteryLineSlopeMinusOne) {
86 TrendlineEstimator estimator(kWindowSize, kSmoothing, kGain);
87 Random rand(0x1234567);
88 double now_ms = rand.Rand<double>() * 10000;
89 for (size_t i = 1; i < 2 * kWindowSize; i++) {
90 double send_delta = rand.Rand<double>() * 2 * kAvgTimeBetweenPackets;
91 double recv_delta = 0.5 * send_delta + rand.Gaussian(0, send_delta / 25);
92 now_ms += recv_delta;
93 estimator.Update(recv_delta, send_delta, now_ms);
94 if (i < kWindowSize)
95 EXPECT_NEAR(estimator.trendline_slope(), 0, 0.001);
96 else
97 EXPECT_NEAR(estimator.trendline_slope(), -1, 0.1);
98 }
99 }
100
101 TEST(TrendlineEstimator, JitteryLineSlopeZero) {
102 TrendlineEstimator estimator(kWindowSize, kSmoothing, kGain);
103 Random rand(0x1234567);
104 double now_ms = rand.Rand<double>() * 10000;
105 for (size_t i = 1; i < 2 * kWindowSize; i++) {
106 double send_delta = rand.Rand<double>() * 2 * kAvgTimeBetweenPackets;
107 double recv_delta = send_delta + rand.Gaussian(0, send_delta / 8);
108 now_ms += recv_delta;
109 estimator.Update(recv_delta, send_delta, now_ms);
110 EXPECT_NEAR(estimator.trendline_slope(), 0, 0.1);
111 }
112 }
113
114 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698