33#include < array>
44#include < stdexcept>
55#include < type_traits>
6+ #include < utility>
67#include < variant>
78#include < vector>
89
@@ -23,27 +24,41 @@ TEST(RHistEngine, Constructor)
2324 const std::vector<std::string> categories = {" a" , " b" , " c" };
2425 const RCategoricalAxis categoricalAxis (categories);
2526
26- RHistEngine<int > engine ({regularAxis, variableBinAxis, categoricalAxis});
27+ // The most generic constructor takes a vector of axis objects.
28+ const std::vector<RAxisVariant> axes = {regularAxis, variableBinAxis, categoricalAxis};
29+ RHistEngine<int > engine (axes);
2730 EXPECT_EQ (engine.GetNDimensions (), 3 );
28- const auto &axes = engine.GetAxes ();
29- ASSERT_EQ (axes.size (), 3 );
30- EXPECT_EQ (axes[0 ].index (), 0 );
31- EXPECT_EQ (axes[1 ].index (), 1 );
32- EXPECT_EQ (axes[2 ].index (), 2 );
33- EXPECT_TRUE (std::get_if<RRegularAxis>(&axes[0 ]) != nullptr );
34- EXPECT_TRUE (std::get_if<RVariableBinAxis>(&axes[1 ]) != nullptr );
35- EXPECT_TRUE (std::get_if<RCategoricalAxis>(&axes[2 ]) != nullptr );
36-
37- // Both axes include underflow and overflow bins.
31+ {
32+ const auto &engineAxes = engine.GetAxes ();
33+ ASSERT_EQ (engineAxes.size (), 3 );
34+ EXPECT_EQ (engineAxes[0 ].index (), 0 );
35+ EXPECT_EQ (engineAxes[1 ].index (), 1 );
36+ EXPECT_EQ (engineAxes[2 ].index (), 2 );
37+ EXPECT_TRUE (std::get_if<RRegularAxis>(&engineAxes[0 ]) != nullptr );
38+ EXPECT_TRUE (std::get_if<RVariableBinAxis>(&engineAxes[1 ]) != nullptr );
39+ EXPECT_TRUE (std::get_if<RCategoricalAxis>(&engineAxes[2 ]) != nullptr );
40+ }
41+
42+ // All axes include underflow and overflow bins.
3843 EXPECT_EQ (engine.GetTotalNBins (), (BinsX + 2 ) * (BinsY + 2 ) * (categories.size () + 1 ));
3944
45+ // Test other constructors, including move-assignment.
4046 engine = RHistEngine<int >(BinsX, {0 , BinsX});
4147 ASSERT_EQ (engine.GetNDimensions (), 1 );
4248 auto *regular = std::get_if<RRegularAxis>(&engine.GetAxes ()[0 ]);
4349 ASSERT_TRUE (regular != nullptr );
4450 EXPECT_EQ (regular->GetNNormalBins (), BinsX);
4551 EXPECT_EQ (regular->GetLow (), 0 );
4652 EXPECT_EQ (regular->GetHigh (), BinsX);
53+ // std::make_pair will take the types of the arguments, std::size_t in this case.
54+ engine = RHistEngine<int >(BinsX, std::make_pair (0 , BinsX));
55+ EXPECT_EQ (engine.GetNDimensions (), 1 );
56+
57+ // Brace-enclosed initializer list
58+ engine = RHistEngine<int >({variableBinAxis});
59+ EXPECT_EQ (engine.GetNDimensions (), 1 );
60+ engine = RHistEngine<int >({variableBinAxis, categoricalAxis});
61+ EXPECT_EQ (engine.GetNDimensions (), 2 );
4762}
4863
4964TEST (RHistEngine, GetBinContentInvalidNumberOfArguments)
0 commit comments