Skip to content

Commit

Permalink
add increasingness test in sort_hierarchy_with_altitudes
Browse files Browse the repository at this point in the history
  • Loading branch information
PerretB committed Apr 29, 2020
1 parent 3fc6b92 commit 8ae7d02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions higra/algo/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ def sort_hierarchy_with_altitudes(tree, altitudes):
:param altitudes: node altitudes of the input tree
:return: the sorted tree (Concept :class:`~higra.CptHierarchy`), its node altitudes, and the node map
"""
if not test_altitudes_increasingness(tree, altitudes):
raise ValueError("'altitudes' must be increasing for 'tree'.")

new_tree, node_map = hg.cpp._sort_hierarchy_with_altitudes(tree, altitudes)
new_altitudes = altitudes[node_map]

Expand Down
5 changes: 5 additions & 0 deletions test/python/test_algo/test_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ def test_sort_hierarchy_with_altitudes(self):
ref_altitudes = np.asarray((0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7))
self.assertTrue(np.all(ref_altitudes == naltitudes))

tree = hg.Tree(np.asarray((5, 5, 6, 6, 7, 7, 7, 7)))
altitudes = np.asarray((0, 0, 1, 0, 0, 2, 1, 1))
with self.assertRaises(ValueError):
hg.sort_hierarchy_with_altitudes(tree, altitudes)

def test_test_altitudes_increasingness(self):
tree = hg.Tree(np.asarray((5, 5, 6, 6, 7, 7, 7, 7)))

Expand Down

0 comments on commit 8ae7d02

Please sign in to comment.