|
1 | 1 | #include "hist_test.hxx"
|
2 | 2 |
|
| 3 | +#include <iterator> |
3 | 4 | #include <limits>
|
| 5 | +#include <stdexcept> |
4 | 6 | #include <vector>
|
5 | 7 |
|
6 | 8 | TEST(RVariableBinAxis, Constructor)
|
@@ -194,3 +196,82 @@ TEST(RVariableBinAxis, GetLinearizedIndex)
|
194 | 196 | EXPECT_FALSE(linIndex.fValid);
|
195 | 197 | }
|
196 | 198 | }
|
| 199 | + |
| 200 | +TEST(RVariableBinAxis, GetNormalRange) |
| 201 | +{ |
| 202 | + static constexpr std::size_t Bins = 20; |
| 203 | + std::vector<double> bins; |
| 204 | + for (std::size_t i = 0; i < Bins; i++) { |
| 205 | + bins.push_back(i); |
| 206 | + } |
| 207 | + bins.push_back(Bins); |
| 208 | + |
| 209 | + const RVariableBinAxis axis(bins); |
| 210 | + const auto index0 = RBinIndex(0); |
| 211 | + const auto indexBins = RBinIndex(Bins); |
| 212 | + |
| 213 | + { |
| 214 | + const auto normal = axis.GetNormalRange(); |
| 215 | + EXPECT_EQ(normal.GetBegin(), index0); |
| 216 | + EXPECT_EQ(normal.GetEnd(), indexBins); |
| 217 | + EXPECT_EQ(std::distance(normal.begin(), normal.end()), Bins); |
| 218 | + } |
| 219 | + |
| 220 | + { |
| 221 | + const auto normal = axis.GetNormalRange(index0, indexBins); |
| 222 | + EXPECT_EQ(normal.GetBegin(), index0); |
| 223 | + EXPECT_EQ(normal.GetEnd(), indexBins); |
| 224 | + EXPECT_EQ(std::distance(normal.begin(), normal.end()), Bins); |
| 225 | + } |
| 226 | + |
| 227 | + { |
| 228 | + const auto index1 = RBinIndex(1); |
| 229 | + const auto index5 = RBinIndex(5); |
| 230 | + const auto normal = axis.GetNormalRange(index1, index5); |
| 231 | + EXPECT_EQ(normal.GetBegin(), index1); |
| 232 | + EXPECT_EQ(normal.GetEnd(), index5); |
| 233 | + EXPECT_EQ(std::distance(normal.begin(), normal.end()), 4); |
| 234 | + } |
| 235 | + |
| 236 | + { |
| 237 | + const auto index1 = RBinIndex(1); |
| 238 | + const auto empty = axis.GetNormalRange(index1, index1); |
| 239 | + EXPECT_EQ(empty.GetBegin(), index1); |
| 240 | + EXPECT_EQ(empty.GetEnd(), index1); |
| 241 | + EXPECT_EQ(empty.begin(), empty.end()); |
| 242 | + EXPECT_EQ(std::distance(empty.begin(), empty.end()), 0); |
| 243 | + } |
| 244 | + |
| 245 | + const auto underflow = RBinIndex::Underflow(); |
| 246 | + const auto overflow = RBinIndex::Overflow(); |
| 247 | + EXPECT_THROW(axis.GetNormalRange(underflow, index0), std::invalid_argument); |
| 248 | + EXPECT_THROW(axis.GetNormalRange(indexBins, indexBins), std::invalid_argument); |
| 249 | + EXPECT_THROW(axis.GetNormalRange(index0, overflow), std::invalid_argument); |
| 250 | + EXPECT_THROW(axis.GetNormalRange(index0, indexBins + 1), std::invalid_argument); |
| 251 | +} |
| 252 | + |
| 253 | +TEST(RVariableBinAxis, GetFullRange) |
| 254 | +{ |
| 255 | + static constexpr std::size_t Bins = 20; |
| 256 | + std::vector<double> bins; |
| 257 | + for (std::size_t i = 0; i < Bins; i++) { |
| 258 | + bins.push_back(i); |
| 259 | + } |
| 260 | + bins.push_back(Bins); |
| 261 | + |
| 262 | + { |
| 263 | + const RVariableBinAxis axis(bins); |
| 264 | + const auto full = axis.GetFullRange(); |
| 265 | + EXPECT_EQ(full.GetBegin(), RBinIndex::Underflow()); |
| 266 | + EXPECT_EQ(full.GetEnd(), RBinIndex()); |
| 267 | + EXPECT_EQ(std::distance(full.begin(), full.end()), Bins + 2); |
| 268 | + } |
| 269 | + |
| 270 | + { |
| 271 | + const RVariableBinAxis axisNoFlowBins(bins, /*enableFlowBins=*/false); |
| 272 | + const auto full = axisNoFlowBins.GetFullRange(); |
| 273 | + EXPECT_EQ(full.GetBegin(), RBinIndex(0)); |
| 274 | + EXPECT_EQ(full.GetEnd(), RBinIndex(Bins)); |
| 275 | + EXPECT_EQ(std::distance(full.begin(), full.end()), Bins); |
| 276 | + } |
| 277 | +} |
0 commit comments