forked from facebook/rocksdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
histogram_test.cc
62 lines (51 loc) · 1.62 KB
/
histogram_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
//
#include "util/histogram.h"
#include "util/testharness.h"
namespace rocksdb {
class HistogramTest : public testing::Test {};
TEST_F(HistogramTest, BasicOperation) {
HistogramImpl histogram;
for (uint64_t i = 1; i <= 100; i++) {
histogram.Add(i);
}
{
double median = histogram.Median();
// ASSERT_LE(median, 50);
ASSERT_GT(median, 0);
}
{
double percentile100 = histogram.Percentile(100.0);
ASSERT_LE(percentile100, 100.0);
ASSERT_GT(percentile100, 0.0);
double percentile99 = histogram.Percentile(99.0);
double percentile85 = histogram.Percentile(85.0);
ASSERT_LE(percentile99, 99.0);
ASSERT_TRUE(percentile99 >= percentile85);
}
ASSERT_EQ(histogram.Average(), 50.5); // avg is acurately calculated.
}
TEST_F(HistogramTest, EmptyHistogram) {
HistogramImpl histogram;
ASSERT_EQ(histogram.Median(), 0.0);
ASSERT_EQ(histogram.Percentile(85.0), 0.0);
ASSERT_EQ(histogram.Average(), 0.0);
}
TEST_F(HistogramTest, ClearHistogram) {
HistogramImpl histogram;
for (uint64_t i = 1; i <= 100; i++) {
histogram.Add(i);
}
histogram.Clear();
ASSERT_EQ(histogram.Median(), 0);
ASSERT_EQ(histogram.Percentile(85.0), 0);
ASSERT_EQ(histogram.Average(), 0);
}
} // namespace rocksdb
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}