Esempio n. 1
0
 def setUp(self) -> None:
     logging.basicConfig(
         format='\n%(asctime)s:%(module)s:%(levelname)s:%(message)s',
         level=logging.DEBUG)
     logging.info('Testing population util class.....')
     self.config_util = ConfigUtil('config/test_config.ini')
     self.k = self.config_util.getFloatValue("virus.stats", "k_value")
     self.r = self.config_util.getFloatValue("virus.stats", "r_value")
     self.size = self.config_util.getIntegerValue("area.stats",
                                                  "total_population")
     self.min_age = self.config_util.getIntegerValue(
         "people.stats", "min_age")
     self.max_age = self.config_util.getIntegerValue(
         "people.stats", "min_age")
     self.mortality_rate = self.config_util.getDictionary(
         "virus.stats", "mortality_rate")
     self.social_distance_per = self.config_util.getFloatValue(
         "people.stats", "social_distancing_percent")
     self.infection_range = self.config_util.getFloatValue(
         "virus.stats", "infection_range")
     self.recovery_time = self.config_util.getFloatValue(
         "virus.stats", "recovery_time")
     self.total_healthcare_capacity = self.size * (
         self.config_util.getIntegerValue(
             "area.stats", "healthcare_capacity_ratio") / 100)
     self.mask_effectiveness = self.config_util.getDictionary(
         "virus.stats", "mask_effectiveness")
     self.speed = self.config_util.getFloatValue("people.stats", "speed")
     self.enforce_social_distance_at = self.config_util.getIntegerValue(
         "area.stats", "enforce_social_distancing_at")
     self.enforce_mask_wearing_at = self.config_util.getIntegerValue(
         "area.stats", "enforce_mask_wearing_at")
     self.initialize()
Esempio n. 2
0
 def setUp(self) -> None:
     """
     Setup method initializes an instance of ConfigUtil class
     """
     logging.basicConfig(
         format='\n%(asctime)s:%(module)s:%(levelname)s:%(message)s',
         level=logging.DEBUG)
     logging.info('Testing ConfigUtil class.....')
     self.config_util = ConfigUtil('config/test_config.ini')
Esempio n. 3
0
    def test_support_methods(self):
        """
        Tests the hasConfigData() and loadConfigData() methods to check if they are able to load the config file if valid and indicate failure if file not valid
        """
        self.assertTrue(self.config_util.hasConfigData())
        self.assertTrue(self.config_util.loadConfigData())

        wrong_config = ConfigUtil('config/wrong_file')

        self.assertFalse(wrong_config.hasConfigData())
        self.assertFalse(wrong_config.loadConfigData())
