Skip to content

Commit

Permalink
Throw exception when pop.generation is past the end of a model.
Browse files Browse the repository at this point in the history
  • Loading branch information
molpopgen committed Feb 25, 2023
1 parent e064f32 commit 3fa24f9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cpptests/test_evolvets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,22 @@ BOOST_FIXTURE_TEST_CASE(test_initial_pop_size_invalid, common_setup)
BOOST_REQUIRE_EQUAL(pop.generation, 0);
}

BOOST_FIXTURE_TEST_CASE(test_generation_time_past_end_of_model, common_setup)
{
auto model = SingleDemeModel();
fwdpy11_core::ForwardDemesGraph forward_demes_graph(model.yaml, 10);

// The model is only set to simulate 10 generations
pop.generation = 11;
BOOST_CHECK_THROW(
{
evolve_with_tree_sequences_refactor(
rng, pop, recorder, 10, forward_demes_graph, 10, 0., 0., mregions,
recregions, gvalue_ptrs, sample_recorder_callback, stopping_criterion,
post_simplification_recorder, options);
},
fwdpy11::discrete_demography::DemographyError);
BOOST_REQUIRE_EQUAL(pop.generation, 11);
}

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 @@ -11,6 +11,7 @@ Back end changes
PR {pr}`1069`.
PR {pr}`1070`.
PR {pr}`1071`.
PR {pr}`1072`.

## 0.19.3

Expand Down
6 changes: 6 additions & 0 deletions lib/evolve_discrete_demes/evolvets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,12 @@ evolve_with_tree_sequences_refactor(
}
}

if (pop.generation >= demography.model_end_time())
{
throw ddemog::DemographyError(
"current time of population is past the end of the model");
}

// TODO: this goes away
//auto current_demographic_state = demography.get_model_state();

Expand Down

0 comments on commit 3fa24f9

Please sign in to comment.