11 #define BOOST_TEST_MODULE BinningSpecs
12 #include <cetlib/quiet_unit_test.hpp>
13 #include <boost/test/test_tools.hpp>
24 BOOST_TEST(BinningSpecs::NBinsFor(-5.0, 8.0, 2.0) == 7UL);
25 BOOST_TEST(BinningSpecs::NBinsFor(-5.0, 8.0, 0.1) == 130UL);
26 BOOST_TEST(BinningSpecs::NBinsFor(-5.0, -5.0, 0.1) == 0UL);
36 BinningSpecs
const binning { -5.0, 8.0, 2.0 };
38 BOOST_TEST(binning.lower() == -5.0, 0.001%
tolerance());
39 BOOST_TEST(binning.upper() == 9.0, 0.001%
tolerance());
40 BOOST_TEST(binning.range() == 14.0, 0.001%
tolerance());
41 BOOST_TEST(binning.nBins() == 7UL);
42 BOOST_TEST(binning.binWidth() == 2.0, 0.001%
tolerance());
44 BOOST_TEST(binning.binWith( -7.0) == -1);
45 BOOST_TEST(binning.binWith( -6.0) == -1);
46 BOOST_TEST(binning.binWith( -5.0) == 0);
47 BOOST_TEST(binning.binWith( -4.0) == 0);
48 BOOST_TEST(binning.binWith( -3.0) == 1);
49 BOOST_TEST(binning.binWith( -2.0) == 1);
50 BOOST_TEST(binning.binWith( -1.0) == 2);
51 BOOST_TEST(binning.binWith( 0.0) == 2);
52 BOOST_TEST(binning.binWith( +1.0) == 3);
53 BOOST_TEST(binning.binWith( +2.0) == 3);
54 BOOST_TEST(binning.binWith( +3.0) == 4);
55 BOOST_TEST(binning.binWith( +4.0) == 4);
56 BOOST_TEST(binning.binWith( +5.0) == 5);
57 BOOST_TEST(binning.binWith( +6.0) == 5);
58 BOOST_TEST(binning.binWith( +7.0) == 6);
59 BOOST_TEST(binning.binWith( +8.0) == 6);
60 BOOST_TEST(binning.binWith( +9.0) == 7);
61 BOOST_TEST(binning.binWith(+10.0) == 7);
62 BOOST_TEST(binning.binWith(+11.0) == 8);
63 BOOST_TEST(binning.binWith(+12.0) == 8);
64 BOOST_TEST(binning.binWith(+13.0) == 9);
66 BOOST_TEST(binning.binBorders(-1).first == -7.0, 0.001%
tolerance());
67 BOOST_TEST(binning.binBorders(-1).second == -5.0, 0.001%
tolerance());
68 BOOST_TEST(binning.binBorders( 0).first == -5.0, 0.001%
tolerance());
69 BOOST_TEST(binning.binBorders( 0).second == -3.0, 0.001%
tolerance());
70 BOOST_TEST(binning.binBorders( 1).first == -3.0, 0.001%
tolerance());
71 BOOST_TEST(binning.binBorders( 1).second == -1.0, 0.001%
tolerance());
72 BOOST_TEST(binning.binBorders( 2).first == -1.0, 0.001%
tolerance());
73 BOOST_TEST(binning.binBorders( 2).second == +1.0, 0.001%
tolerance());
74 BOOST_TEST(binning.binBorders( 3).first == +1.0, 0.001%
tolerance());
75 BOOST_TEST(binning.binBorders( 3).second == +3.0, 0.001%
tolerance());
76 BOOST_TEST(binning.binBorders( 4).first == +3.0, 0.001%
tolerance());
77 BOOST_TEST(binning.binBorders( 4).second == +5.0, 0.001%
tolerance());
78 BOOST_TEST(binning.binBorders( 5).first == +5.0, 0.001%
tolerance());
79 BOOST_TEST(binning.binBorders( 5).second == +7.0, 0.001%
tolerance());
80 BOOST_TEST(binning.binBorders( 6).first == +7.0, 0.001%
tolerance());
81 BOOST_TEST(binning.binBorders( 6).second == +9.0, 0.001%
tolerance());
82 BOOST_TEST(binning.binBorders( 7).first == +9.0, 0.001%
tolerance());
83 BOOST_TEST(binning.binBorders( 7).second == +11.0, 0.001%
tolerance());
84 BOOST_TEST(binning.binBorders( 8).first == +11.0, 0.001%
tolerance());
85 BOOST_TEST(binning.binBorders( 8).second == +13.0, 0.001%
tolerance());
86 BOOST_TEST(binning.binBorders( 9).first == +13.0, 0.001%
tolerance());
99 BOOST_TEST(binning.lower() == -6.0, 0.001%
tolerance());
100 BOOST_TEST(binning.upper() == 8.0, 0.001%
tolerance());
101 BOOST_TEST(binning.range() == 14.0, 0.001%
tolerance());
102 BOOST_TEST(binning.nBins() == 7UL);
103 BOOST_TEST(binning.binWidth() == 2.0, 0.001%
tolerance());
115 BOOST_TEST(binning.lower() == -6.0, 0.001%
tolerance());
116 BOOST_TEST(binning.upper() == 8.0, 0.001%
tolerance());
117 BOOST_TEST(binning.range() == 14.0, 0.001%
tolerance());
118 BOOST_TEST(binning.nBins() == 7UL);
119 BOOST_TEST(binning.binWidth() == 2.0, 0.001%
tolerance());
132 BOOST_TEST(binning.lower() == -1.0, 0.001%
tolerance());
133 BOOST_TEST(binning.upper() == 3.0, 0.001%
tolerance());
134 BOOST_TEST(binning.range() == 4.0, 0.001%
tolerance());
135 BOOST_TEST(binning.nBins() == 20UL);
136 BOOST_TEST(binning.binWidth() == 0.2, 0.001%
tolerance());
149 BOOST_TEST(binning.lower() == -1.2, 0.001%
tolerance());
150 BOOST_TEST(binning.upper() == 3.0, 0.001%
tolerance());
151 BOOST_TEST(binning.range() == 4.2, 0.001%
tolerance());
152 BOOST_TEST(binning.nBins() == 14UL);
153 BOOST_TEST(binning.binWidth() == 0.3, 0.001%
tolerance());
173 BOOST_TEST(binning.lower() == -1.0, 0.001%
tolerance());
174 BOOST_TEST(binning.upper() == 3.0, 0.001%
tolerance());
175 BOOST_TEST(binning.range() == 4.0, 0.001%
tolerance());
176 BOOST_TEST(binning.nBins() == 16UL);
177 BOOST_TEST(binning.binWidth() == 0.25, 0.001%
tolerance());
190 BOOST_TEST(binning.lower() == -1.0, 0.001%
tolerance());
191 BOOST_TEST(binning.upper() == 3.0, 0.001%
tolerance());
192 BOOST_TEST(binning.range() == 4.0, 0.001%
tolerance());
193 BOOST_TEST(binning.nBins() == 16UL);
194 BOOST_TEST(binning.binWidth() == 0.25, 0.001%
tolerance());
208 BOOST_TEST(binning.lower() == -6.0, 0.001%
tolerance());
209 BOOST_TEST(binning.upper() == 8.0, 0.001%
tolerance());
210 BOOST_TEST(binning.range() == 14.0, 0.001%
tolerance());
211 BOOST_TEST(binning.nBins() == 7UL);
212 BOOST_TEST(binning.binWidth() == 2.0, 0.001%
tolerance());
224 BOOST_TEST(binning.lower() == -6.0, 0.001%
tolerance());
225 BOOST_TEST(binning.upper() == 8.0, 0.001%
tolerance());
226 BOOST_TEST(binning.range() == 14.0, 0.001%
tolerance());
227 BOOST_TEST(binning.nBins() == 7UL);
228 BOOST_TEST(binning.binWidth() == 2.0, 0.001%
tolerance());
241 BOOST_TEST(binning.lower() == -1.2, 0.001%
tolerance());
242 BOOST_TEST(binning.upper() == 3.2, 0.001%
tolerance());
243 BOOST_TEST(binning.range() == 4.4, 0.001%
tolerance());
244 BOOST_TEST(binning.nBins() == 11UL);
245 BOOST_TEST(binning.binWidth() == 0.4, 0.001%
tolerance());
258 BOOST_TEST(binning.lower() == -1.5, 0.001%
tolerance());
259 BOOST_TEST(binning.upper() == 3.0, 0.001%
tolerance());
260 BOOST_TEST(binning.range() == 4.5, 0.001%
tolerance());
261 BOOST_TEST(binning.nBins() == 3UL);
262 BOOST_TEST(binning.binWidth() == 1.5, 0.001%
tolerance());
282 BOOST_TEST(binning.lower() == -12.0/9.0, 0.001%
tolerance());
283 BOOST_TEST(binning.upper() == 28.0/9.0, 0.001%
tolerance());
284 BOOST_TEST(binning.range() == 40.0/9.0, 0.001%
tolerance());
285 BOOST_TEST(binning.nBins() == 10UL);
286 BOOST_TEST(binning.binWidth() == 4.0/9.0, 0.001%
tolerance());
298 BOOST_TEST(binning.lower() == -2.0, 0.001%
tolerance());
299 BOOST_TEST(binning.upper() == 4.0, 0.001%
tolerance());
300 BOOST_TEST(binning.range() == 6.0, 0.001%
tolerance());
301 BOOST_TEST(binning.nBins() == 3UL);
302 BOOST_TEST(binning.binWidth() == 2.0, 0.001%
tolerance());
void makeBinningFromBinWidth_alignment_test()
Simple utility for human-friendly binning.
void makeBinningFromNBins_alignment_test()
void BinningSpecs_NBinsFor_test()
void makeBinningFromNBins_extension_test()
Data structure holding binning information.
void makeBinningFromNBins_hints_test()
void makeBinningFromBinWidth_stretch_test()
void makeBinningFromBinWidth_nohint_test()
void makeBinningFromBinWidth_extension_test()
void makeBinningFromNBins_stretch_test()
void makeBinningFromNBins_defhints_test()
BinningSpecs makeBinningFromNBins(double lower, double upper, unsigned long nBins, std::initializer_list< double > hints=DefaultBinningHints, double allowedStretch=DefaultAllowedBinningStretch)
Returns the "optimal" binning for the requested parameters.
void makeBinningFromBinWidth_defhints_test()
void makeBinningFromNBins_nohint_test()
void makeBinningFromBinWidth_hints_test()
BinningSpecs makeBinningFromBinWidth(double lower, double upper, double width, std::initializer_list< double > hints=DefaultBinningHints, double allowedStretch=DefaultAllowedBinningStretch)
Returns the "optimal" binning for the requested parameters.