Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / histogram / test / histogram_dynamic_test.cpp
index 2d55c68..8200f94 100644 (file)
@@ -5,6 +5,7 @@
 // or copy at http://www.boost.org/LICENSE_1_0.txt)
 
 #include <algorithm>
+#include <boost/core/ignore_unused.hpp>
 #include <boost/core/lightweight_test.hpp>
 #include <boost/histogram/axis.hpp>
 #include <boost/histogram/axis/ostream.hpp>
@@ -56,6 +57,22 @@ int main() {
     BOOST_TEST_EQ(h3.axis(1), v2[1]);
   }
 
+  // too many axes
+  {
+    using I = axis::integer<int, axis::null_type, axis::option::none_t>;
+
+    // test edge case
+    auto av = std::vector<I>(BOOST_HISTOGRAM_DETAIL_AXES_LIMIT, I(0, 1));
+    auto h = make_histogram(av);
+    auto inputs = std::vector<std::vector<int>>(BOOST_HISTOGRAM_DETAIL_AXES_LIMIT,
+                                                std::vector<int>(1, 0));
+    h.fill(inputs); // should not crash
+
+    auto bad = std::vector<I>(BOOST_HISTOGRAM_DETAIL_AXES_LIMIT + 1, I(0, 1));
+    boost::ignore_unused(bad);
+    BOOST_TEST_THROWS((void)make_histogram(bad), std::invalid_argument);
+  }
+
   // bad fill
   {
     auto a = axis::integer<>(0, 1);