Пример #1
0
def start():
    """
    Start application function
    get and process data from user and put them into list
    compare and sort triangulars by square
    print triangulars
    :return: None
    """

    triangular_list = []
    input_triang_flag = True
    while input_triang_flag:
        print(
            "Input triangle data. Input format - \"name,side_a,side_b,side_c\"."
        )
        input_data = input()
        validate_res = TaskValidator.validate_triangular(input_data)
        if validate_res[0]:
            triangular_list.append(Triangular.triangular_create(input_data))
            input_triang_flag = do_continue()
        else:
            print(validate_res[1])
            input_triang_flag = do_continue()

    triangular_list = Triangular.sort_triangular_list(triangular_list)
    print("============= Triangular List: =============")
    for triangular in triangular_list:
        print(triangular)
Пример #2
0
 def test_validate_sequence(self, name, data_list, exp_res):
     act_res = (TaskValidator.validate_sequence(data_list))
     try:
         self.assertEqual(act_res[0], exp_res[0])
     except AssertionError as e:
         msg = "\nFail test - \"{0}\"; Input data - {1}; Error{2}".format(
             name, data_list, e)
         raise AssertionError(msg)
def start():
    parser = OptionParser()
    args = parser.parse_args()
    validate_res = TaskValidator.validate_number_translation(args)
    if validate_res[0]:
        print(NumberTranslator().translate(int(args[1][0])))
    else:
        print(validate_res[1])
Пример #4
0
 def test_validate_envelope_sides(self, name, side_a, side_b, exp_res):
     act_res = (TaskValidator.validate_envelope_sides(side_a, side_b))
     try:
         self.assertEqual(act_res[0], exp_res[0])
         self.assertEqual(act_res[1], exp_res[1])
     except AssertionError as e:
         msg = "\nFail test - \"{0}\"; Input data - {1}; Error{2}".format(
             name, (side_a, side_b), e)
         raise AssertionError(msg)
Пример #5
0
 def test_validate_chess_board_list(self, name, value, exp_res):
     act_res = (TaskValidator.validate_chess_board_list(value))
     try:
         self.assertEqual(act_res[0], exp_res[0])
         self.assertEqual(act_res[1], exp_res[1])
     except AssertionError as e:
         msg = "\nFail test - \"{0}\"; Input data - {1}; Error{2}".format(
             name, value, e)
         raise AssertionError(msg)
Пример #6
0
 def test_validate_number_translation(self, name, data_list, exp_res):
     act_res = TaskValidator.validate_number_translation(data_list)
     try:
         self.assertEqual(act_res[0], exp_res[0])
         self.assertEqual(act_res[1], exp_res[1])
     except AssertionError as e:
         msg = "\nFail test - \"{0}\"; Input data - {1}; Error{2}".format(
             name, data_list, e)
         raise AssertionError(msg)
Пример #7
0
 def test_validate_file_handler(self, name, arg_list, exp_res):
     act_res = TaskValidator.validate_file_handler(arg_list)
     try:
         self.assertEqual(act_res[0], exp_res[0])
         self.assertEqual(act_res[1], exp_res[1])
     except AssertionError as e:
         msg = "\nFail test - \"{0}\"; Input data - {1}; Error{2}".format(
             name, arg_list, e)
         raise AssertionError(msg)
Пример #8
0
 def test_validate_triangular(self, name, triang_str, exp_res):
     act_res = (TaskValidator.validate_triangular(triang_str))
     try:
         self.assertEqual(act_res[0], exp_res[0])
         self.assertEqual(act_res[1], exp_res[1])
     except AssertionError as e:
         msg = "\nFail test - \"{0}\"; Input data - {1}; Error{2}".format(
             name, triang_str, e)
         raise AssertionError(msg)
Пример #9
0
def start():
    """
    Start application function
    :return:
    """

    parser = OptionParser()
    args = parser.parse_args()

    validation_res = TaskValidator.validate_fibonachi(args)
    if validation_res[0]:
        fib_arr = Fibonachi.fib_in_interval(int(args[1][0]), int(args[1][1]))
        Fibonachi.print_arr(fib_arr)
    else:
        print(validation_res[1])