Esempio n. 4
0
 def setUp(self) -> None:
     logging.basicConfig(
         format='\n%(asctime)s:%(module)s:%(levelname)s:%(message)s',
         level=logging.DEBUG)
     logging.info('Testing virus util class.....')
     self.config_util = ConfigUtil('config/test_config.ini')
     self.k = self.config_util.getFloatValue("virus.stats", "k_value")
     self.r = self.config_util.getFloatValue("virus.stats", "r_value")
     self.size = 10
     self.min_age = self.config_util.getIntegerValue(
         "people.stats", "min_age")
     self.max_age = self.config_util.getIntegerValue(
         "people.stats", "min_age")
     self.mortality_rate = self.config_util.getDictionary(
         "virus.stats", "mortality_rate")
     self.social_distance_per = self.config_util.getFloatValue(
         "people.stats", "social_distancing_percent")
     self.infection_range = self.config_util.getFloatValue(
         "virus.stats", "infection_range")
     self.recovery_time = self.config_util.getFloatValue(
         "virus.stats", "recovery_time")
     self.total_healthcare_capacity = self.size * (
         self.config_util.getIntegerValue(
             "area.stats", "healthcare_capacity_ratio") / 100)
     self.mask_effectiveness = self.config_util.getDictionary(
         "virus.stats", "mask_effectiveness")
     self.speed = self.config_util.getFloatValue("people.stats", "speed")
     self.x_bounds = [0, 1]
     self.y_bounds = [0, 1]
     self.population = Population(self.size)
     self.population.initialize_id(0, self.size)
     self.population.initialize_ages(self.min_age, self.max_age, self.size)
     self.population.initialize_positions(self.x_bounds, self.y_bounds,
                                          self.size)
     self.population.initialize_g_value(self.r, 1 / self.k, self.size)
     self.population.initialize_mortality_rate(self.size,
                                               self.mortality_rate)
     self.population.initialize_susceptibility()
     self.virus_util = Virus(1, self.recovery_time,
                             self.total_healthcare_capacity)
     self.population.persons[:, 7] = 1
     self.population.persons[:, 10] = 0.1
     self.population.persons[:, 11] = 0.1
     self.movement = Movement()
    def load_influenza_data(self):
        """
        Method to load config data of the influenza virus
        """
        config_util = ConfigUtil("config/config.ini")

        self.data.k_val.set(
            str(config_util.getFloatValue("influenza.stats", "k_value")))
        self.data.k_value_scale.set(
            config_util.getFloatValue("influenza.stats", "k_value"))

        self.data.r_val.set(
            str(config_util.getFloatValue("influenza.stats", "r_value")))
        self.data.r_value_scale.set(
            config_util.getFloatValue("influenza.stats", "r_value"))

        self.data.recovery_time_val.set(
            str(config_util.getIntegerValue("influenza.stats",
                                            "recovery_time")))
        self.data.recovery_time_scale.set(
            config_util.getIntegerValue("influenza.stats", "recovery_time"))

        mortality_dict = config_util.getDictionary("influenza.stats",
                                                   "mortality_rate")
        self.data.mortality_rate_zero_to_nineteen.set(
            str(mortality_dict["0-19"] * 100) + "%")
        self.data.mortality_rate_twenty_to_fortynine.set(
            str(mortality_dict["20-49"] * 100) + "%")
        self.data.mortality_rate_fifty_to_sixtynine.set(
            str(mortality_dict["50-69"] * 100) + "%")
        self.data.mortality_rate_seventyplus.set(
            str(mortality_dict["70-100"] * 100) + "%")

        mask_dict = config_util.getDictionary("influenza.stats",
                                              "mask_effectiveness")
        self.data.mask_effectiveness_cloth_mask.set(
            str(mask_dict["cloth_mask"]) + "%")
        self.data.mask_effectiveness_surgical_mask.set(
            str(mask_dict["surgery_mask"]) + "%")
        self.data.mask_effectiveness_n95_mask.set(
            str(mask_dict["n95_mask"]) + "%")

        self.update()
 def setUp(self) -> None:
     """
     Setup method initializes all necessary variables from the configuration file and also creates an instance of the Population class
     """
     logging.basicConfig(
         format='\n%(asctime)s:%(module)s:%(levelname)s:%(message)s',
         level=logging.DEBUG)
     logging.info('Testing population class.....')
     self.config_util = ConfigUtil('config/test_config.ini')
     self.k = self.config_util.getFloatValue("virus.stats", "k_value")
     self.r = self.config_util.getFloatValue("virus.stats", "r_value")
     self.size = self.config_util.getIntegerValue("area.stats",
                                                  "total_population")
     self.min_age = self.config_util.getIntegerValue(
         "people.stats", "min_age")
     self.max_age = self.config_util.getIntegerValue(
         "people.stats", "min_age")
     self.mortality_rate = self.config_util.getDictionary(
         "virus.stats", "mortality_rate")
     self.social_distance_per = self.config_util.getFloatValue(
         "people.stats", "social_distancing_percent")
     self.infection_range = self.config_util.getFloatValue(
         "virus.stats", "infection_range")
     self.recovery_time = self.config_util.getFloatValue(
         "virus.stats", "recovery_time")
     self.total_healthcare_capacity = self.size * (
         self.config_util.getIntegerValue(
             "area.stats", "healthcare_capacity_ratio") / 100)
     self.mask_effectiveness = self.config_util.getDictionary(
         "virus.stats", "mask_effectiveness")
     self.speed = self.config_util.getFloatValue("people.stats", "speed")
     self.enforce_social_distance_at = self.config_util.getIntegerValue(
         "area.stats", "enforce_social_distancing_at")
     self.enforce_mask_wearing_at = self.config_util.getIntegerValue(
         "area.stats", "enforce_mask_wearing_at")
     self.x_bounds = [0, 1]
     self.y_bounds = [0, 1]
     self.population = Population(self.size)
