Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/boost/histogram/indexed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ class BOOST_ATTRIBUTE_NODISCARD indexed_range {
const auto cbeg = indices_.begin();
auto c = cbeg;
++iter_;
// rank-0 histogram has a single cell and no indices to update
if (c == indices_.end()) return *this;
++c->idx;
if (c->idx < c->end) return *this;
while (c->idx == c->end) {
Expand Down
11 changes: 11 additions & 0 deletions test/algorithm_empty_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <algorithm>
#include <array>
#include <boost/core/lightweight_test.hpp>
#include <boost/histogram/accumulators/weighted_mean.hpp>
Expand Down Expand Up @@ -61,5 +62,15 @@ int main() {
run_tests<static_tag>();
run_tests<dynamic_tag>();

{
// regression test for https://github.com/boostorg/histogram/issues/430
auto h = make(dynamic_tag());
BOOST_TEST(empty(h, coverage::all));
BOOST_TEST(empty(h, coverage::inner));
std::fill(h.begin(), h.end(), 1);
BOOST_TEST(!empty(h, coverage::all));
BOOST_TEST(!empty(h, coverage::inner));
}

return boost::report_errors();
}
8 changes: 8 additions & 0 deletions test/algorithm_sum_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,13 @@ int main() {
run_tests<static_tag>();
run_tests<dynamic_tag>();

{
// regression test for https://github.com/boostorg/histogram/issues/430
auto h = make(dynamic_tag());
std::fill(h.begin(), h.end(), 3);
BOOST_TEST_EQ(sum(h), 3);
BOOST_TEST_EQ(sum(h, coverage::inner), 3);
}

return boost::report_errors();
}
26 changes: 26 additions & 0 deletions test/indexed_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,29 @@ void run_comparison_tests(Tag) {
BOOST_TEST(1 >= a);
}

// regression test for https://github.com/boostorg/histogram/issues/430
void run_0d_tests(coverage cov) {
auto h = make(dynamic_tag());
BOOST_TEST_EQ(h.rank(), 0u);
BOOST_TEST_EQ(h.size(), 1u);
std::fill(h.begin(), h.end(), 2);

auto ind = indexed(h, cov);
auto it = ind.begin();
BOOST_TEST(it != ind.end());
BOOST_TEST_EQ(it->indices().size(), 0u);
BOOST_TEST_EQ(**it, 2);
++it;
BOOST_TEST(it == ind.end());

int count = 0;
for (auto&& x : indexed(h, cov)) {
BOOST_TEST_EQ(*x, 2);
++count;
}
BOOST_TEST_EQ(count, 1);
}

template <class Tag>
void run_indexed_with_range_tests(Tag) {
{
Expand Down Expand Up @@ -258,6 +281,9 @@ int main() {
run_comparison_tests(static_tag{});
run_comparison_tests(dynamic_tag{});

run_0d_tests(coverage::inner);
run_0d_tests(coverage::all);

run_indexed_with_range_tests(static_tag{});
run_indexed_with_range_tests(dynamic_tag{});
return boost::report_errors();
Expand Down
Loading