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

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: Pick nits. 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
« no previous file with comments | « remoting/base/running_average.cc ('k') | remoting/host/capture_scheduler.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 // 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 // Average across a single element, i.e. just return the most recent.
13 TEST(RunningAverageTest, OneElementWindow) {
14 RunningAverage running_average(1);
15 EXPECT_EQ(0, running_average.Average());
16
17 for (size_t i = 0; i < arraysize(kTestValues); ++i) {
18 running_average.Record(kTestValues[i]);
19 EXPECT_EQ(static_cast<double>(kTestValues[i]), running_average.Average());
20 }
21 }
22
23 // Average the two most recent elements.
24 TEST(RunningAverageTest, TwoElementWindow) {
25 RunningAverage running_average(2);
26 EXPECT_EQ(0, running_average.Average());
27
28 for (size_t i = 0; i < arraysize(kTestValues); ++i) {
29 running_average.Record(kTestValues[i]);
30
31 double expected = kTestValues[i];
32 if (i > 0)
33 expected = (expected + kTestValues[i-1]) / 2;
34
35 EXPECT_EQ(expected, running_average.Average());
36 }
37 }
38
39 // Average across all the elements if the window size exceeds the element count.
40 TEST(RunningAverageTest, LongWindow) {
41 RunningAverage running_average(arraysize(kTestValues) + 1);
42 EXPECT_EQ(0, running_average.Average());
43
44 for (size_t i = 0; i < arraysize(kTestValues); ++i) {
45 running_average.Record(kTestValues[i]);
46
47 double expected = 0.0;
48 for (size_t j = 0; j <= i; ++j)
49 expected += kTestValues[j];
50 expected /= i + 1;
51
52 EXPECT_EQ(expected, running_average.Average());
53 }
54 }
55
56 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/base/running_average.cc ('k') | remoting/host/capture_scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698