Esempio n. 7
0
class PopulationUtilClassTest(unittest.TestCase):
    """
    Test cases to test the granular functionality of Population util class
    """
    def setUp(self) -> None:
        logging.basicConfig(
            format='\n%(asctime)s:%(module)s:%(levelname)s:%(message)s',
            level=logging.DEBUG)
        logging.info('Testing population util class.....')
        self.config_util = ConfigUtil('config/test_config.ini')
        self.k = self.config_util.getFloatValue("virus.stats", "k_value")
        self.r = self.config_util.getFloatValue("virus.stats", "r_value")
        self.size = self.config_util.getIntegerValue("area.stats",
                                                     "total_population")
        self.min_age = self.config_util.getIntegerValue(
            "people.stats", "min_age")
        self.max_age = self.config_util.getIntegerValue(
            "people.stats", "min_age")
        self.mortality_rate = self.config_util.getDictionary(
            "virus.stats", "mortality_rate")
        self.social_distance_per = self.config_util.getFloatValue(
            "people.stats", "social_distancing_percent")
        self.infection_range = self.config_util.getFloatValue(
            "virus.stats", "infection_range")
        self.recovery_time = self.config_util.getFloatValue(
            "virus.stats", "recovery_time")
        self.total_healthcare_capacity = self.size * (
            self.config_util.getIntegerValue(
                "area.stats", "healthcare_capacity_ratio") / 100)
        self.mask_effectiveness = self.config_util.getDictionary(
            "virus.stats", "mask_effectiveness")
        self.speed = self.config_util.getFloatValue("people.stats", "speed")
        self.enforce_social_distance_at = self.config_util.getIntegerValue(
            "area.stats", "enforce_social_distancing_at")
        self.enforce_mask_wearing_at = self.config_util.getIntegerValue(
            "area.stats", "enforce_mask_wearing_at")
        self.initialize()

    def initialize(self) -> None:
        """
        Initializes the population util class with the appropriate parameters
        """
        self.population_util = PopulationUtil(
            k=self.k,
            r=self.r,
            min_age=self.min_age,
            max_age=self.max_age,
            size=self.size,
            mortality_rate=self.mortality_rate,
            infection_range=self.infection_range,
            recovery_time=self.recovery_time,
            total_healthcare_capacity=self.total_healthcare_capacity,
            social_distance_per=self.social_distance_per,
            mask_effectiveness=self.mask_effectiveness,
            speed=self.speed,
            social_distancing_at=self.enforce_social_distance_at,
            mask_wearing_at=self.enforce_mask_wearing_at)

    def test_move(self):
        """
        Tests the move() method to check if the position of the persons is changing according to the configurations
        """

        try:
            x_axis_before = list(self.population_util.population.get_x_axis())
            y_axis_before = list(self.population_util.population.get_y_axis())
            self.population_util.move(1)
            x_axis_after = list(self.population_util.population.get_x_axis())
            y_axis_after = list(self.population_util.population.get_y_axis())
            if functools.reduce(
                    lambda x, y: x and y,
                    map(lambda p, q: p == q, x_axis_before, x_axis_after),
                    True):
                self.assertTrue(False,
                                "Test failed, x axis values did not change")
            else:
                self.assertTrue(True, "Test passed, x axis values changed")

            if functools.reduce(
                    lambda x, y: x and y,
                    map(lambda p, q: p == q, y_axis_before, y_axis_after),
                    True):
                self.assertTrue(False,
                                "Test failed, y axis values did not change")
            else:
                self.assertTrue(True, "Test passed, y axis values changed")
        except Exception as e:
            self.assertTrue(False, 'Test failed')
            logging.error('Error occured ' + e)
