OLD | NEW |
---|---|
(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/rate_counter.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(RateCounterTest, OneSecondWindow) { | |
alexeypa (please no reviews)
2013/03/18 19:39:39
nit: Add the case when Record() is never called.
Wez
2013/03/19 23:23:14
Done.
| |
13 base::Time now = base::Time::Now(); | |
14 | |
15 RateCounter rate_counter(base::TimeDelta::FromSeconds(1)); | |
16 for (size_t i = 0; i < arraysize(kTestValues); ++i) { | |
17 now += base::TimeDelta::FromSeconds(1); | |
18 rate_counter.SetCurrentTimeForTest(now); | |
19 rate_counter.Record(kTestValues[i]); | |
20 EXPECT_EQ(static_cast<double>(kTestValues[i]), rate_counter.Rate()); | |
21 } | |
22 } | |
23 | |
24 TEST(RateCounterTest, TwoSecondWindow) { | |
25 base::Time now = base::Time::Now(); | |
26 | |
27 RateCounter rate_counter(base::TimeDelta::FromSeconds(2)); | |
28 for (size_t i = 0; i < arraysize(kTestValues); ++i) { | |
29 now += base::TimeDelta::FromSeconds(1); | |
30 rate_counter.SetCurrentTimeForTest(now); | |
31 rate_counter.Record(kTestValues[i]); | |
32 if (i > 0) { | |
33 double expected = kTestValues[i] + kTestValues[i-1]; | |
34 expected /= 2; | |
35 EXPECT_EQ(expected, rate_counter.Rate()); | |
alexeypa (please no reviews)
2013/03/18 19:39:39
nit: Verify the result of Rate() when |i| is 0 as
Wez
2013/03/19 23:23:14
Done.
| |
36 } | |
37 } | |
38 } | |
39 | |
40 TEST(RateCounterTest, LongWindow) { | |
41 base::Time now = base::Time::Now(); | |
42 | |
43 const size_t kWindowSeconds = arraysize(kTestValues) + 1; | |
alexeypa (please no reviews)
2013/03/18 19:39:39
I guess it is better to have kWindowsSeconds = arr
Wez
2013/03/19 23:23:14
I've reworded the comments and updated this test t
| |
44 | |
45 RateCounter rate_counter(base::TimeDelta::FromSeconds(kWindowSeconds)); | |
46 double expected = 0.0; | |
47 for (size_t i = 0; i < arraysize(kTestValues); ++i) { | |
48 now += base::TimeDelta::FromSeconds(1); | |
49 rate_counter.SetCurrentTimeForTest(now); | |
50 rate_counter.Record(kTestValues[i]); | |
51 expected += kTestValues[i]; | |
52 } | |
53 expected /= kWindowSeconds; | |
54 | |
55 EXPECT_EQ(expected, rate_counter.Rate()); | |
56 } | |
57 | |
58 } // namespace remoting | |
OLD | NEW |