Index: webrtc/video/quality_threshold_unittest.cc |
diff --git a/webrtc/video/quality_threshold_unittest.cc b/webrtc/video/quality_threshold_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c89c041c12d759a535cdca774a8bc8a4b95d24d1 |
--- /dev/null |
+++ b/webrtc/video/quality_threshold_unittest.cc |
@@ -0,0 +1,72 @@ |
+/* |
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
+ * |
+ * Use of this source code is governed by a BSD-style license |
+ * that can be found in the LICENSE file in the root of the source |
+ * tree. An additional intellectual property rights grant can be found |
+ * in the file PATENTS. All contributing project authors may |
+ * be found in the AUTHORS file in the root of the source tree. |
+ */ |
+ |
+#include "webrtc/video/quality_threshold.h" |
+ |
+#include "webrtc/test/gtest.h" |
+ |
+namespace webrtc { |
+ |
+TEST(QualityThresholdTest, BackAndForth) { |
+ QualityThreshold thresh(0, 1, 0.75f, 10); |
sprang_webrtc
2016/11/24 16:25:21
Define constants for high / low / capacity and use
|
+ for (int i = 0; i < 8; ++i) { |
+ EXPECT_FALSE(thresh.IsHigh()); |
+ thresh.AddMeasurement(0); |
+ } |
+ ASSERT_TRUE(thresh.IsHigh()); |
+ for (int i = 0; i < 8; ++i) { |
+ EXPECT_FALSE(*thresh.IsHigh()); |
+ thresh.AddMeasurement(1); |
+ } |
+ EXPECT_TRUE(*thresh.IsHigh()); |
+ |
+ for (int i = 0; i < 8; ++i) { |
+ EXPECT_TRUE(*thresh.IsHigh()); |
+ thresh.AddMeasurement(0); |
+ } |
+ EXPECT_FALSE(*thresh.IsHigh()); |
+} |
+ |
+TEST(QualityThresholdTest, Variance) { |
+ const int max_measurements = 10; |
sprang_webrtc
2016/11/24 16:25:21
kMaxMeasurements or MAX_MEASUREMENTS
|
+ const double max_error = 0.01; |
+ int values[] = {51, 79, 80, 56, 19, 20, 48, 57, 48, 25, 2, 25, 38, 37, 25}; |
+ double variances[] = {476.9, 687.6, 552, 336.4, 278.767, 265.167}; |
sprang_webrtc
2016/11/24 16:25:21
please comment what these numbers are
|
+ QualityThreshold thresh(0, 1, 0.8f, max_measurements); |
+ |
+ for (int i = 0; i < max_measurements; ++i) { |
+ EXPECT_FALSE(thresh.CalculateVariance()); |
+ thresh.AddMeasurement(values[i]); |
+ } |
+ |
+ ASSERT_TRUE(thresh.CalculateVariance()); |
+ EXPECT_NEAR(variances[0], *thresh.CalculateVariance(), max_error); |
+ for (unsigned int i = 1; i < sizeof(variances) / sizeof(double); ++i) { |
+ thresh.AddMeasurement(values[i + max_measurements - 1]); |
+ EXPECT_NEAR(variances[i], *thresh.CalculateVariance(), max_error); |
+ } |
+ |
+ for (int i = 0; i < max_measurements; ++i) { |
+ thresh.AddMeasurement(42); |
+ } |
+ EXPECT_NEAR(0, *thresh.CalculateVariance(), max_error); |
+} |
+ |
+TEST(QualityThresholdTest, BetweenThresholds) { |
+ const int max_measurements = 10; |
+ QualityThreshold thresh(0, 2, 0.6f, max_measurements); |
+ for (int i = 0; i < 2 * max_measurements; ++i) { |
+ EXPECT_FALSE(thresh.IsHigh()); |
+ thresh.AddMeasurement(1); |
+ } |
+ EXPECT_FALSE(thresh.IsHigh()); |
+} |
+ |
+} // namespace webrtc |