def test_find_left_operand():
    function_string = "1+2"
    sign_position = 1
    returned_operand = OperandFinder.find_left_operand(function_string,
                                                       sign_position)
    expected_operand = Operand(0, "1", 1)
    assert returned_operand == expected_operand
def test_find_right_operand_tail_position():
    function_string = "1+2"
    sign_position = 1
    returned_operand_tail = OperandFinder.find_right_operand_tail(
        function_string, sign_position)
    expected_operand_tail = 3
    assert returned_operand_tail == expected_operand_tail
def test_find_left_operand_position_():
    function_string = "1+2+3"
    sign_position = 3
    returned_operand_position = OperandFinder.find_left_operand_position(
        function_string, sign_position)
    expected_operand_position = 2
    assert returned_operand_position == expected_operand_position
def test_find_right_sign_operand():
    function_string = "1+2"
    sign_position = 1
    returned_operand = OperandFinder.find_right_operand(
        function_string, sign_position)
    expected_operand = Operand(2, "2", 3)
    assert returned_operand == expected_operand
Exemple #5
0
def test_do_operation_with_zero_result():
    function_string = "1-1"
    operand_finder = OperandFinder()
    operation = Substraction(operand_finder, 1, 1)
    returned_function_string = operation.do_operation(function_string)
    expected_function_string = "0.0"
    assert returned_function_string == expected_function_string
Exemple #6
0
def test_do_operation_with_negative_left_operand():
    function_string = "-1-1"
    operand_finder = OperandFinder()
    operation = Substraction(operand_finder, 2, 1)
    returned_function_string = operation.do_operation(function_string)
    expected_function_string = "-2.0"
    assert returned_function_string == expected_function_string
Exemple #7
0
def test_do_operation():
    function_string = "1+1"
    operand_finder = OperandFinder()
    operation = Addition(operand_finder, 1, 1)
    returned_function_string = operation.do_operation(function_string)
    expected_function_string = "2.0"
    assert returned_function_string == expected_function_string
Exemple #8
0
def test_do_operation_warns_right_operation():
    class SubstractionSpy(Substraction):
        def update_positions_after_shift(self, shift_length):
            super()
            self.was_warned = True

    function_string = "1-1-1"
    operand_finder = OperandFinder()
    operation = Substraction(operand_finder, 1, 1)
    right_operation = SubstractionSpy(operand_finder, 3, 1)
    operation.set_right_operation(right_operation)
    operation.do_operation(function_string)
    assert right_operation.was_warned
 def create(sign: str, sign_position: int):
     operand_finder = OperandFinder()
     if sign == Sign.EXPONENTIATION_CHARACTER:
         return Exponentiation(operand_finder, sign_position,
                               Sign.EXPONENTIATION_PRIORITY)
     if sign == Sign.DIVISION_CHARACTER:
         return Division(operand_finder, sign_position,
                         Sign.DIVISION_PRIORITY)
     if sign == Sign.MULTIPLICATION_CHARACTER:
         return Multiplication(operand_finder, sign_position,
                               Sign.MULTIPLICATION_PRIORITY)
     if sign == Sign.SUBSTRACTION_CHARACTER:
         return Substraction(operand_finder, sign_position,
                             Sign.SUBSTRACTION_PRIORITY)
     elif sign == Sign.ADDITION_CHARACTER:
         return Addition(operand_finder, sign_position,
                         Sign.ADDITION_PRIORITY)
     else:
         raise NotImplementedError
def test_find_right_negative_operand(function_string, sign_position,
                                     expected_right_operand_string):
    right_operand = OperandFinder.find_right_operand(function_string,
                                                     sign_position)
    assert right_operand.operand == expected_right_operand_string