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

Unified Diff: remoting/base/running_average_unittest.cc

Issue 12803008: Add unit tests for sub-components of CaptureScheduler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months 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 side-by-side diff with in-line comments
Download patch
Index: remoting/base/running_average_unittest.cc
diff --git a/remoting/base/running_average_unittest.cc b/remoting/base/running_average_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4a05dafaec9b92a6e6f79c24720d66de0a319d07
--- /dev/null
+++ b/remoting/base/running_average_unittest.cc
@@ -0,0 +1,49 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/base/running_average.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace remoting {
+
+static const int64 kTestValues[] = { 10, 20, 30, 10, 25, 16, 15 };
+
+TEST(RunningAverageTest, OneElementWindow) {
alexeypa (please no reviews) 2013/03/18 19:39:39 nit: Add the case when Record() wasn't called at a
Wez 2013/03/19 23:23:14 Done.
+ RunningAverage running_average(1);
+ for (size_t i = 0; i < arraysize(kTestValues); ++i) {
+ running_average.Record(kTestValues[i]);
+ EXPECT_EQ(static_cast<double>(kTestValues[i]), running_average.Average());
+ }
+}
+
+TEST(RunningAverageTest, TwoElementWindow) {
+ RunningAverage running_average(2);
+ for (size_t i = 0; i < arraysize(kTestValues); ++i) {
+ running_average.Record(kTestValues[i]);
+
+ double expected = kTestValues[i];
+ if (i > 0)
+ expected = (expected + kTestValues[i-1]) / 2;
+
+ EXPECT_EQ(expected, running_average.Average());
+ }
+}
+
+// Test that average is across all samples when there are fewer samples than
+// the window size.
+TEST(RunningAverageTest, TenElementWindow) {
+ RunningAverage running_average(10);
+ for (size_t i = 0; i < arraysize(kTestValues); ++i) {
+ running_average.Record(kTestValues[i]);
+
+ double expected = 0.0;
+ for (size_t j = 0; j <= i; ++j)
+ expected += kTestValues[j];
+ expected /= i+1;
alexeypa (please no reviews) 2013/03/18 19:39:39 nit: i + 1
Wez 2013/03/19 23:23:14 Done.
+
+ EXPECT_EQ(expected, running_average.Average());
+ }
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698