Skip to content

Commit

Permalink
Add prune tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emilydolson committed Jul 16, 2024
1 parent 4f69b75 commit df0ffff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion systematics_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ PYBIND11_MODULE(systematics, m) {
Set a custom function that is triggered every time a taxon is pruned from the tree. This occurs when a taxon and all its descendants go extinct.
The function must take a single argument: a `taxon_t` object representing the taxon getting pruned.
The custom function will be triggered at the beginning of the taxon pruning process.
This allows the user to customize the way objects are represented interlally by the systematics manager, or to implement extra bookkeeping functionality.
This allows the user to customize the way objects are represented internally by the systematics manager, or to implement extra bookkeeping functionality.
Parameters
----------
Expand Down
30 changes: 28 additions & 2 deletions test/test_systematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def test_systematics_by_position():
assert sys.is_taxon_at(child_pos) is True
sys.add_org_by_position(org, org_pos, child_pos)
assert sys.is_taxon_at(child_pos) is False
# sys.remove_org_by_position((2,0))
sys.set_next_parent_by_position(org_pos)
assert sys.get_next_parent() == sys.get_taxon_at(org_pos)
sys.add_org_by_position(ExampleOrg("test"), child_pos)
assert sys.get_taxon_at(child_pos).get_parent() == sys.get_taxon_at(org_pos)
assert sys.get_next_parent() is None


def test_construct_systematics():
Expand Down Expand Up @@ -501,4 +505,26 @@ def test_collapse_unifurcations():
sys.remove_org(org4_tax)
assert sys.get_num_ancestors() == 1
sys.remove_org(org5_tax)
assert sys.get_num_ancestors() == 0
assert sys.get_num_ancestors() == 0


tax_sum = 0


def test_on_prune():
sys = systematics.Systematics(lambda x: x, True, True, False, False)

def prune_fun(x):
global tax_sum
tax_sum += x.get_info()

sys.on_prune(prune_fun)
tax1 = sys.add_org(1)
tax2 = sys.add_org(2, tax1)
tax3 = sys.add_org(3, tax2)
sys.remove_org(tax2)
assert tax_sum == 0
sys.remove_org(tax3)
assert tax_sum == 5
sys.remove_org(tax1)
assert tax_sum == 6

0 comments on commit df0ffff

Please sign in to comment.