def find_operations(expression_string): operations = list() for character_position, character in enumerate(expression_string): if Sign.is_operation_sign(character_position, expression_string): operation = OperationFactory.create(character, character_position) operations.append(operation) return operations
def find_first_sign_position_in_string(string): character_position = 0 for character in string: if Sign.is_sign(character): return character_position else: character_position += 1 raise ValueError("No sign in string")
def find_left_operand_position(function_string, sign_position): left_sign_or_end_position = SignFinder.find_left_sign_or_end_position( function_string, sign_position) if left_sign_or_end_position == 0: return left_sign_or_end_position if Sign.is_sign_of_negative_operand(left_sign_or_end_position, function_string): return left_sign_or_end_position return left_sign_or_end_position + 1
def find_left_sign_or_end_position(function_string, sign_position): left_substring = function_string[:sign_position] if Sign.contains_sign(left_substring): reversed_left_substring = left_substring[::-1] first_sign_position_in_reversed_left_substring = ( SignFinder.find_first_sign_position_in_string(reversed_left_substring) ) left_sign_position = ( SignFinder.get_string_position_from_left_substring_position( first_sign_position_in_reversed_left_substring, sign_position ) ) return left_sign_position else: end_position = 0 return end_position
def find_right_sign_or_end_position(function_string, sign_position): sign_position_tail = sign_position + 1 right_substring = function_string[sign_position_tail:] if Sign.contains_operation_sign(right_substring): first_operation_sign_position_in_right_substring = ( SignFinder.find_first_operation_sign_position_in_string(right_substring) ) right_sign_position = ( SignFinder.get_string_position_from_right_substring_position( first_operation_sign_position_in_right_substring, sign_position ) ) return right_sign_position else: end_position = len(function_string) return end_position
def find_first_operation_sign_position_in_string(function_string): for character_position, character in enumerate(function_string): if Sign.is_operation_sign(character_position, function_string): return character_position raise ValueError("No sign in string")
def test_is_sign_when_sign_given(sign): assert Sign.is_sign(sign) is True
def test_is_operation_sign_returns_false_for_negative_operand_sign(sign_position, expression_string): assert Sign.is_operation_sign(sign_position, expression_string) is False