def test_set_xalgorithm_algorithm(self): interface = Interface(self.file_handler_xml1) expected_algorithm = "XAlgorithm" interface.config.defaultAlgorithm = expected_algorithm interface._set_algorithm() actual_algorithm = interface.algorithm.__class__.__name__ self.assertEqual(expected_algorithm, actual_algorithm)
def __init__(self, config_file_handler, master=None): """Builds and initializes the GUI as a Interface type if instance. First, the Interface instance attributes are created, additionally the following instance attributes are created: solve_action_set -- Set of methods for the solve menu actions settings_action_set -- Set of methods for the settings menu actions play_action_set -- Set of methods for the play menu actions gui_builder -- Set of methods for building the PAC Sudoku GUI config_file -- XMLFileHandler object with the config file loaded interactive -- Sudokuinteractive initialized as None violation -- Violation flag set to False currently_editing -- Canvas image ID of a square initialized as None timer -- Sudoku timer _timer_increment -- Used to increment by 1 second the timer """ Interface.__init__(self, config_file_handler) self.solve_action_set = SudokuGUISolveActionSet(self) self.settings_action_set = SudokuGUISettingsActionSet(self) self.play_action_set = SudokuGUIPlayActionSet(self) self.gui_builder = SudokuGUIBuilder(self) self.config_file = config_file_handler self.interactive = None self.violation = False self.currently_editing = None self.timer = datetime(1900, 1, 1) self._timer_increment = timedelta(seconds=1) Frame.__init__(self, master) self.pack() self._create_widgets()
def __init__(self, map, population_size, distance_factor, collision_penalty, retain_percentage, random_select_chance, mutate_chance): """ Creates a number of individuals (i.e. a population). map: the map on which the tracks should take place population_size: the number of individuals in the population distance_factor: a weight for the fitness function collision_penalty: fitness function penalty for collisions retain_percentage: how much of the population should be retained during evolution random_select_chance: how many bad individuals should live on anyway mutate_chance: chance for randomly mutating some individuals """ self.map = map self.distance_factor = float(distance_factor) self.collision_penalty = float(collision_penalty) self.retain_percentage = float(retain_percentage) self.random_select_chance = float(random_select_chance) self.mutate_chance = float(mutate_chance) self.tracks = [] # defered import to avoid circular import from main import Interface interface = Interface() population_size = int(population_size) for i in range(population_size): interface.init_msg("Generating population", progress=float(i/population_size), ok=False) self.tracks.append(self.individual())
def test_config_changes_not_saved_returns_true_if_config_empty(self): empty_file = FileHandlerXML("config.xml", 'w') interface = Interface(empty_file) self.assertTrue( interface.config_changes_not_saved(empty_file) ) empty_file.file.close() remove("config.xml")
def __init__(self, config_file_handler): Interface.__init__(self, config_file_handler) self.config_file_handler = config_file_handler self.time = 0 self.recovered_time = 0 self.loaded_game = False self.blank_matrix = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]
def __init__(self): #window = Gtk.Window(Gtk.WindowType.TOPLEVEL) #window.set_title("Video-Player") #window.set_default_size(300, -1) #window.connect("destroy", Gtk.main_quit, "WM destroy") interface = Interface("interfacevideo.glade") time.sleep(5) interface.window1.show_all()
def test_solve_sudoku_returns_false_if_unsupported_algorithm(self): interface = Interface(self.file_handler_xml1) interface.load_sudoku_from_file(self.sudoku_import_txt) interface.config.defaultAlgorithm = "MyAlgorithm" self.assertFalse(interface.solve_sudoku())
def test_solve_sudoku_returns_true_if_solved(self): interface = Interface(self.file_handler_xml1) interface.load_sudoku_from_file(self.sudoku_import_txt) self.assertTrue(interface.solve_sudoku())
def test_update_config_output_type_if_invalid(self): interface = Interface(self.file_handler_xml2) self.assertFalse(interface.update_config_output_type("Network"))
def test_solve_sudoku_returns_false_if_no_matrix_loaded(self): interface = Interface(self.file_handler_xml2) self.assertFalse(interface.solve_sudoku())
def test_export_sudoku_returns_false_if_no_matrix_loaded(self): interface = Interface(self.file_handler_xml2) self.assertFalse(interface.export_sudoku_to_file(self.sudoku_export))
def test_resetting_output_matrix_if_none(self): interface = Interface(self.file_handler_xml2) interface._reset_output_matrix() self.assertEqual(None, interface.output_matrix)
def test_config_changes_not_saved_returns_true_if_config_changed(self): interface = Interface(self.file_handler_xml2) interface.config.defaultAlgorithm = "Norvig" self.assertTrue( interface.config_changes_not_saved(self.file_handler_xml2) )
def test_export_sudoku_returns_true_if_valid_file_path(self): interface = Interface(self.file_handler_xml1) interface.load_sudoku_from_file(self.sudoku_import_csv) interface.solve_sudoku() self.assertTrue(interface.export_sudoku_to_file(self.sudoku_export))
def test_update_config_difficulty_level_if_invalid(self): interface = Interface(self.file_handler_xml2) self.assertFalse(interface.update_config_difficulty_level("Easy"))
def test_save_config_to_file_returns_true_if_valid(self): interface = Interface(self.file_handler_xml1) self.assertTrue(interface.save_config_to_file(self.file_handler_xml1))
def test_update_config_difficulty_level(self): interface = Interface(self.file_handler_xml1) self.assertTrue(interface.update_config_difficulty_level("High"))
def test_update_config_default_algorithm_if_invalid(self): interface = Interface(self.file_handler_xml2) self.assertFalse( interface.update_config_default_algorithm("MyAlgorithm") )
def test_update_config_default_algorithm_norvig(self): interface = Interface(self.file_handler_xml1) self.assertTrue( interface.update_config_default_algorithm("Norvig") )
def test_generate_sudoku_returns_true_if_matrix_generated(self): interface = Interface(self.file_handler_xml1) self.assertTrue(interface.generate_sudoku())
def test_resetting_output_matrix(self): interface = Interface(self.file_handler_xml1) interface.output_matrix = "dummy" interface._reset_output_matrix() self.assertEqual(None, interface.output_matrix)
def test_generate_sudoku_returns_false_if_invalid_algorithm(self): interface = Interface(self.file_handler_xml1) interface.config.defaultAlgorithm = "MyAlgorithm" self.assertFalse(interface.generate_sudoku())
def test_resetting_algorithm_if_none(self): interface = Interface(self.file_handler_xml2) interface._reset_algorithm() self.assertEqual(None, interface.algorithm)
def test_export_sudoku_returns_false_if_invalid_file_path(self): interface = Interface(self.file_handler_xml1) interface.load_sudoku_from_file(self.sudoku_import_csv) interface.solve_sudoku() self.assertFalse(interface.export_sudoku_to_file("/test/no"))
def test_load_sudoku_returns_true_for_valid_matrix_in_txt(self): interface = Interface(self.file_handler_xml2) self.assertTrue( interface.load_sudoku_from_file(self.sudoku_import_txt) )
def test_resetting_algorithm(self): interface = Interface(self.file_handler_xml1) interface.algorithm = "dummy" interface._reset_algorithm() self.assertEqual(None, interface.algorithm)
def test_load_sudoku_returns_false_if_matrix_has_no_valid_format(self): interface = Interface(self.file_handler_xml1) self.assertFalse( interface.load_sudoku_from_file(self.sudoku_import_txt) )
def test_config_changes_not_saved_returns_false_if_config_same(self): interface = Interface(self.file_handler_xml1) self.assertFalse( interface.config_changes_not_saved(self.file_handler_xml1) )
def test_update_config_output_type(self): interface = Interface(self.file_handler_xml1) self.assertTrue(interface.update_config_output_type("File"))