Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / cc / base / rolling_time_delta_history_unittest.cc
blob5458240bc7be5f2483c2c141be3883bbc45dfe23
1 // Copyright 2014 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 "cc/base/rolling_time_delta_history.h"
6 #include "testing/gtest/include/gtest/gtest.h"
8 namespace cc {
9 namespace {
11 TEST(RollingTimeDeltaHistoryTest, EmptyHistory) {
12 RollingTimeDeltaHistory empty_history(0);
14 EXPECT_EQ(base::TimeDelta(), empty_history.Percentile(0.0));
15 EXPECT_EQ(base::TimeDelta(), empty_history.Percentile(50.0));
16 EXPECT_EQ(base::TimeDelta(), empty_history.Percentile(100.0));
18 empty_history.InsertSample(base::TimeDelta::FromMilliseconds(10));
19 empty_history.InsertSample(base::TimeDelta::FromMilliseconds(15));
20 empty_history.InsertSample(base::TimeDelta::FromMilliseconds(20));
22 EXPECT_EQ(base::TimeDelta(), empty_history.Percentile(0.0));
23 EXPECT_EQ(base::TimeDelta(), empty_history.Percentile(50.0));
24 EXPECT_EQ(base::TimeDelta(), empty_history.Percentile(100.0));
26 empty_history.Clear();
27 EXPECT_EQ(base::TimeDelta(), empty_history.Percentile(0.0));
28 EXPECT_EQ(base::TimeDelta(), empty_history.Percentile(50.0));
29 EXPECT_EQ(base::TimeDelta(), empty_history.Percentile(100.0));
32 TEST(RollingTimeDeltaHistoryTest, SizeOneHistory) {
33 RollingTimeDeltaHistory size_one_history(1);
34 base::TimeDelta sample1 = base::TimeDelta::FromMilliseconds(10);
35 base::TimeDelta sample2 = base::TimeDelta::FromMilliseconds(20);
37 EXPECT_EQ(base::TimeDelta(), size_one_history.Percentile(0.0));
38 EXPECT_EQ(base::TimeDelta(), size_one_history.Percentile(50.0));
39 EXPECT_EQ(base::TimeDelta(), size_one_history.Percentile(100.0));
41 size_one_history.InsertSample(sample1);
42 EXPECT_EQ(sample1, size_one_history.Percentile(0.0));
43 EXPECT_EQ(sample1, size_one_history.Percentile(50.0));
44 EXPECT_EQ(sample1, size_one_history.Percentile(100.0));
46 size_one_history.InsertSample(sample2);
47 EXPECT_EQ(sample2, size_one_history.Percentile(0.0));
48 EXPECT_EQ(sample2, size_one_history.Percentile(50.0));
49 EXPECT_EQ(sample2, size_one_history.Percentile(100.0));
51 size_one_history.Clear();
52 EXPECT_EQ(base::TimeDelta(), size_one_history.Percentile(0.0));
53 EXPECT_EQ(base::TimeDelta(), size_one_history.Percentile(50.0));
54 EXPECT_EQ(base::TimeDelta(), size_one_history.Percentile(100.0));
57 TEST(RollingTimeDeltaHistoryTest, LargeHistory) {
58 RollingTimeDeltaHistory large_history(100);
59 base::TimeDelta sample1 = base::TimeDelta::FromMilliseconds(150);
60 base::TimeDelta sample2 = base::TimeDelta::FromMilliseconds(250);
61 base::TimeDelta sample3 = base::TimeDelta::FromMilliseconds(200);
63 large_history.InsertSample(sample1);
64 large_history.InsertSample(sample2);
66 EXPECT_EQ(sample1, large_history.Percentile(0.0));
67 EXPECT_EQ(sample1, large_history.Percentile(25.0));
68 EXPECT_EQ(sample2, large_history.Percentile(75.0));
69 EXPECT_EQ(sample2, large_history.Percentile(100.0));
71 large_history.InsertSample(sample3);
72 EXPECT_EQ(sample1, large_history.Percentile(0.0));
73 EXPECT_EQ(sample1, large_history.Percentile(25.0));
74 EXPECT_EQ(sample3, large_history.Percentile(50.0));
75 EXPECT_EQ(sample2, large_history.Percentile(100.0));
77 // Fill the history.
78 for (int i = 1; i <= 97; i++)
79 large_history.InsertSample(base::TimeDelta::FromMilliseconds(i));
81 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1),
82 large_history.Percentile(0.0));
83 for (int i = 1; i <= 97; i++) {
84 EXPECT_EQ(base::TimeDelta::FromMilliseconds(i),
85 large_history.Percentile(i - 0.5));
87 EXPECT_EQ(sample1, large_history.Percentile(97.5));
88 EXPECT_EQ(sample3, large_history.Percentile(98.5));
89 EXPECT_EQ(sample2, large_history.Percentile(99.5));
91 // Continue inserting samples, causing the oldest samples to be discarded.
92 base::TimeDelta sample4 = base::TimeDelta::FromMilliseconds(100);
93 base::TimeDelta sample5 = base::TimeDelta::FromMilliseconds(102);
94 base::TimeDelta sample6 = base::TimeDelta::FromMilliseconds(104);
95 large_history.InsertSample(sample4);
96 large_history.InsertSample(sample5);
97 large_history.InsertSample(sample6);
98 EXPECT_EQ(sample4, large_history.Percentile(97.5));
99 EXPECT_EQ(sample5, large_history.Percentile(98.5));
100 EXPECT_EQ(sample6, large_history.Percentile(99.5));
102 large_history.Clear();
103 EXPECT_EQ(base::TimeDelta(), large_history.Percentile(0.0));
104 EXPECT_EQ(base::TimeDelta(), large_history.Percentile(50.0));
105 EXPECT_EQ(base::TimeDelta(), large_history.Percentile(100.0));
108 } // namespace
109 } // namespace cc