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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/base/running_average.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7
8 namespace remoting {
9
10 static const int64 kTestValues[] = { 10, 20, 30, 10, 25, 16, 15 };
11
12 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.
13 RunningAverage running_average(1);
14 for (size_t i = 0; i < arraysize(kTestValues); ++i) {
15 running_average.Record(kTestValues[i]);
16 EXPECT_EQ(static_cast<double>(kTestValues[i]), running_average.Average());
17 }
18 }
19
20 TEST(RunningAverageTest, TwoElementWindow) {
21 RunningAverage running_average(2);
22 for (size_t i = 0; i < arraysize(kTestValues); ++i) {
23 running_average.Record(kTestValues[i]);
24
25 double expected = kTestValues[i];
26 if (i > 0)
27 expected = (expected + kTestValues[i-1]) / 2;
28
29 EXPECT_EQ(expected, running_average.Average());
30 }
31 }
32
33 // Test that average is across all samples when there are fewer samples than
34 // the window size.
35 TEST(RunningAverageTest, TenElementWindow) {
36 RunningAverage running_average(10);
37 for (size_t i = 0; i < arraysize(kTestValues); ++i) {
38 running_average.Record(kTestValues[i]);
39
40 double expected = 0.0;
41 for (size_t j = 0; j <= i; ++j)
42 expected += kTestValues[j];
43 expected /= i+1;
alexeypa (please no reviews) 2013/03/18 19:39:39 nit: i + 1
Wez 2013/03/19 23:23:14 Done.
44
45 EXPECT_EQ(expected, running_average.Average());
46 }
47 }
48
49 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698