Update V8 to version 4.7.56.
[chromium-blink-merge.git] / media / base / moving_average_unittest.cc
blobda8e51922d8912bb50398fe7e7c51cd0c5afe1ea
1 // Copyright 2015 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.
5 #include "base/time/time.h"
6 #include "media/base/moving_average.h"
7 #include "testing/gtest/include/gtest/gtest.h"
9 namespace media {
11 TEST(MovingAverageTest, Average) {
12 const int kSamples = 5;
13 MovingAverage moving_average(kSamples);
14 moving_average.AddSample(base::TimeDelta::FromSeconds(1));
15 EXPECT_EQ(base::TimeDelta::FromSeconds(1), moving_average.Average());
16 for (int i = 0; i < kSamples - 1; ++i)
17 moving_average.AddSample(base::TimeDelta::FromSeconds(1));
18 EXPECT_EQ(base::TimeDelta::FromSeconds(1), moving_average.Average());
20 for (int i = 0; i < kSamples; ++i) {
21 moving_average.AddSample(base::TimeDelta::FromMilliseconds(500));
22 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000 - (i + 1) * 100),
23 moving_average.Average());
27 TEST(MovingAverageTest, Reset) {
28 MovingAverage moving_average(2);
29 moving_average.AddSample(base::TimeDelta::FromSeconds(1));
30 EXPECT_EQ(base::TimeDelta::FromSeconds(1), moving_average.Average());
31 moving_average.Reset();
32 moving_average.AddSample(base::TimeDelta());
33 EXPECT_EQ(base::TimeDelta(), moving_average.Average());
36 } // namespace media