Esempio n. 8
0
class VirusUtilTest(unittest.TestCase):
    """
    Test case to test the Virus class
    """
    def setUp(self) -> None:
        logging.basicConfig(
            format='\n%(asctime)s:%(module)s:%(levelname)s:%(message)s',
            level=logging.DEBUG)
        logging.info('Testing virus util class.....')
        self.config_util = ConfigUtil('config/test_config.ini')
        self.k = self.config_util.getFloatValue("virus.stats", "k_value")
        self.r = self.config_util.getFloatValue("virus.stats", "r_value")
        self.size = 10
        self.min_age = self.config_util.getIntegerValue(
            "people.stats", "min_age")
        self.max_age = self.config_util.getIntegerValue(
            "people.stats", "min_age")
        self.mortality_rate = self.config_util.getDictionary(
            "virus.stats", "mortality_rate")
        self.social_distance_per = self.config_util.getFloatValue(
            "people.stats", "social_distancing_percent")
        self.infection_range = self.config_util.getFloatValue(
            "virus.stats", "infection_range")
        self.recovery_time = self.config_util.getFloatValue(
            "virus.stats", "recovery_time")
        self.total_healthcare_capacity = self.size * (
            self.config_util.getIntegerValue(
                "area.stats", "healthcare_capacity_ratio") / 100)
        self.mask_effectiveness = self.config_util.getDictionary(
            "virus.stats", "mask_effectiveness")
        self.speed = self.config_util.getFloatValue("people.stats", "speed")
        self.x_bounds = [0, 1]
        self.y_bounds = [0, 1]
        self.population = Population(self.size)
        self.population.initialize_id(0, self.size)
        self.population.initialize_ages(self.min_age, self.max_age, self.size)
        self.population.initialize_positions(self.x_bounds, self.y_bounds,
                                             self.size)
        self.population.initialize_g_value(self.r, 1 / self.k, self.size)
        self.population.initialize_mortality_rate(self.size,
                                                  self.mortality_rate)
        self.population.initialize_susceptibility()
        self.virus_util = Virus(1, self.recovery_time,
                                self.total_healthcare_capacity)
        self.population.persons[:, 7] = 1
        self.population.persons[:, 10] = 0.1
        self.population.persons[:, 11] = 0.1
        self.movement = Movement()

    def test_infect(self):
        """
        Test to test the infect() method; compares the number of infected people before and after calling the infect method to see if healthy people within the infection range get infected
        """
        before_infect_population = self.population.get_all_infected()
        self.population.persons = self.movement.update_persons(
            self.population.persons, self.size, self.speed, 1)
        self.infected_person = np.random.randint(0, self.size)
        self.population.persons[self.infected_person, index.g_value] = 3
        self.population.set_infected_at(1, 0)
        self.population.persons[self.infected_person,
                                index.social_distance] = 0
        self.population.persons[self.infected_person, 9] = 1
        _xbounds = np.array([[0, 1]] * self.size)
        _ybounds = np.array([[0, 1]] * self.size)

        for i in range(1, self.size):
            self.population.persons = self.movement.out_of_bounds(
                self.population.persons, _xbounds, _ybounds)

            self.population.persons = self.movement.update_persons(
                self.population.persons, self.size, self.speed, 1)

            self.population.persons = self.movement.update_pop(
                self.population.persons)

            self.population = self.virus_util.infect(self.population, i)

        self.assertTrue(
            len(before_infect_population[:, 9]) != len(
                self.population.get_all_infected()[:, 9])
            and len(self.population.get_all_infected()[:, 9]) > 1,
            "Test failed, infect did not work")

    def test_die_or_immune(self):
        """
        Test case to test the die_or_immune() method; check if the people passing the recovery time die or recover according to their mortality rate chance
        """
        dead_frame_1 = self.population.get_all_dead()
        self.assertEqual(len(dead_frame_1), 0)

        self.population.persons = self.movement.update_persons(
            self.population.persons, self.size, self.speed, 1)
        self.infected_person = np.random.randint(0, self.size)
        self.population.persons[self.infected_person, index.g_value] = 3
        self.population.set_infected_at(1, 0)
        self.population.persons[self.infected_person,
                                index.social_distance] = 0
        self.population.persons[self.infected_person, 9] = 1
        _xbounds = np.array([[0, 1]] * self.size)
        _ybounds = np.array([[0, 1]] * self.size)

        for i in range(1, self.size):
            self.population.persons = self.movement.out_of_bounds(
                self.population.persons, _xbounds, _ybounds)

            self.population.persons = self.movement.update_persons(
                self.population.persons, self.size, self.speed, 1)

            self.population.persons = self.movement.update_pop(
                self.population.persons)

            self.population = self.virus_util.infect(self.population, i)
        self.population.persons[:, index.mortality_rate] = 1.00
        self.virus_util.die_or_immune(
            self.population, int(self.population.get_all_infected()[0][0]))
        self.assertNotEqual(len(self.population.get_all_dead()), 0)
