|
| 1 | +#include "hist_test.hxx" |
| 2 | + |
| 3 | +TEST(RHistEngine, FillAtomic) |
| 4 | +{ |
| 5 | + static constexpr std::size_t Bins = 20; |
| 6 | + const RRegularAxis axis(Bins, {0, Bins}); |
| 7 | + RHistEngine<int> engine({axis}); |
| 8 | + |
| 9 | + engine.FillAtomic(-100); |
| 10 | + for (std::size_t i = 0; i < Bins; i++) { |
| 11 | + engine.FillAtomic(i); |
| 12 | + } |
| 13 | + engine.FillAtomic(100); |
| 14 | + |
| 15 | + EXPECT_EQ(engine.GetBinContent(RBinIndex::Underflow()), 1); |
| 16 | + for (auto index : axis.GetNormalRange()) { |
| 17 | + EXPECT_EQ(engine.GetBinContent(index), 1); |
| 18 | + } |
| 19 | + EXPECT_EQ(engine.GetBinContent(RBinIndex::Overflow()), 1); |
| 20 | + |
| 21 | + // Instantiate further bin content types to make sure they work. |
| 22 | + RHistEngine<long> engineL({axis}); |
| 23 | + engineL.FillAtomic(1); |
| 24 | + |
| 25 | + RHistEngine<long long> engineLL({axis}); |
| 26 | + engineLL.FillAtomic(1); |
| 27 | + |
| 28 | + RHistEngine<float> engineF({axis}); |
| 29 | + engineF.FillAtomic(1); |
| 30 | + |
| 31 | + RHistEngine<double> engineD({axis}); |
| 32 | + engineD.FillAtomic(1); |
| 33 | +} |
| 34 | + |
| 35 | +TEST(RHistEngine, FillAtomicTuple) |
| 36 | +{ |
| 37 | + static constexpr std::size_t Bins = 20; |
| 38 | + const RRegularAxis axis(Bins, {0, Bins}); |
| 39 | + RHistEngine<int> engine({axis}); |
| 40 | + |
| 41 | + engine.FillAtomic(std::make_tuple(-100)); |
| 42 | + for (std::size_t i = 0; i < Bins; i++) { |
| 43 | + engine.FillAtomic(std::make_tuple(i)); |
| 44 | + } |
| 45 | + engine.FillAtomic(std::make_tuple(100)); |
| 46 | + |
| 47 | + EXPECT_EQ(engine.GetBinContent(RBinIndex::Underflow()), 1); |
| 48 | + for (auto index : axis.GetNormalRange()) { |
| 49 | + EXPECT_EQ(engine.GetBinContent(index), 1); |
| 50 | + } |
| 51 | + EXPECT_EQ(engine.GetBinContent(RBinIndex::Overflow()), 1); |
| 52 | +} |
| 53 | + |
| 54 | +TEST(RHistEngine, FillInvalidNumberOfArguments) |
| 55 | +{ |
| 56 | + static constexpr std::size_t Bins = 20; |
| 57 | + const RRegularAxis axis(Bins, {0, Bins}); |
| 58 | + RHistEngine<int> engine1({axis}); |
| 59 | + ASSERT_EQ(engine1.GetNDimensions(), 1); |
| 60 | + RHistEngine<int> engine2({axis, axis}); |
| 61 | + ASSERT_EQ(engine2.GetNDimensions(), 2); |
| 62 | + |
| 63 | + EXPECT_NO_THROW(engine1.FillAtomic(1)); |
| 64 | + EXPECT_THROW(engine1.FillAtomic(1, 2), std::invalid_argument); |
| 65 | + |
| 66 | + EXPECT_THROW(engine2.FillAtomic(1), std::invalid_argument); |
| 67 | + EXPECT_NO_THROW(engine2.FillAtomic(1, 2)); |
| 68 | + EXPECT_THROW(engine2.FillAtomic(1, 2, 3), std::invalid_argument); |
| 69 | +} |
| 70 | + |
| 71 | +TEST(RHistEngine, FillAtomicWeight) |
| 72 | +{ |
| 73 | + static constexpr std::size_t Bins = 20; |
| 74 | + const RRegularAxis axis(Bins, {0, Bins}); |
| 75 | + RHistEngine<float> engine({axis}); |
| 76 | + |
| 77 | + engine.FillAtomic(-100, RWeight(0.25)); |
| 78 | + for (std::size_t i = 0; i < Bins; i++) { |
| 79 | + engine.FillAtomic(i, RWeight(0.1 + i * 0.03)); |
| 80 | + } |
| 81 | + engine.FillAtomic(100, RWeight(0.75)); |
| 82 | + |
| 83 | + EXPECT_FLOAT_EQ(engine.GetBinContent(RBinIndex::Underflow()), 0.25); |
| 84 | + for (auto index : axis.GetNormalRange()) { |
| 85 | + EXPECT_FLOAT_EQ(engine.GetBinContent(index), 0.1 + index.GetIndex() * 0.03); |
| 86 | + } |
| 87 | + EXPECT_EQ(engine.GetBinContent(RBinIndex::Overflow()), 0.75); |
| 88 | + |
| 89 | + // Instantiate further bin content types to make sure they work. |
| 90 | + RHistEngine<double> engineD({axis}); |
| 91 | + engineD.FillAtomic(1, RWeight(0.8)); |
| 92 | +} |
| 93 | + |
| 94 | +TEST(RHistEngine, FillAtomicTupleWeight) |
| 95 | +{ |
| 96 | + static constexpr std::size_t Bins = 20; |
| 97 | + const RRegularAxis axis(Bins, {0, Bins}); |
| 98 | + RHistEngine<float> engine({axis}); |
| 99 | + |
| 100 | + engine.FillAtomic(std::make_tuple(-100), RWeight(0.25)); |
| 101 | + for (std::size_t i = 0; i < Bins; i++) { |
| 102 | + engine.FillAtomic(std::make_tuple(i), RWeight(0.1 + i * 0.03)); |
| 103 | + } |
| 104 | + engine.FillAtomic(std::make_tuple(100), RWeight(0.75)); |
| 105 | + |
| 106 | + EXPECT_FLOAT_EQ(engine.GetBinContent(RBinIndex::Underflow()), 0.25); |
| 107 | + for (auto index : axis.GetNormalRange()) { |
| 108 | + EXPECT_FLOAT_EQ(engine.GetBinContent(index), 0.1 + index.GetIndex() * 0.03); |
| 109 | + } |
| 110 | + EXPECT_EQ(engine.GetBinContent(RBinIndex::Overflow()), 0.75); |
| 111 | +} |
| 112 | + |
| 113 | +TEST(RHistEngine, FillWeightInvalidNumberOfArguments) |
| 114 | +{ |
| 115 | + static constexpr std::size_t Bins = 20; |
| 116 | + const RRegularAxis axis(Bins, {0, Bins}); |
| 117 | + RHistEngine<float> engine1({axis}); |
| 118 | + ASSERT_EQ(engine1.GetNDimensions(), 1); |
| 119 | + RHistEngine<float> engine2({axis, axis}); |
| 120 | + ASSERT_EQ(engine2.GetNDimensions(), 2); |
| 121 | + |
| 122 | + EXPECT_NO_THROW(engine1.FillAtomic(1, RWeight(1))); |
| 123 | + EXPECT_THROW(engine1.FillAtomic(1, 2, RWeight(1)), std::invalid_argument); |
| 124 | + |
| 125 | + EXPECT_THROW(engine2.FillAtomic(1, RWeight(1)), std::invalid_argument); |
| 126 | + EXPECT_NO_THROW(engine2.FillAtomic(1, 2, RWeight(1))); |
| 127 | + EXPECT_THROW(engine2.FillAtomic(1, 2, 3, RWeight(1)), std::invalid_argument); |
| 128 | +} |
| 129 | + |
| 130 | +TEST(RHistEngine, FillTupleWeightInvalidNumberOfArguments) |
| 131 | +{ |
| 132 | + static constexpr std::size_t Bins = 20; |
| 133 | + const RRegularAxis axis(Bins, {0, Bins}); |
| 134 | + RHistEngine<float> engine1({axis}); |
| 135 | + ASSERT_EQ(engine1.GetNDimensions(), 1); |
| 136 | + RHistEngine<float> engine2({axis, axis}); |
| 137 | + ASSERT_EQ(engine2.GetNDimensions(), 2); |
| 138 | + |
| 139 | + EXPECT_NO_THROW(engine1.FillAtomic(std::make_tuple(1), RWeight(1))); |
| 140 | + EXPECT_THROW(engine1.FillAtomic(std::make_tuple(1, 2), RWeight(1)), std::invalid_argument); |
| 141 | + |
| 142 | + EXPECT_THROW(engine2.FillAtomic(std::make_tuple(1), RWeight(1)), std::invalid_argument); |
| 143 | + EXPECT_NO_THROW(engine2.FillAtomic(std::make_tuple(1, 2), RWeight(1))); |
| 144 | + EXPECT_THROW(engine2.FillAtomic(std::make_tuple(1, 2, 3), RWeight(1)), std::invalid_argument); |
| 145 | +} |
0 commit comments