def test_go_and_get_individuals(self): # load random values for the simulation self._load_random_values() # Execute a simulation mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR) mlc.new_experiment("test_go_and_check", MLCWorkspaceTest.ORIGINAL_CONFIGURATION) mlc.open_experiment("test_go_and_check") mlc.go("test_go_and_check", 2) # obtain individuals individuals = mlc.get_individuals("test_go_and_check") # check number of individuals self.assertEqual(len(individuals), 11) # TODO: Check individual values for indiv_id, indiv_data in individuals.items(): self.assertIsInstance(indiv_data, IndividualData) # Test Update Individual Cost in all generations mlc.update_individual_cost("test_go_and_check", 2, 1000, 1001) indiv_data = mlc.get_individuals("test_go_and_check")[2] self.assertEqual(indiv_data.get_appearances(), 2) self.assertEqual(indiv_data.get_cost_history(), {1: [(1000.0, 1001)], 2: [(1000.0, 1001)]}) mlc.close_experiment("test_go_and_check") mlc.delete_experiment("test_go_and_check")
def test_go_and_get_generations(self): try: # load random values for the simulation self._load_random_values() # Execute a simulation mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR) mlc.new_experiment("test_go_and_check", MLCWorkspaceTest.ORIGINAL_CONFIGURATION) mlc.open_experiment("test_go_and_check") mlc.go("test_go_and_check", 2) # get first population first_generation = mlc.get_generation("test_go_and_check", 1) self.assertIsInstance(first_generation, MLCPopulation) # get second generation second_generation = mlc.get_generation("test_go_and_check", 2) self.assertIsInstance(second_generation, MLCPopulation) # third generation does not exist and must raise an Exception # TODO: Use a specific exception instead of IndexError try: third_generation = mlc.get_generation("test_go_and_check", 3) self.assertIsInstance(third_generation, MLCPopulation) self.assertTrue(False) except IndexError: self.assertTrue(True) finally: # FIXME: use Setup/TearDown testcase os.unlink(os.path.join(MLCWorkspaceTest.WORKSPACE_DIR, "test_go_and_check") + ".conf") os.unlink(os.path.join(MLCWorkspaceTest.WORKSPACE_DIR, "test_go_and_check") + ".mlc") pass
def test_go_and_check_simulation_info(self): # load random values for the simulation self._load_random_values() # Execute a simulation mlc = MLCLocal(working_dir=MLCWorkspaceTest.WORKSPACE_DIR) mlc.new_experiment("test_go_and_check", MLCWorkspaceTest.ORIGINAL_CONFIGURATION) mlc.open_experiment("test_go_and_check") mlc.go("test_go_and_check", 2) # check simulation info info = mlc.get_experiment_info("test_go_and_check") self._assert_key_value(info, "name", "test_go_and_check") self._assert_key_value(info, "generations", 2) self._assert_key_value(info, "individuals", 11) self._assert_key_value(info, "individuals_per_generation", 10) mlc.close_experiment("test_go_and_check") mlc.delete_experiment("test_go_and_check")