Esempio n. 9
0
class Main(object):
    """
    Main class to execute it all
    """
    def __init__(self) -> None:
        """
        Constructor to initialize a configUtil object
        """
        self.config_util = ConfigUtil("config/config.ini")

    def load_config(self) -> None:
        """
        Method to load config
        """
        self.k = self.config_util.getFloatValue("covid.stats", "k_value")
        self.r = self.config_util.getFloatValue("covid.stats", "r_value")
        self.size = self.config_util.getIntegerValue("area.stats",
                                                     "total_population")
        self.min_age = self.config_util.getIntegerValue(
            "people.stats", "min_age")
        self.max_age = self.config_util.getIntegerValue(
            "people.stats", "max_age")
        self.mortality_rate = self.config_util.getDictionary(
            "covid.stats", "mortality_rate")
        self.social_distance_per = self.config_util.getFloatValue(
            "people.stats", "social_distancing_percent")
        self.infection_range = self.config_util.getFloatValue(
            "covid.stats", "infection_range")
        self.recovery_time = self.config_util.getFloatValue(
            "covid.stats", "recovery_time")
        self.total_healthcare_capacity = self.size * (
            self.config_util.getIntegerValue(
                "area.stats", "healthcare_capacity_ratio") / 100)
        self.mask_effectiveness = self.config_util.getDictionary(
            "covid.stats", "mask_effectiveness")
        self.speed = self.config_util.getFloatValue("people.stats", "speed")
        self.enforce_social_distance_at = self.config_util.getIntegerValue(
            "area.stats", "enforce_social_distancing_at")
        self.enforce_mask_wearing_at = self.config_util.getIntegerValue(
            "area.stats", "enforce_mask_wearing_at")

    def runNoUI(self) -> None:
        """
        Function to run with NO UI, loads everyting from config file
        """
        print("Running with no UI, loading data from the config file")
        self.load_config()
        self.population_util = PopulationUtil(
            k=self.k,
            r=self.r,
            min_age=self.min_age,
            max_age=self.max_age,
            size=self.size,
            mortality_rate=self.mortality_rate,
            infection_range=self.infection_range,
            recovery_time=self.recovery_time,
            total_healthcare_capacity=self.total_healthcare_capacity,
            social_distance_per=self.social_distance_per,
            mask_effectiveness=self.mask_effectiveness,
            speed=self.speed,
            social_distancing_at=self.enforce_social_distance_at,
            mask_wearing_at=self.enforce_mask_wearing_at)
        self.visualize = Visualization(self.population_util, render_mode=False)

    def render(self, path: str) -> None:
        """
        Function to directly render without showing ANY UI
        """
        print("Rendering to " + path)
        self.load_config()
        self.population_util = PopulationUtil(
            k=self.k,
            r=self.r,
            min_age=self.min_age,
            max_age=self.max_age,
            size=self.size,
            mortality_rate=self.mortality_rate,
            infection_range=self.infection_range,
            recovery_time=self.recovery_time,
            total_healthcare_capacity=self.total_healthcare_capacity,
            social_distance_per=self.social_distance_per,
            mask_effectiveness=self.mask_effectiveness,
            speed=self.speed,
            social_distancing_at=self.enforce_social_distance_at,
            mask_wearing_at=self.enforce_mask_wearing_at)
        Visualization(self.population_util, render_mode=True, render_path=path)

    def runUI(self) -> None:
        """
        Function to execute helper UI
        """
        main()
Esempio n. 10
0
 def __init__(self) -> None:
     """
     Constructor to initialize a configUtil object
     """
     self.config_util = ConfigUtil("config/config.ini")
    def start(self):
        """
        Starts the simulation with the requested configuration;
        Updates the top level window with the simulation in live mode, generates the video file of the simulation in render mode;
        """

        config_util = ConfigUtil("config/config.ini")
        if self.data.render_dir == None and self.simulation_mode.get() == 1:
            self.start_sim_button["text"] = "Please select a directory"
            return

        if self.simulation_mode.get() == 1:
            self.start_sim_button["text"] = "Rendering. Please Wait"

        self.update()

        k = self.data.get_k_val()
        r = self.data.get_r_val()
        size = self.data.get_population_val()
        min_age = config_util.getIntegerValue("people.stats", "min_age")
        max_age = config_util.getIntegerValue("people.stats", "max_age")
        mortality = self.data.get_all_mortality_rates()
        social_dist_per = self.data.get_social_distancing_val() / 100
        infection_range = self.data.get_infection_range_val()
        recovery_time = self.data.get_recovery_time_val()
        health_cap = int(size * self.data.get_hospital_capacity_val() / 100)
        mask_effect = self.data.get_all_mask_effectiveness()
        speed = config_util.getFloatValue("people.stats", "speed")

        if self.social_distance_enable.get() == 0:
            enforce_social_distance_at = -1
        else:
            enforce_social_distance_at = self.data.get_social_distancing_starting_at_val(
            )

        if self.mask_wearing_enable.get() == 0:
            enforce_masks_at = -1
        else:
            enforce_masks_at = self.data.get_mask_mandate_starting_at_val()

        p_util = PopulationUtil(
            r=r,
            k=k,
            size=size,
            min_age=min_age,
            max_age=max_age,
            mortality_rate=mortality,
            infection_range=infection_range,
            recovery_time=recovery_time,
            total_healthcare_capacity=health_cap,
            mask_effectiveness=mask_effect,
            speed=speed,
            social_distance_per=social_dist_per,
            social_distancing_at=enforce_social_distance_at,
            mask_wearing_at=enforce_masks_at)

        if self.simulation_mode.get() == 2:
            self.newWindow.destroy()
            Visualization(p_util, render_mode=False)

        if self.simulation_mode.get() == 1:
            Visualization(p_util,
                          render_mode=True,
                          render_path=self.data.render_dir)
            self.start_sim_button["text"] = "Done Rendering."
