Skip to content

Commit

Permalink
Fix #226 for empty selections (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
matz-e authored Oct 11, 2022
1 parent c34c7c4 commit ab6c6ee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
10 changes: 10 additions & 0 deletions python/tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ def test_enumeration_names(self):
)

def test_enumeration_values(self):
self.assertEqual(
self.test_obj.get_attribute(
"E-mapping-good",
Selection([])
).tolist(),
[]
)

self.assertEqual(
self.test_obj.get_attribute(
"E-mapping-good",
Expand Down Expand Up @@ -240,10 +248,12 @@ def test_target(self):
def test_source_nodes(self):
self.assertEqual(self.test_obj.source_node(1), 1)
self.assertEqual(self.test_obj.source_nodes(Selection([0, 1, 2, 4])).tolist(), [1, 1, 2, 3])
self.assertEqual(self.test_obj.source_nodes(Selection([])).tolist(), [])

def test_target_nodes(self):
self.assertEqual(self.test_obj.target_node(1), 2)
self.assertEqual(self.test_obj.target_nodes(Selection([0, 1, 2, 4])).tolist(), [1, 2, 1, 0])
self.assertEqual(self.test_obj.target_nodes(Selection([])).tolist(), [])

def test_afferent_edges(self):
self.assertEqual(self.test_obj.afferent_edges([1, 2]).ranges, [(0, 4), (5, 6)])
Expand Down
4 changes: 3 additions & 1 deletion src/population.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ std::vector<T> _readSelection(const HighFive::DataSet& dset, const Selection& se

template <typename T, typename std::enable_if<std::is_pod<T>::value>::type* = nullptr>
std::vector<T> _readSelection(const HighFive::DataSet& dset, const Selection& selection) {
if (selection.ranges().size() == 1) {
if (selection.ranges().empty()) {
return {};
} else if (selection.ranges().size() == 1) {
return _readChunk<T>(dset, selection.ranges().front());
}

Expand Down
2 changes: 2 additions & 0 deletions tests/test_nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ TEST_CASE("NodePopulation", "[base]") {
REQUIRE(population.enumerationNames() ==
std::set<std::string>{"E-mapping-good", "E-mapping-bad"});

CHECK(population.getAttribute<double>("attr-X", Selection({})) ==
std::vector<double>{});
CHECK(population.getAttribute<double>("attr-X", Selection({{0, 1}, {5, 6}})) ==
std::vector<double>{11.0, 16.0});
CHECK(population.getAttribute<float>("attr-X", Selection({{0, 1}})) ==
Expand Down

0 comments on commit ab6c6ee

Please sign in to comment.