Skip to content

Commit

Permalink
Add test of repeatedly simulating short epochs of a model.
Browse files Browse the repository at this point in the history
  • Loading branch information
molpopgen committed Feb 28, 2023
1 parent 264e769 commit ae486f5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
65 changes: 61 additions & 4 deletions cpptests/test_evolvets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@
#include "fwdpy11/discrete_demography/exceptions.hpp"
#include "fwdpy11/discrete_demography/simulation/functions.hpp"

BOOST_AUTO_TEST_SUITE(test_evolvets)

/* Tests needed
*
* - [X] simlen > model time in graph
* - [X] initial population config not compatible
* with state of parental demes for single deme models.
* - [X] initial population config not compatible
* with state of parental demes for multi deme models.
* - [] simlen < model time in graph,
* but we keep simulating until we are done.
* - [X] simlen < model time in graph,
* but we keep simulating until we are done.
* - [X] One deme, multiple epochs, test size history is
* correct
*/
Expand Down Expand Up @@ -266,6 +264,8 @@ validate_ancestry(const std::vector<ancestry_proportions>& ancestry,
return false;
}

BOOST_AUTO_TEST_SUITE(test_evolvets)

BOOST_FIXTURE_TEST_CASE(test_basic_api_coherence, common_setup)
{
auto model = SingleDemeModel();
Expand Down Expand Up @@ -617,3 +617,60 @@ BOOST_FIXTURE_TEST_CASE(test_ancestry_with_extreme_migration_until_one_generatio
}

BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE(test_evolvets_start_stop_start)

// Tests of repeatedly entering in to the same model
BOOST_FIXTURE_TEST_CASE(
test_ancestry_with_extreme_migration_until_one_generation_ago_start_stop,
common_setup_with_ancestry_tracking)
{
// NOTE: this is a copy-paste of a test from above.
// The only difference is that we call into the
// evolve function for one generation at a time.
auto model = ExtremeMigrationUntilOneGenerationAgo();
fwdpy11_core::ForwardDemesGraph forward_demes_graph(model.yaml, 10);
BOOST_REQUIRE_EQUAL(forward_demes_graph.number_of_demes(), 2);
pop = fwdpy11::DiploidPopulation({1000, 1000}, 1.);
update_parents(pop);
auto last_generation = pop.generation;
for (std::size_t i = 0; i < 10; ++i)
{
evolve_with_tree_sequences_refactor(
rng, pop, recorder, 10, forward_demes_graph, 1, 0., 0., mregions,
recregions, gvalue_ptrs, sample_recorder_callback, stopping_criterion,
post_simplification_recorder, options);
BOOST_REQUIRE_EQUAL(pop.generation, last_generation + 1);
last_generation += 1;
}
BOOST_REQUIRE_EQUAL(pop.generation, 10);

auto validate_complete_ancestry = [](std::uint32_t p) { return p == 1000; };

auto validate_partial_ancestry = [](std::uint32_t p) { return p > 0 && p < 1000; };

// NOTE: at the deme sizes in this model
// and migration rates reflecting 50% migrant
// ancestry each generation, is is very unlikely
// to not observe some ancestry each generation
// in each combo tested below.
for (std::uint32_t g = 1; g < 10; ++g)
{
for (std::int32_t i = 0; i < 2; ++i)
{
for (std::int32_t j = 0; j < 2; ++j)
{
auto found = validate_ancestry(ancestry, g, i, j,
validate_partial_ancestry);
BOOST_REQUIRE(found);
}
}
}
auto found = validate_ancestry(ancestry, 10, 0, 0, validate_complete_ancestry);
BOOST_REQUIRE(found);

found = validate_ancestry(ancestry, 10, 1, 1, validate_complete_ancestry);
BOOST_REQUIRE(found);
}

BOOST_AUTO_TEST_SUITE_END()
1 change: 1 addition & 0 deletions doc/misc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Back end changes
PR {pr}`1073`.
PR {pr}`1074`.
PR {pr}`1075`.
PR {pr}`1076`.

## 0.19.3

Expand Down

0 comments on commit ae486f5

Please sign in to comment.