@@ -172,6 +172,43 @@ TEST(RHist, FillWeight)
172172 EXPECT_FLOAT_EQ (hist.ComputeStdDev (), 0.49913420 );
173173}
174174
175+ TEST (RHist, FillCategorical)
176+ {
177+ const std::vector<std::string> categories = {" a" , " b" , " c" };
178+ const RCategoricalAxis axis (categories);
179+ RHist<int > hist ({axis});
180+
181+ hist.Fill (" b" );
182+ hist.Fill (std::make_tuple (" c" ));
183+
184+ EXPECT_EQ (hist.GetBinContent (RBinIndex (1 )), 1 );
185+ std::array<RBinIndex, 1 > indices = {2 };
186+ EXPECT_EQ (hist.GetBinContent (indices), 1 );
187+
188+ EXPECT_EQ (hist.GetNEntries (), 2 );
189+ EXPECT_FLOAT_EQ (hist.ComputeNEffectiveEntries (), 2 );
190+ }
191+
192+ TEST (RHist, FillCategoricalWeight)
193+ {
194+ const std::vector<std::string> categories = {" a" , " b" , " c" };
195+ const RCategoricalAxis axis (categories);
196+ RHist<float > hist ({axis});
197+
198+ hist.Fill (" b" , RWeight (0.8 ));
199+ hist.Fill (std::make_tuple (" c" ), RWeight (0.9 ));
200+
201+ EXPECT_FLOAT_EQ (hist.GetBinContent (RBinIndex (1 )), 0.8 );
202+ std::array<RBinIndex, 1 > indices = {2 };
203+ EXPECT_FLOAT_EQ (hist.GetBinContent (indices), 0.9 );
204+
205+ EXPECT_EQ (hist.GetNEntries (), 2 );
206+ EXPECT_FLOAT_EQ (hist.GetStats ().GetSumW (), 1.7 );
207+ EXPECT_FLOAT_EQ (hist.GetStats ().GetSumW2 (), 1.45 );
208+ // Cross-checked with TH1
209+ EXPECT_FLOAT_EQ (hist.ComputeNEffectiveEntries (), 1.9931034 );
210+ }
211+
175212TEST (RHist, Scale)
176213{
177214 static constexpr std::size_t Bins = 20 ;
0 commit comments