| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
| 8 #include "base/macros.h" |
| 5 #include "remoting/base/running_average.h" | 9 #include "remoting/base/running_average.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 11 |
| 8 namespace remoting { | 12 namespace remoting { |
| 9 | 13 |
| 10 static const int64 kTestValues[] = { 10, 20, 30, 10, 25, 16, 15 }; | 14 static const int64_t kTestValues[] = { 10, 20, 30, 10, 25, 16, 15 }; |
| 11 | 15 |
| 12 // Average across a single element, i.e. just return the most recent. | 16 // Average across a single element, i.e. just return the most recent. |
| 13 TEST(RunningAverageTest, OneElementWindow) { | 17 TEST(RunningAverageTest, OneElementWindow) { |
| 14 RunningAverage running_average(1); | 18 RunningAverage running_average(1); |
| 15 EXPECT_EQ(0, running_average.Average()); | 19 EXPECT_EQ(0, running_average.Average()); |
| 16 | 20 |
| 17 for (size_t i = 0; i < arraysize(kTestValues); ++i) { | 21 for (size_t i = 0; i < arraysize(kTestValues); ++i) { |
| 18 running_average.Record(kTestValues[i]); | 22 running_average.Record(kTestValues[i]); |
| 19 EXPECT_EQ(static_cast<double>(kTestValues[i]), running_average.Average()); | 23 EXPECT_EQ(static_cast<double>(kTestValues[i]), running_average.Average()); |
| 20 } | 24 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 47 double expected = 0.0; | 51 double expected = 0.0; |
| 48 for (size_t j = 0; j <= i; ++j) | 52 for (size_t j = 0; j <= i; ++j) |
| 49 expected += kTestValues[j]; | 53 expected += kTestValues[j]; |
| 50 expected /= i + 1; | 54 expected /= i + 1; |
| 51 | 55 |
| 52 EXPECT_EQ(expected, running_average.Average()); | 56 EXPECT_EQ(expected, running_average.Average()); |
| 53 } | 57 } |
| 54 } | 58 } |
| 55 | 59 |
| 56 } // namespace remoting | 60 } // namespace remoting |
| OLD | NEW |