def test_immune_and_get_events2(): config_path = os.path.join(os.path.dirname(__file__), "..", "src", "config.json") Expected = -1 with open(config_path) as json_data_file: ConfigData = json.load(json_data_file) paramsDataPath = ConfigData['ParamsFilePath'] Params.load_from(os.path.join(os.path.dirname(__file__), "..", "src", paramsDataPath), override=True) p = Person(30) ok,events = p.immune_and_get_events(INITIAL_DATE , timedelta(days = 20), \ ((DiseaseState.SUSCEPTIBLE,timedelta(10)),(DiseaseState.LATENT,timedelta(5)), \ (DiseaseState.SUSCEPTIBLE,None))) assert len(events) == 3 assert ok persons_arr = [p] env_arr = [] small_world = world.World(all_people=persons_arr, all_environments=env_arr, generating_city_name="test", generating_scale=1) my_simulation = Simulation(world=small_world, initial_date=INITIAL_DATE, interventions=[]) for i in range(10): my_simulation.simulate_day() events[0].apply(simulation=my_simulation) assert p.get_disease_state() == DiseaseState.LATENT for i in range(5): my_simulation.simulate_day() events[1].apply(simulation=my_simulation) assert p.get_disease_state() == DiseaseState.IMMUNE
def test_createInfectedPersonsOredredASCENDING(): config_path = os.path.join(os.path.dirname(__file__),"..","src","config.json") Expected = -1 with open(config_path) as json_data_file: ConfigData = json.load(json_data_file) paramsDataPath = ConfigData['ParamsFilePath'] Params.load_from(os.path.join(os.path.dirname(__file__),"..","src", paramsDataPath), override=True) kids = [0,4,8,12,16] adults = [25,29,33] ageList = kids + adults youngest = Person(21) Oldest = Person(37) PersonList = list(map(Person, ageList)) PersonList = PersonList + [youngest , Oldest] env_arr = [] my_world = World( all_people = PersonList, all_environments=env_arr, generating_city_name = "test", generating_scale = 1) my_simulation = Simulation(world = my_world, initial_date= INITIAL_DATE) my_simulation.infect_random_set(num_infected = 0, infection_doc = "", per_to_immune = 0.5,order= ORDER.ASCENDING,city_name = None,min_age=18,people_per_day =1) my_simulation.simulate_day() assert youngest.get_disease_state() == DiseaseState.IMMUNE #Can't check day by day lots of noise with seir times for _ in range(4): my_simulation.simulate_day() cnt_immune =0 for person in my_world.all_people(): if person.get_disease_state() == DiseaseState.IMMUNE: cnt_immune = cnt_immune + 1 assert cnt_immune <= 5
def test_immune_and_get_events5(): """ Test that a person that is not Susptible nor latent when he should get immuned continues his usual path to his death """ config_path = os.path.join(os.path.dirname(__file__), "..", "src", "config.json") Expected = -1 with open(config_path) as json_data_file: ConfigData = json.load(json_data_file) paramsDataPath = ConfigData['ParamsFilePath'] Params.load_from(os.path.join(os.path.dirname(__file__), "..", "src", paramsDataPath), override=True) p = Person(30) ok, events = p.immune_and_get_events(INITIAL_DATE , timedelta(days = 20), \ ((DiseaseState.SUSCEPTIBLE,timedelta(10)),(DiseaseState.LATENT,timedelta(5)),\ (DiseaseState.ASYMPTOMATICINFECTIOUS,timedelta(5)),(DiseaseState.DECEASED,timedelta(5)),(DiseaseState.DECEASED,None))) assert len(events) == 4 assert ok == False persons_arr = [p] env_arr = [] small_world = world.World(all_people=persons_arr, all_environments=env_arr, generating_city_name="test", generating_scale=1) my_simulation = Simulation(world=small_world, initial_date=INITIAL_DATE, interventions=[]) for i in range(10): my_simulation.simulate_day() events[0].apply(simulation=my_simulation) assert p.get_disease_state() == DiseaseState.LATENT for i in range(5): my_simulation.simulate_day() events[1].apply(simulation=my_simulation) assert p.get_disease_state() == DiseaseState.ASYMPTOMATICINFECTIOUS #Because this person was not susptible nor latent he cannot be immuned for i in range(5): my_simulation.simulate_day() events[2].apply(simulation=my_simulation) assert p.get_disease_state() == DiseaseState.DECEASED