#include "tracing/tracing/value/histogram.h"
#include <cmath>
#include <sstream>
#include "testing/gtest/include/gtest/gtest.h"
#include "tracing/tracing/proto/histogram.pb.h"
namespace catapult {
namespace proto = tracing::tracing::proto;
proto::UnitAndDirection UnitWhatever() { … }
TEST(…) {
HistogramBuilder builder("my name", UnitWhatever());
auto histogram = builder.toProto();
EXPECT_EQ(…);
}
TEST(…) {
proto::UnitAndDirection unit;
unit.set_unit(proto::TS_MS);
unit.set_improvement_direction(proto::BIGGER_IS_BETTER);
HistogramBuilder builder("", unit);
auto histogram = builder.toProto();
EXPECT_EQ(…);
EXPECT_EQ(…);
}
TEST(…) {
HistogramBuilder builder("", UnitWhatever());
builder.set_description("desc!");
auto histogram = builder.toProto();
EXPECT_EQ(…);
}
TEST(…) {
HistogramBuilder builder("", UnitWhatever());
proto::Diagnostic diag1;
proto::GenericSet* set1 = diag1.mutable_generic_set();
set1->add_values("1234");
set1->add_values("\"a JSON encoded string\"");
builder.AddDiagnostic("diag1", diag1);
proto::Diagnostic diag2;
proto::GenericSet* set2 = diag2.mutable_generic_set();
set2->add_values("{}");
builder.AddDiagnostic("diag2", diag2);
auto histogram = builder.toProto();
auto map = histogram->diagnostics().diagnostic_map();
EXPECT_EQ(…);
EXPECT_TRUE(…);
const proto::GenericSet& actual_set1 = map["diag1"].generic_set();
EXPECT_EQ(…);
EXPECT_EQ(…);
EXPECT_EQ(…);
EXPECT_TRUE(…);
EXPECT_EQ(…);
EXPECT_EQ(…);
}
TEST(…) {
HistogramBuilder builder("", UnitWhatever());
builder.AddSample(1.0);
builder.AddSample(2.0);
builder.AddSample(3.0);
builder.AddSample(4.0);
auto histogram = builder.toProto();
EXPECT_EQ(…);
EXPECT_EQ(…);
EXPECT_EQ(…);
EXPECT_EQ(…);
EXPECT_EQ(…);
}
TEST(…) {
HistogramBuilder builder("", UnitWhatever());
for (int i = 0; i < 100; ++i) {
builder.AddSample(i);
}
auto histogram = builder.toProto();
EXPECT_EQ(…)
<< "Did not expect num samples to grow beyond 10, which is the default "
<< "max number of samples";
ASSERT_LE(…);
ASSERT_GE(…);
ASSERT_LE(…);
ASSERT_GE(…);
ASSERT_LE(…);
ASSERT_GE(…);
}
TEST(…) {
HistogramBuilder builder("", UnitWhatever());
builder.AddSample(10.0);
builder.AddSample(20.0);
builder.AddSample(30.0);
builder.AddSample(40.0);
auto histogram = builder.toProto();
EXPECT_EQ(…);
EXPECT_EQ(…);
EXPECT_FLOAT_EQ(…);
EXPECT_EQ(…);
EXPECT_EQ(…);
EXPECT_EQ(…);
EXPECT_FLOAT_EQ(…);
}
TEST(…) {
HistogramBuilder builder("", UnitWhatever());
builder.AddSample(20.0);
builder.AddSample(-1.0);
auto histogram = builder.toProto();
ASSERT_EQ(…);
}
TEST(…) {
HistogramBuilder builder("", UnitWhatever());
proto::SummaryOptions options;
options.set_count(false);
options.set_avg(true);
builder.SetSummaryOptions(options);
auto histogram = builder.toProto();
ASSERT_EQ(…);
ASSERT_EQ(…);
ASSERT_EQ(…);
}
TEST(…) {
EXPECT_EQ(…);
EXPECT_EQ(…);
EXPECT_EQ(…);
EXPECT_EQ(…);
EXPECT_EQ(…);
EXPECT_EQ(…);
}
TEST(…) {
EXPECT_EQ(…);
}
TEST(…) {
EXPECT_EQ(…);
EXPECT_EQ(…);
}
}