class PopulationClassTest(unittest.TestCase):
    """
    Test cases to test the granular functionality of Population class
    """
    def setUp(self) -> None:
        """
        Setup method initializes all necessary variables from the configuration file and also creates an instance of the Population class
        """
        logging.basicConfig(
            format='\n%(asctime)s:%(module)s:%(levelname)s:%(message)s',
            level=logging.DEBUG)
        logging.info('Testing population class.....')
        self.config_util = ConfigUtil('config/test_config.ini')
        self.k = self.config_util.getFloatValue("virus.stats", "k_value")
        self.r = self.config_util.getFloatValue("virus.stats", "r_value")
        self.size = self.config_util.getIntegerValue("area.stats",
                                                     "total_population")
        self.min_age = self.config_util.getIntegerValue(
            "people.stats", "min_age")
        self.max_age = self.config_util.getIntegerValue(
            "people.stats", "min_age")
        self.mortality_rate = self.config_util.getDictionary(
            "virus.stats", "mortality_rate")
        self.social_distance_per = self.config_util.getFloatValue(
            "people.stats", "social_distancing_percent")
        self.infection_range = self.config_util.getFloatValue(
            "virus.stats", "infection_range")
        self.recovery_time = self.config_util.getFloatValue(
            "virus.stats", "recovery_time")
        self.total_healthcare_capacity = self.size * (
            self.config_util.getIntegerValue(
                "area.stats", "healthcare_capacity_ratio") / 100)
        self.mask_effectiveness = self.config_util.getDictionary(
            "virus.stats", "mask_effectiveness")
        self.speed = self.config_util.getFloatValue("people.stats", "speed")
        self.enforce_social_distance_at = self.config_util.getIntegerValue(
            "area.stats", "enforce_social_distancing_at")
        self.enforce_mask_wearing_at = self.config_util.getIntegerValue(
            "area.stats", "enforce_mask_wearing_at")
        self.x_bounds = [0, 1]
        self.y_bounds = [0, 1]
        self.population = Population(self.size)

    def initialize(self):
        """
        Method Calls all the initialize functions from the Population class
        """
        self.population.initialize_id(0, self.size)
        self.population.initialize_ages(self.min_age, self.max_age, self.size)
        self.population.initialize_positions(self.x_bounds, self.y_bounds,
                                             self.size)
        self.population.initialize_g_value(self.r, 1 / self.k, self.size)
        self.population.initialize_mortality_rate(self.size,
                                                  self.mortality_rate)
        self.population.initialize_mask_eff(self.size, self.mask_effectiveness)
        self.population.initialize_social_distancing(self.social_distance_per)
        self.population.initialize_susceptibility()

    def tearDown(self) -> None:
        pass

    def test_get_people(self):
        """
        Test to check if the population has been created of a correct size as provided by the config file
        """
        assert isinstance(self.population.get_person(), np.ndarray)
        self.assertEqual(self.size, self.population.get_person()[:, 0].size)

    def test_get_all_infected(self):
        """
        Test to check if people returned by get_all_infected() are within the infection range of the infected person and are actually infected
        """
        persons = self.population.get_person()

        # Test if get_all_infected returns indices of all people infected
        self.assertEqual(persons[persons[:, 9] == 1].size,
                         self.population.get_all_infected().size)

    def test_get_all_healthy(self):
        """
        Test to check if the people at indices returned by get_all_healthy() are returned correctly; only healthy people are returned
        """
        persons = self.population.get_person()

        # Test if get_all_healthy returns indices of all people healthy
        self.assertEqual(persons[persons[:, 9] == 0].size,
                         self.population.get_all_healthy().size)

    def test_get_all_recovered(self):
        """
        Test to check if the people returned by get_all_recovered() are returned correctly; only recovered people are returned
        """
        persons = self.population.get_person()

        # Test if get_all_recovered returns indices of all people who recovered
        self.assertEqual(persons[persons[:, 9] == 2].size,
                         self.population.get_all_recovered().size)

    def test_get_all_dead(self):
        """
        Test to check if the people returned by get_all_dead() are returned correctly; only columns of dead people are returned
        """
        persons = self.population.get_person()

        # Test if get_all_dead returns indices of all people dead
        self.assertEqual(persons[persons[:, 9] == 3].size,
                         self.population.get_all_dead().size)

    def test_get_currently_active(self):
        """
        Test to check if get_currently_active() returns correct information about the current population; people currently moving towards their destination are returned
        """
        for i in self.population.get_currently_active_info():
            if int(i) != 0 and int(i) != 1:
                self.assertTrue(False,
                                "Array contains values other than 0 and 1")
        self.assertTrue(True, "Array contains either 0 or 1")
