Skip to content
Snippets Groups Projects
Unverified Commit ab6c6ee1 authored by Matthias Wolf's avatar Matthias Wolf Committed by GitHub
Browse files

Fix #226 for empty selections (#232)

parent c34c7c4a
No related branches found
No related tags found
No related merge requests found
...@@ -163,6 +163,14 @@ class TestNodePopulation(unittest.TestCase): ...@@ -163,6 +163,14 @@ class TestNodePopulation(unittest.TestCase):
) )
def test_enumeration_values(self): def test_enumeration_values(self):
self.assertEqual(
self.test_obj.get_attribute(
"E-mapping-good",
Selection([])
).tolist(),
[]
)
self.assertEqual( self.assertEqual(
self.test_obj.get_attribute( self.test_obj.get_attribute(
"E-mapping-good", "E-mapping-good",
...@@ -240,10 +248,12 @@ class TestEdgePopulation(unittest.TestCase): ...@@ -240,10 +248,12 @@ class TestEdgePopulation(unittest.TestCase):
def test_source_nodes(self): def test_source_nodes(self):
self.assertEqual(self.test_obj.source_node(1), 1) 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([0, 1, 2, 4])).tolist(), [1, 1, 2, 3])
self.assertEqual(self.test_obj.source_nodes(Selection([])).tolist(), [])
def test_target_nodes(self): def test_target_nodes(self):
self.assertEqual(self.test_obj.target_node(1), 2) 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([0, 1, 2, 4])).tolist(), [1, 2, 1, 0])
self.assertEqual(self.test_obj.target_nodes(Selection([])).tolist(), [])
def test_afferent_edges(self): def test_afferent_edges(self):
self.assertEqual(self.test_obj.afferent_edges([1, 2]).ranges, [(0, 4), (5, 6)]) self.assertEqual(self.test_obj.afferent_edges([1, 2]).ranges, [(0, 4), (5, 6)])
......
...@@ -89,7 +89,9 @@ std::vector<T> _readSelection(const HighFive::DataSet& dset, const Selection& se ...@@ -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> 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) { 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()); return _readChunk<T>(dset, selection.ranges().front());
} }
......
...@@ -38,6 +38,8 @@ TEST_CASE("NodePopulation", "[base]") { ...@@ -38,6 +38,8 @@ TEST_CASE("NodePopulation", "[base]") {
REQUIRE(population.enumerationNames() == REQUIRE(population.enumerationNames() ==
std::set<std::string>{"E-mapping-good", "E-mapping-bad"}); 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}})) == CHECK(population.getAttribute<double>("attr-X", Selection({{0, 1}, {5, 6}})) ==
std::vector<double>{11.0, 16.0}); std::vector<double>{11.0, 16.0});
CHECK(population.getAttribute<float>("attr-X", Selection({{0, 1}})) == CHECK(population.getAttribute<float>("attr-X", Selection({{0, 1}})) ==
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment