class Program: def __init__(self): self.__ui_manager = CommandUI() self.__DEBUGGING_MODE = True self.__function = Function() def change_ui(self): if not self.__ui_manager.switch(): return if self.__ui_manager.TYPE == constants.TYPE_COMMAND: self.__ui_manager = MenuUI() print("Changed to menu based UI") else: self.__ui_manager = CommandUI() print("Changed to command based UI") def start(self): if self.__DEBUGGING_MODE: run_tests() self.__function.preload_list() self.change_ui() self.__ui_manager.show_help() while True: action = self.__ui_manager.get_action() try: if action.type == constants.ACTION_ADD: result = self.__function.add(action.params) self.__ui_manager.print_result(result) elif action.type == constants.ACTION_CHANGE_UI: self.change_ui() elif action.type == constants.ACTION_ERROR: self.__ui_manager.on_invalid_command() elif action.type == constants.ACTION_EXIT: return elif action.type == constants.ACTION_FILTER_CATEGORY: result = self.__function.filter_category(action.params) self.__ui_manager.print_result(result) elif action.type == constants.ACTION_FILTER_CATEGORY_CONDITION: result = self.__function.filter_category_condition( action.params) self.__ui_manager.print_result(result) elif action.type == constants.ACTION_HELP: self.__ui_manager.show_help() elif action.type == constants.ACTION_INSERT: result = self.__function.insert(action.params) self.__ui_manager.print_result(result) elif action.type == constants.ACTION_LIST_ALL: result = self.__function.list_all() self.__ui_manager.print_result(result) elif action.type == constants.ACTION_LIST_CATEGORY: result = self.__function.list_category(action.params) self.__ui_manager.print_result(result) elif action.type == constants.ACTION_LIST_CATEGORY_CONDITION: result = self.__function.list_category_condition( action.params) self.__ui_manager.print_result(result) elif action.type == constants.ACTION_MAX_DAY: result = self.__function.max_day(action.params) self.__ui_manager.print_result(result) elif action.type == constants.ACTION_REMOVE_CATEGORY: result = self.__function.remove_category(action.params) self.__ui_manager.print_result(result) elif action.type == constants.ACTION_REMOVE_DAY: result = self.__function.remove_day(action.params) self.__ui_manager.print_result(result) elif action.type == constants.ACTION_REMOVE_RANGE: result = self.__function.remove_range(action.params) self.__ui_manager.print_result(result) elif action.type == constants.ACTION_SORT_CATEGORY: result = self.__function.sort_category(action.params) self.__ui_manager.print_result(result) elif action.type == constants.ACTION_SORT_DAY: result = self.__function.sort_day(action.params) self.__ui_manager.print_result(result) elif action.type == constants.ACTION_SUM_CATEGORY: result = self.__function.sum_category(action.params) self.__ui_manager.print_result(result) elif action.type == constants.ACTION_UNDO: result = self.__function.undo_last_action() self.__ui_manager.print_result(result) except ValidationError as error: self.__ui_manager.handle_error(error)
def run_remove_range_test(): expenses = [] function = Function(expenses) function.insert(["26", "4", constants.CATEGORY_INTERNET]) assert len(expenses) == 1 try: function.remove_range(["", "", ""]) assert False except ValidationError: assert True assert len(expenses) == 1 try: function.remove_range(["abc", "", "abc"]) assert False except ValidationError: assert True assert len(expenses) == 1 try: function.remove_range(["0", "", "abc"]) assert False except ValidationError: assert True assert len(expenses) == 1 try: function.remove_range(["32", "", "abc"]) assert False except ValidationError: assert True assert len(expenses) == 1 try: function.remove_range(["1", "", "abc"]) assert False except ValidationError: assert True assert len(expenses) == 1 try: function.remove_range(["31", "", "0"]) assert False except ValidationError: assert True assert len(expenses) == 1 try: function.remove_range(["2", "", "32"]) assert False except ValidationError: assert True assert len(expenses) == 1 try: function.remove_range(["30", "", "3"]) assert False except ValidationError: assert True assert len(expenses) == 1 function.remove_range(["1", "", "10"]) assert len(expenses) == 1 function.remove_range(["10", "to", "20"]) assert len(expenses) == 1 function.remove_range(["1", "to", "20"]) assert len(expenses) == 1 function.remove_range(["21", "to", "26"]) assert len(expenses) == 0 function.remove_range(["1", "", "31"]) assert len(expenses) == 0