YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/rocksdb/util/histogram_test.cc
Line
Count
Source
1
//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2
//  This source code is licensed under the BSD-style license found in the
3
//  LICENSE file in the root directory of this source tree. An additional grant
4
//  of patent rights can be found in the PATENTS file in the same directory.
5
//
6
// The following only applies to changes made to this file as part of YugaByte development.
7
//
8
// Portions Copyright (c) YugaByte, Inc.
9
//
10
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
11
// in compliance with the License.  You may obtain a copy of the License at
12
//
13
// http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software distributed under the License
16
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
17
// or implied.  See the License for the specific language governing permissions and limitations
18
// under the License.
19
//
20
#include "yb/rocksdb/util/histogram.h"
21
22
#include <string>
23
#include <gtest/gtest.h>
24
25
#include "yb/rocksdb/util/testutil.h"
26
27
namespace rocksdb {
28
29
class HistogramTest : public RocksDBTest {};
30
31
1
TEST_F(HistogramTest, BasicOperation) {
32
1
  HistogramImpl histogram;
33
101
  for (uint64_t i = 1; i <= 100; i++) {
34
100
    histogram.Add(i);
35
100
  }
36
37
1
  {
38
1
    double median = histogram.Median();
39
    // ASSERT_LE(median, 50);
40
1
    ASSERT_GT(median, 0);
41
1
  }
42
43
1
  {
44
1
    double percentile100 = histogram.Percentile(100.0);
45
1
    ASSERT_LE(percentile100, 100.0);
46
1
    ASSERT_GT(percentile100, 0.0);
47
1
    double percentile99 = histogram.Percentile(99.0);
48
1
    double percentile85 = histogram.Percentile(85.0);
49
1
    ASSERT_LE(percentile99, 99.0);
50
1
    ASSERT_TRUE(percentile99 >= percentile85);
51
1
  }
52
53
1
  ASSERT_EQ(histogram.Average(), 50.5); // avg is acurately calculated.
54
1
}
55
56
1
TEST_F(HistogramTest, EmptyHistogram) {
57
1
  HistogramImpl histogram;
58
1
  ASSERT_EQ(histogram.Median(), 0.0);
59
1
  ASSERT_EQ(histogram.Percentile(85.0), 0.0);
60
1
  ASSERT_EQ(histogram.Average(), 0.0);
61
1
}
62
63
1
TEST_F(HistogramTest, ClearHistogram) {
64
1
  HistogramImpl histogram;
65
101
  for (uint64_t i = 1; i <= 100; i++) {
66
100
    histogram.Add(i);
67
100
  }
68
1
  histogram.Clear();
69
1
  ASSERT_EQ(histogram.Median(), 0);
70
1
  ASSERT_EQ(histogram.Percentile(85.0), 0);
71
1
  ASSERT_EQ(histogram.Average(), 0);
72
1
}
73
74
1
TEST_F(HistogramTest, BigValues) {
75
1
  double values[] = {0, 0, 1e19, 1e19};
76
1
  HistogramImpl histogram;
77
4
  for (auto v : values) {
78
4
    histogram.Add(v);
79
4
  }
80
1
  ASSERT_EQ(histogram.Average(), 5e18);
81
1
  ASSERT_GT(histogram.Median(), 0);
82
1
  ASSERT_LT(histogram.Median(), 1e19);
83
1
  ASSERT_EQ(histogram.StandardDeviation(), 5e18);
84
1
}
85
86
}  // namespace rocksdb
87
88
13.2k
int main(int argc, char** argv) {
89
13.2k
  ::testing::InitGoogleTest(&argc, argv);
90
13.2k
  return RUN_ALL_TESTS();
91
13.2k
}