Esempio n. 13
0
class ConfigUtilClassTest(unittest.TestCase):
    """
    Test cases to test the methods of the ConfigUtil class
    """
    def setUp(self) -> None:
        """
        Setup method initializes an instance of ConfigUtil class
        """
        logging.basicConfig(
            format='\n%(asctime)s:%(module)s:%(levelname)s:%(message)s',
            level=logging.DEBUG)
        logging.info('Testing ConfigUtil class.....')
        self.config_util = ConfigUtil('config/test_config.ini')

    def test_get_value(self):
        """
        Tests the getValue() method to see if the method is able to obtain the String value from the config file using the section and key given
        """
        self.assertIsInstance(
            self.config_util.getValue("virus.stats", "k_value"), str)
        self.assertEqual(self.config_util.getValue("virus.stats", "k_value"),
                         str(0.1))

    def test_get_integer(self):
        """
        Tests the getIntegerValue() method to see if the method is able to obtain the int value from the config file using the section and key given
        """
        self.assertIsInstance(
            self.config_util.getIntegerValue("virus.stats", "r_value"), int)
        self.assertEqual(
            self.config_util.getIntegerValue("virus.stats", "r_value"), 3)

    def test_get_float(self):
        """
        Tests the getFloatValue() method to see if the method is able to obtain the float value from the config file using the section and key given
        """
        self.assertIsInstance(
            self.config_util.getFloatValue("virus.stats", "r_value"), float)
        self.assertEqual(
            self.config_util.getFloatValue("virus.stats", "k_value"), 0.1)

    def test_get_dictionary(self):
        """
        Tests the getDictionary method to see if the method is able to obtain the json string from the config file and convert it to dictionary type using the section and key given
        """
        self.assertIsInstance(
            self.config_util.getDictionary("virus.stats", "mortality_rate"),
            dict)
        self.assertEqual(
            self.config_util.getDictionary("virus.stats", "mortality_rate"),
            json.loads(
                self.config_util.getValue("virus.stats", "mortality_rate")))

    def test_get_boolean(self):
        """
        Tests the getBooleanValue() method to see if the method is able to obtain the boolean value from the config file using the section and key given
        """
        self.assertIsInstance(
            self.config_util.getBooleanValue("people.stats", "use_masks"),
            bool)
        self.assertEqual(
            self.config_util.getBooleanValue("people.stats", "use_masks"),
            True)

    def test_support_methods(self):
        """
        Tests the hasConfigData() and loadConfigData() methods to check if they are able to load the config file if valid and indicate failure if file not valid
        """
        self.assertTrue(self.config_util.hasConfigData())
        self.assertTrue(self.config_util.loadConfigData())

        wrong_config = ConfigUtil('config/wrong_file')

        self.assertFalse(wrong_config.hasConfigData())
        self.assertFalse(wrong_config.loadConfigData())