Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/event/Infections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
namespace event {
class Infections::InfectionsIMPL {
private:
double gt3_prob = 0;

using incidencemap_t =
std::unordered_map<Utils::tuple_3i, double, Utils::key_hash_3i,
Utils::key_equal_3i>;
Expand Down Expand Up @@ -101,11 +103,25 @@ namespace event {
// decide whether person is infected; if value == 0, infect
if (decider->GetDecision(prob) == 0) {
person->InfectHCV();
// decide whether hcv is genotype three
if (decider->GetDecision({gt3_prob}) == 0) {
person->SetGenotypeThree(true);
}
}
}

InfectionsIMPL(std::shared_ptr<datamanagement::DataManagerBase> dm) {
int rc = LoadIncidenceData(dm);
std::string data;
dm->GetFromConfig("infection.genotype_three_prob", data);
if (data.empty()) {
spdlog::get("main")->warn(
"[Infections] No probability of genotype three infection "
"found. Using default value of {}",
gt3_prob);
} else {
this->gt3_prob = Utils::stod_positive(data);
}
}
};
Infections::Infections(
Expand Down
99 changes: 98 additions & 1 deletion tests/src/eventtests/InfectionsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ TEST_F(InfectionsTest, Infections_NewInfection) {
ON_CALL(*testPerson, GetHCV()).WillByDefault(Return(person::HCV::NONE));

// Data Setup
ON_CALL(*event_dm, GetFromConfig("infection.genotype_three_prob", _))
.WillByDefault(DoAll(SetArgReferee<1>("0.5"), Return(0)));
std::vector<double> storage = {1.0};
ON_CALL(*event_dm, SelectCustomCallback(INCIDENCE_QUERY, _, _, _))
.WillByDefault(
Expand Down Expand Up @@ -58,6 +60,9 @@ TEST_F(InfectionsTest, Infections_DoNotInfect) {
ON_CALL(*testPerson, GetHCV()).WillByDefault(Return(person::HCV::NONE));

// Data Setup
ON_CALL(*event_dm, GetFromConfig("infection.genotype_three_prob", _))
.WillByDefault(DoAll(SetArgReferee<1>("0.5"), Return(0)));

// Incidence Setup
double incidence = 0.0;
Utils::tuple_3i tup_3i = std::make_tuple(25, 0, 0);
Expand Down Expand Up @@ -89,6 +94,10 @@ TEST_F(InfectionsTest, Infections_AcuteProgression) {
ON_CALL(*testPerson, GetHCV()).WillByDefault(Return(person::HCV::ACUTE));
ON_CALL(*testPerson, GetTimeSinceHCVChanged()).WillByDefault(Return(6));

// Data Setup
ON_CALL(*event_dm, GetFromConfig("infection.genotype_three_prob", _))
.WillByDefault(DoAll(SetArgReferee<1>("0.5"), Return(0)));

// Incidence Setup
double incidence = 0.0;
Utils::tuple_3i tup_3i = std::make_tuple(25, 0, 0);
Expand Down Expand Up @@ -118,6 +127,10 @@ TEST_F(InfectionsTest, Infections_NoAcuteProgression) {
ON_CALL(*testPerson, GetHCV()).WillByDefault(Return(person::HCV::ACUTE));
ON_CALL(*testPerson, GetTimeSinceHCVChanged()).WillByDefault(Return(5));

// Data Setup
ON_CALL(*event_dm, GetFromConfig("infection.genotype_three_prob", _))
.WillByDefault(DoAll(SetArgReferee<1>("0.5"), Return(0)));

// Incidence Setup
double incidence = 0.0;
Utils::tuple_3i tup_3i = std::make_tuple(25, 0, 0);
Expand Down Expand Up @@ -150,6 +163,10 @@ TEST_F(InfectionsTest, Infections_HandleChronicHCV) {
ON_CALL(*testPerson, GetHCV()).WillByDefault(Return(person::HCV::CHRONIC));
ON_CALL(*testPerson, GetTimeSinceHCVChanged()).WillByDefault(Return(5));

// Data Setup
ON_CALL(*event_dm, GetFromConfig("infection.genotype_three_prob", _))
.WillByDefault(DoAll(SetArgReferee<1>("0.5"), Return(0)));

// Incidence Setup
double incidence = 0.0;
Utils::tuple_3i tup_3i = std::make_tuple(25, 0, 0);
Expand All @@ -168,4 +185,84 @@ TEST_F(InfectionsTest, Infections_HandleChronicHCV) {
std::shared_ptr<event::Event> event =
efactory.create("Infections", event_dm);
event->Execute(testPerson, event_dm, decider);
}
}

TEST_F(InfectionsTest, Infections_NewInfectionGenotype3) {
// Person Setup
ON_CALL(*testPerson, GetAge()).WillByDefault(Return(300));
ON_CALL(*testPerson, GetSex()).WillByDefault(Return(person::Sex::MALE));
ON_CALL(*testPerson, GetBehavior())
.WillByDefault(Return(person::Behavior::NEVER));
ON_CALL(*testPerson, GetHCV()).WillByDefault(Return(person::HCV::NONE));

// Data Setup
ON_CALL(*event_dm, GetFromConfig("infection.genotype_three_prob", _))
.WillByDefault(DoAll(SetArgReferee<1>("0.5"), Return(0)));
std::vector<double> storage = {1.0};
ON_CALL(*event_dm, SelectCustomCallback(INCIDENCE_QUERY, _, _, _))
.WillByDefault(
DoAll(SetArg2ToDoubleCallbackValue(&storage), Return(0)));

// Incidence Setup
double incidence = 1.0;
Utils::tuple_3i tup_3i = std::make_tuple(25, 0, 0);
std::unordered_map<Utils::tuple_3i, double, Utils::key_hash_3i,
Utils::key_equal_3i>
istorage;
istorage[tup_3i] = incidence;
ON_CALL(*event_dm, SelectCustomCallback(INCIDENCE_QUERY, _, _, _))
.WillByDefault(DoAll(SetArg2ToUM_T3I_Double(&istorage), Return(0)));

// Decider Setup
ON_CALL(*decider, GetDecision(_)).WillByDefault(Return(0)); // Infect

// Expectations
EXPECT_CALL(*testPerson, InfectHCV()).Times(1);
EXPECT_CALL(*testPerson, SetGenotypeThree(true)).Times(1);

// Running Test
std::shared_ptr<event::Event> event =
efactory.create("Infections", event_dm);
event->Execute(testPerson, event_dm, decider);
}

TEST_F(InfectionsTest, Infections_NewInfectionNotGenotype3) {
// Person Setup
ON_CALL(*testPerson, GetAge()).WillByDefault(Return(300));
ON_CALL(*testPerson, GetSex()).WillByDefault(Return(person::Sex::MALE));
ON_CALL(*testPerson, GetBehavior())
.WillByDefault(Return(person::Behavior::NEVER));
ON_CALL(*testPerson, GetHCV()).WillByDefault(Return(person::HCV::NONE));

// Data Setup
ON_CALL(*event_dm, GetFromConfig("infection.genotype_three_prob", _))
.WillByDefault(DoAll(SetArgReferee<1>("0.5"), Return(0)));
std::vector<double> storage = {1.0};
ON_CALL(*event_dm, SelectCustomCallback(INCIDENCE_QUERY, _, _, _))
.WillByDefault(
DoAll(SetArg2ToDoubleCallbackValue(&storage), Return(0)));

// Incidence Setup
double incidence = 1.0;
Utils::tuple_3i tup_3i = std::make_tuple(25, 0, 0);
std::unordered_map<Utils::tuple_3i, double, Utils::key_hash_3i,
Utils::key_equal_3i>
istorage;
istorage[tup_3i] = incidence;
ON_CALL(*event_dm, SelectCustomCallback(INCIDENCE_QUERY, _, _, _))
.WillByDefault(DoAll(SetArg2ToUM_T3I_Double(&istorage), Return(0)));

// Decider Setup
EXPECT_CALL(*decider, GetDecision(_))
.WillOnce(Return(0)) // Infect
.WillRepeatedly(Return(1));

// Expectations
EXPECT_CALL(*testPerson, InfectHCV()).Times(1);
EXPECT_CALL(*testPerson, SetGenotypeThree(_)).Times(0);

// Running Test
std::shared_ptr<event::Event> event =
efactory.create("Infections", event_dm);
event->Execute(testPerson, event_dm, decider);
}