43 #include <gtest/gtest.h> 45 #include <ACG/Utils/Histogram.hh> 61 virtual void SetUp() {
65 virtual void TearDown() {
70 std::vector<double> v {1.0, 1.1, 2.0};
73 std::vector<size_t> correct_bins {2, 1};
74 EXPECT_EQ(hist.getBins(), correct_bins);
77 auto widths = hist.getBinWidths();
78 ASSERT_EQ(widths.size(), 2);
79 EXPECT_DOUBLE_EQ(widths[0], 0.5);
80 EXPECT_DOUBLE_EQ(widths[1], 0.5);
82 double width_sum = std::accumulate(widths.begin(), widths.end(), 0.0);
83 double total_width = hist.getTotalWidth();
84 EXPECT_DOUBLE_EQ(total_width, 1.0);
85 EXPECT_DOUBLE_EQ(total_width, width_sum);
87 auto boundaries = hist.getBinBoundaries();
88 ASSERT_EQ(boundaries.size(), 3);
89 EXPECT_DOUBLE_EQ(boundaries.at(0), 1);
90 EXPECT_DOUBLE_EQ(boundaries.at(1), 1.5);
91 EXPECT_DOUBLE_EQ(boundaries.at(2), 2);
94 #if 0 // not yet implemented 96 std::vector<int> v {0, 1, 1, 2, 5};
101 std::vector<size_t> correct_bins {2, 1, 1};
102 EXPECT_EQ(hist.getBins(), correct_bins);
105 auto widths = hist.getBinWidths();
106 ASSERT_EQ(widths.size(), 3);
107 EXPECT_EQ(widths[0], 2);
108 EXPECT_EQ(widths[1], 2);
109 EXPECT_EQ(widths[2], 2);
111 int width_sum = std::accumulate(widths.begin(), widths.end(), 0.0);
112 int total_width = hist.getTotalWidth();
113 EXPECT_EQ(total_width, 6);
114 EXPECT_EQ(total_width, width_sum);
116 std::vector<int> correct_boundaries {0, 2, 4, 5};
117 auto boundaries = hist.getBinBoundaries();
118 ASSERT_EQ(boundaries, correct_boundaries);