Пример #10
0
def start():
    """
        Start application function
    :return:
    """
    parser = OptionParser()
    args = parser.parse_args()

    validation_res = TaskValidator.validate_chess_board_list(args)
    if validation_res[0]:
        board = ChessBoard(int(args[1][0]), int(args[1][1]))
        board.print_board()
    else:
        print(validation_res[1])
        ChessBoard.show_instructions()
Пример #11
0
 def start():
     """
     Start application function
     :return:
     """
     parser = OptionParser()
     args = parser.parse_args()
     validate_res = TaskValidator.validate_sequence(args)
     if validate_res[0]:
         num = int(args[1][0])
         sequence = Sequence(
             [str(i) for i in range(1, num**2) if i**2 < num])
         print(sequence)
     else:
         print(validate_res[1])
Пример #12
0
 def input_tickets_manually(self):
     """
     Get tickets from console(user input) validate and
     save they into self.__tickets
     :return: None
     """
     flag = True
     while flag:
         print("Input ticket number - 6 digits:")
         ticket_num = input()
         validation_res = TaskValidator.validate_ticket(ticket_num)
         if validation_res[0]:
             self.__tickets.append(Ticket(ticket_num))
         else:
             print(validation_res[1])
         flag = self.do_continue()
Пример #13
0
def input_envelope():
    """
    Input data for create one envelope send data into validator
    :return: Envelope|raise UserExitError
    """
    flag = True
    while flag:
        print("Please input the first side")
        a_side = input()
        print("Please input the second side")
        b_side = input()
        validation_res = TaskValidator.validate_envelope_sides(a_side, b_side)
        if validation_res[0]:
            return Envelope(float(a_side), float(b_side))
        print(validation_res[1])
        flag = do_continue()

    raise UserExitError("User exit")
Пример #14
0
 def get_tickets_from_file(self):
     """
     Get filepath from console validate and get
     tickets from file and save they into self.__tickets
     :return: None
     """
     is_continue = True
     while is_continue:
         file_path = input("Input path to file with tickets - ")
         validate_res = TaskValidator.validate_tickets_file(file_path)
         if validate_res[0]:
             with open(file_path, "r") as f:
                 tickets = f.read()
             for t in tickets.split(','):
                 self.__tickets.append(Ticket(t))
             print("Tickets loaded successfully!")
             is_continue = False
         else:
             print(validate_res[1])
             is_continue = __class__.do_continue()
Пример #15
0
def start():
    """
    Start application function
    :return:
    """
    parser = OptionParser()
    args = parser.parse_args()
    valid_res = TaskValidator.validate_file_handler(args)
    if valid_res[0]:
        path = args[1][0]
        if len(args[1]) == 3:
            old_str = args[1][1]
            new_str = args[1][2]
            FileHandler.find_n_replace(path, old_str, new_str)
        elif len(args[1]) == 2:
            substr = args[1][1]
            substr_in_file = FileHandler.find_n_count(path, substr)
            print("The file by path \'{0}\' contain {1}, substrings \'{2}\'.".
                  format(path, substr_in_file, substr))
    else:
        print(valid_res[1])
Пример #16
0
    def get_tickets_from_numbers(self):
        """
        Get min and max ticket value from console(user input) validate and
        generate tickets between min and max, save they into self.__tickets
        :return: None
        """
        flag = True
        while flag:

            print("Input minimum ticket number between 000000 .. 999999:")
            minimum_num = input()
            print("Input maximum ticket number between 000000 .. 999999:")
            maximum_num = input()
            validate_res = TaskValidator.validate_tickets_from_numbers(
                minimum_num, maximum_num)
            if validate_res[0]:
                self.generate_tickets_by_input_numbers(int(minimum_num),
                                                       int(maximum_num))
                flag = False
            else:
                print(validate_res[1])
                flag = __class__.do_continue()