def test_createInfectedPersonsByHouseHoldBestEffort2(): """ Test that when the population size is less then the amount of people that had been chosen to be infected by households, the simulation doesn't crash """ config_path = os.path.join(os.path.dirname(__file__),"..","src","config.json") 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) #create diff enviroments KidsHouse = Household(city = None,contact_prob_between_each_two_people=1) AdultsHouse = Household(city = None,contact_prob_between_each_two_people=1) MixedHouse = Household(city = None,contact_prob_between_each_two_people=1) kidsAges = [random.randint(0,17) for i in range(4)] adultsAges = [random.randint(19,40) for i in range(3)] KidsLst = list(map(Person, kidsAges)) adultsLst = list(map(Person, adultsAges)) persons_arr = KidsLst + adultsLst #register people to diff env KidsHouse.sign_up_for_today(KidsLst[0],1) KidsHouse.sign_up_for_today(KidsLst[1],1) AdultsHouse.sign_up_for_today(adultsLst[0],1) AdultsHouse.sign_up_for_today(adultsLst[1],1) MixedHouse.sign_up_for_today(adultsLst[2],1) MixedHouse.sign_up_for_today(KidsLst[2],1) MixedHouse.sign_up_for_today(KidsLst[3],1) assert len(KidsHouse.get_people()) == 2 assert len(AdultsHouse.get_people()) == 2 assert len(MixedHouse.get_people()) == 3 env_arr = [KidsHouse,AdultsHouse,MixedHouse] my_world = World( all_people = persons_arr, all_environments=env_arr, generating_city_name = "test", generating_scale = 1,) my_simulation = Simulation(world = my_world, initial_date= INITIAL_DATE) my_simulation.immune_households_infect_others(num_infected = 0, infection_doc = "", per_to_immune = 2 ,city_name = None,min_age=18,people_per_day =5) my_simulation.simulate_day() cnt_immune = 0 cnt_sick = 0 for person in my_world.all_people(): if person.get_disease_state() == DiseaseState.IMMUNE: cnt_immune += 1 elif person.get_disease_state() != DiseaseState.SUSCEPTIBLE: cnt_sick += 1 assert cnt_immune == 3 assert cnt_sick == 0
def test_createImmunehouseholds4(): config_path = os.path.join(os.path.dirname(__file__),"..","src","config.json") 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) #create diff enviroments KidsHouse = Household(city = None,contact_prob_between_each_two_people=1) AdultsHouse = Household(city = None,contact_prob_between_each_two_people=1) MixedHouse = Household(city = None,contact_prob_between_each_two_people=1) kidsAges = [random.randint(0,17) for i in range(4)] adultsAges = [random.randint(19,40) for i in range(3)] KidsLst = list(map(Person, kidsAges)) adultsLst = list(map(Person, adultsAges)) persons_arr = KidsLst + adultsLst #register people to diff env KidsHouse.sign_up_for_today(KidsLst[0],1) KidsHouse.sign_up_for_today(KidsLst[1],1) AdultsHouse.sign_up_for_today(adultsLst[0],1) AdultsHouse.sign_up_for_today(adultsLst[1],1) MixedHouse.sign_up_for_today(adultsLst[2],1) MixedHouse.sign_up_for_today(KidsLst[2],1) MixedHouse.sign_up_for_today(KidsLst[3],1) assert len(KidsHouse.get_people()) == 2 assert len(AdultsHouse.get_people()) == 2 assert len(MixedHouse.get_people()) == 3 env_arr = [KidsHouse,AdultsHouse,MixedHouse] my_world = World( all_people = persons_arr, all_environments=env_arr, generating_city_name = "test", generating_scale = 1,) my_simulation = Simulation(world = my_world, initial_date= INITIAL_DATE) my_simulation.immune_households_infect_others(num_infected = 0, infection_doc = "", per_to_immune = 1,Immune_compliance= 0 ,city_name = None,min_age=18,people_per_day= 3 ) my_simulation.simulate_day() #assert events dictionary is not empty 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 == 0
def test_createImmunehouseholds2(): config_path = os.path.join(os.path.dirname(__file__),"..","src","config.json") 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) #create diff enviroments house1 = Household(city = None,contact_prob_between_each_two_people=1) house2 = Household(city = None,contact_prob_between_each_two_people=1) house1Ages = [98,93,5] house2Ages = [94,6] house1Lst = list(map(Person, house1Ages)) house2Lst = list(map(Person, house2Ages)) persons_arr = house1Lst + house2Lst #register people to diff env house1.sign_up_for_today(house1Lst[0],1) house1.sign_up_for_today(house1Lst[1],1) house1.sign_up_for_today(house1Lst[2],1) house2.sign_up_for_today(house2Lst[0],1) house2.sign_up_for_today(house2Lst[1],1) assert len(house1.get_people()) == 3 assert len(house2.get_people()) == 2 env_arr = [house1,house2] my_world = World( all_people = persons_arr, all_environments=env_arr, generating_city_name = "test", generating_scale = 1,) my_simulation = Simulation(world = my_world, initial_date= INITIAL_DATE) my_simulation.immune_households_infect_others(num_infected = 0, infection_doc = "", per_to_immune = 0.6,Sort_order=ORDER.DESCENDING ,city_name = None,min_age=18,people_per_day= 3 ) my_simulation.simulate_day() #assert events dictionary is not empty cnt_immune = 0 for person in my_world.all_people(): if (person.get_age() in [94,93,98]) and (person.get_disease_state() == DiseaseState.IMMUNE): cnt_immune = cnt_immune + 1 assert cnt_immune == 3