Skip to content

Commit

Permalink
Merge pull request #195 from K-Johnson-Horrigan/main
Browse files Browse the repository at this point in the history
delete hosts before deleting sym systematic
  • Loading branch information
anyaevostinar committed Nov 11, 2022
2 parents 9a85ee6 + 082a8cf commit 28d4e90
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions source/default_mode/SymWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class SymWorld : public emp::World<Organism>{
}

if(my_config->PHYLOGENY()){ //host systematic deletion is handled by empirical world destructor
Clear(); // delete hosts here so that hosted symbionts get
// deleted and unlinked from the sym_sys
sym_sys.Delete();
}
}
Expand Down
20 changes: 20 additions & 0 deletions source/test/default_mode_test/SymWorld.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,26 @@ TEST_CASE( "Symbiont Phylogeny", "[default]" ){
world.DoSymDeath(0);
REQUIRE(sym_sys->GetNumActive() == 0);
}

THEN("hosted and free symbionts are deleted without a segmentation fault") {
world_size = 4;
world.Resize(world_size);

// add a free living sym to the world
emp::Ptr<Organism> symbiont = emp::NewPtr<Symbiont>(&random, &world, &config, int_val);
world.InjectSymbiont(symbiont);

// add a host to the world
emp::Ptr<Organism> host = emp::NewPtr<Host>(&random, &world, &config, int_val);
world.InjectHost(host);

// add a hosted sym to the host
emp::Ptr<Organism> hosted_sym = symbiont->Reproduce();
host->AddSymbiont(hosted_sym);

// check that free living organisms have properly been added to the world
REQUIRE(world.GetNumOrgs() == 2);
}
}

WHEN("generations pass"){
Expand Down

0 comments on commit 28d4e90

Please sign in to comment.