Skip to content

Commit

Permalink
Empty instead of throw if id out of range
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Cornu committed Jul 9, 2020
1 parent 7798143 commit 7fae5e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/report_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ DataFrame<T> ReportReader<T>::Population::get(const nonstd::optional<Selection>&
}
}

if (data_frame.ids.empty()) {
throw SonataError("Given ids are out of range");
if (data_frame.ids.empty()) { // At the end no data available (wrong node_ids?)
return DataFrame<T>{{}, {}, {}};
}

return data_frame;
Expand Down
7 changes: 4 additions & 3 deletions tests/test_report_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ TEST_CASE("SomaReportReader limits", "[base]") {
auto pop = reader.openPopulation("All");

// ids out of range
REQUIRE_THROWS(pop.get(Selection({{100, 101}})));
REQUIRE(pop.get(Selection({{100, 101}})).ids == DataFrame<NodeID>::DataType{});

// Inverted id
REQUIRE_THROWS(pop.get(Selection({{2, 1}})));
Expand Down Expand Up @@ -88,7 +88,8 @@ TEST_CASE("ElementReportReader limits", "[base]") {
auto pop = reader.openPopulation("All");

// ids out of range
REQUIRE_THROWS(pop.get(Selection({{100, 101}})));
REQUIRE(pop.get(Selection({{100, 101}})).ids ==
DataFrame<std::pair<NodeID, ElementID>>::DataType{});

// Inverted id
REQUIRE_THROWS(pop.get(Selection({{2, 1}})));
Expand Down Expand Up @@ -127,7 +128,7 @@ TEST_CASE("ElementReportReader", "[base]") {

auto data = pop.get(Selection({{3, 5}}), 0.2, 0.5);
REQUIRE(data.ids ==
DataFrame<std::pair<NodeID, uint32_t>>::DataType{
DataFrame<std::pair<NodeID, ElementID>>::DataType{
{{3, 5}, {3, 5}, {3, 6}, {3, 6}, {3, 7}, {4, 7}, {4, 8}, {4, 8}, {4, 9}, {4, 9}}});
testTimes(data.times, 0.2, 0.2, 2);
REQUIRE(data.data ==
Expand Down

0 comments on commit 7fae5e5

Please sign in to comment.