@@ -59,8 +59,14 @@ TEST(RProfile, Fill)
5959 static constexpr std::size_t Bins = 20 ;
6060 RProfile profile (Bins, {0 , Bins});
6161
62+ profile.Fill (8.5 , 23.0 );
6263 profile.Fill (std::make_tuple (9.5 ), 25.0 );
6364
65+ auto &bin8 = profile.GetBinContent (RBinIndex (8 ));
66+ EXPECT_EQ (bin8.fSumValues , 23.0 );
67+ EXPECT_EQ (bin8.fSumValues2 , 529.0 );
68+ EXPECT_EQ (bin8.fSum , 1.0 );
69+ EXPECT_EQ (bin8.fSum2 , 1.0 );
6470 std::array<RBinIndex, 1 > indices = {9 };
6571 auto &bin9 = profile.GetBinContent (indices);
6672 EXPECT_EQ (bin9.fSumValues , 25.0 );
@@ -69,13 +75,36 @@ TEST(RProfile, Fill)
6975 EXPECT_EQ (bin9.fSum2 , 1.0 );
7076}
7177
78+ TEST (RProfile, FillInvalidNumberOfArguments)
79+ {
80+ static constexpr std::size_t Bins = 20 ;
81+ const RRegularAxis axis (Bins, {0 , Bins});
82+ RProfile profile1 (axis);
83+ ASSERT_EQ (profile1.GetNDimensions (), 1 );
84+ RProfile profile2 (axis, axis);
85+ ASSERT_EQ (profile2.GetNDimensions (), 2 );
86+
87+ EXPECT_NO_THROW (profile1.Fill (1 , 2 ));
88+ EXPECT_THROW (profile1.Fill (1 , 2 , 3 ), std::invalid_argument);
89+
90+ EXPECT_THROW (profile2.Fill (1 , 2 ), std::invalid_argument);
91+ EXPECT_NO_THROW (profile2.Fill (1 , 2 , 3 ));
92+ EXPECT_THROW (profile2.Fill (1 , 2 , 3 , 4 ), std::invalid_argument);
93+ }
94+
7295TEST (RProfile, FillWeight)
7396{
7497 static constexpr std::size_t Bins = 20 ;
7598 RProfile profile (Bins, {0 , Bins});
7699
100+ profile.Fill (8.5 , 23.0 , RWeight (0.8 ));
77101 profile.Fill (std::make_tuple (9.5 ), 25.0 , RWeight (0.9 ));
78102
103+ auto &bin8 = profile.GetBinContent (RBinIndex (8 ));
104+ EXPECT_FLOAT_EQ (bin8.fSumValues , 18.4 );
105+ EXPECT_FLOAT_EQ (bin8.fSumValues2 , 423.2 );
106+ EXPECT_FLOAT_EQ (bin8.fSum , 0.8 );
107+ EXPECT_FLOAT_EQ (bin8.fSum2 , 0.64 );
79108 std::array<RBinIndex, 1 > indices = {9 };
80109 auto &bin9 = profile.GetBinContent (indices);
81110 EXPECT_FLOAT_EQ (bin9.fSumValues , 22.5 );
@@ -84,14 +113,38 @@ TEST(RProfile, FillWeight)
84113 EXPECT_FLOAT_EQ (bin9.fSum2 , 0.81 );
85114}
86115
116+ TEST (RProfile, FillWeightInvalidNumberOfArguments)
117+ {
118+ static constexpr std::size_t Bins = 20 ;
119+ const RRegularAxis axis (Bins, {0 , Bins});
120+ RProfile profile1 (axis);
121+ ASSERT_EQ (profile1.GetNDimensions (), 1 );
122+ RProfile profile2 (axis, axis);
123+ ASSERT_EQ (profile2.GetNDimensions (), 2 );
124+
125+ EXPECT_THROW (profile1.Fill (1 , RWeight (1 )), std::invalid_argument);
126+ EXPECT_NO_THROW (profile1.Fill (1 , 2 , RWeight (1 )));
127+ EXPECT_THROW (profile1.Fill (1 , 2 , 3 , RWeight (1 )), std::invalid_argument);
128+
129+ EXPECT_THROW (profile2.Fill (1 , 2 , RWeight (1 )), std::invalid_argument);
130+ EXPECT_NO_THROW (profile2.Fill (1 , 2 , 3 , RWeight (1 )));
131+ EXPECT_THROW (profile2.Fill (1 , 2 , 3 , 4 , RWeight (1 )), std::invalid_argument);
132+ }
133+
87134TEST (RProfile, FillCategorical)
88135{
89136 const std::vector<std::string> categories = {" a" , " b" , " c" };
90137 const RCategoricalAxis axis (categories);
91138 RProfile profile ({axis});
92139
140+ profile.Fill (" b" , 23.0 );
93141 profile.Fill (std::make_tuple (" c" ), 25.0 );
94142
143+ auto &bin1 = profile.GetBinContent (RBinIndex (1 ));
144+ EXPECT_EQ (bin1.fSumValues , 23.0 );
145+ EXPECT_EQ (bin1.fSumValues2 , 529.0 );
146+ EXPECT_EQ (bin1.fSum , 1.0 );
147+ EXPECT_EQ (bin1.fSum2 , 1.0 );
95148 std::array<RBinIndex, 1 > indices = {2 };
96149 auto &bin2 = profile.GetBinContent (indices);
97150 EXPECT_EQ (bin2.fSumValues , 25.0 );
@@ -106,8 +159,14 @@ TEST(RProfile, FillCategoricalWeight)
106159 const RCategoricalAxis axis (categories);
107160 RProfile profile ({axis});
108161
162+ profile.Fill (" b" , 23.0 , RWeight (0.8 ));
109163 profile.Fill (std::make_tuple (" c" ), 25.0 , RWeight (0.9 ));
110164
165+ auto &bin1 = profile.GetBinContent (RBinIndex (1 ));
166+ EXPECT_FLOAT_EQ (bin1.fSumValues , 18.4 );
167+ EXPECT_FLOAT_EQ (bin1.fSumValues2 , 423.2 );
168+ EXPECT_FLOAT_EQ (bin1.fSum , 0.8 );
169+ EXPECT_FLOAT_EQ (bin1.fSum2 , 0.64 );
111170 std::array<RBinIndex, 1 > indices = {2 };
112171 auto &bin2 = profile.GetBinContent (indices);
113172 EXPECT_FLOAT_EQ (bin2.fSumValues , 22.5 );
@@ -151,4 +210,11 @@ TEST(RProfile, FillForward)
151210 EXPECT_EQ (profile.GetBinContent (1 ).fSumValues , 34.5 );
152211
153212 ASSERT_FALSE (CopyArgument::HasBeenCopied ());
213+
214+ CopyArgument arg (2.5 );
215+ profile.Fill (arg, value);
216+ profile.Fill (arg, value, RWeight (0.5 ));
217+ EXPECT_EQ (profile.GetBinContent (2 ).fSumValues , 34.5 );
218+
219+ ASSERT_FALSE (CopyArgument::HasBeenCopied ());
154220}
0 commit comments