<commit_before>from sys import float_info


def tuple_matches(
    t,
    tolerance=1.0e-8,
    error_definition="relative",
    ignore_sign=False,
    skip_below=float_info.min,
    skip_above=float_info.max,
):
    """
    Checks if tuple matches based on tolerance settings.

    Returns:
        (tuple matches, error message) - error message is None if there is no error
    """

    assert error_definition in ["relative", "absolute"]

    x, x_ref = t

    if abs(x_ref) < skip_below:
        return (True, None)

    if abs(x_ref) > skip_above:
        return (True, None)

    error = x - x_ref
    if error_definition == "relative":
        error /= x_ref

    if abs(error) <= tolerance:
        return (True, None)
    else:
        if isinstance(error, int):
            error_message = "expected: {0} ({1} diff: {2:d}".format(
                x_ref, error_definition[:3], abs(error)
            )
        else:
            error_message = "expected: {0} ({1} diff: {2:6.2e}".format(
                x_ref, error_definition[:3], abs(error)
            )
        if ignore_sign:
            error_message += " ignoring signs"
        error_message += ")"
        return (False, error_message)


def test_tuple_matches():
    assert tuple_matches((13, 13)) == (True, None)
    assert tuple_matches((13, 13), tolerance=1.0e-10, error_definition="absolute") == (
        True,
        None,
    )
    assert tuple_matches((13, 13), tolerance=1.0e-10, error_definition="relative") == (
        True,
        None,
    )
    assert tuple_matches((13, 14), tolerance=1, error_definition="absolute") == (<commit_msg>stop if relative tolerance is integer<commit_after>from sys import float_info


def tuple_matches(
    t,
    tolerance=1.0e-8,
    error_definition="relative",
    ignore_sign=False,
    skip_below=float_info.min,
    skip_above=float_info.max,
):
    """
    Checks if tuple matches based on tolerance settings.

    Returns:
        (tuple matches, error message) - error message is None if there is no error
    """

    if isinstance(tolerance, int) and error_definition == "relative":
        return (False, "relative tolerance cannot be integer")

    assert error_definition in ["relative", "absolute"]

    x, x_ref = t

    if abs(x_ref) < skip_below:
        return (True, None)

    if abs(x_ref) > skip_above:
        return (True, None)

    error = x - x_ref
    if error_definition == "relative":
        error /= x_ref

    if abs(error) <= tolerance:
        return (True, None)
    else:
        if isinstance(error, int):
            error_message = "expected: {0} ({1} diff: {2:d}".format(
                x_ref, error_definition[:3], abs(error)
            )
        else:
            error_message = "expected: {0} ({1} diff: {2:6.2e}".format(
                x_ref, error_definition[:3], abs(error)
            )
        if ignore_sign:
            error_message += " ignoring signs"
        error_message += ")"
        return (False, error_message)


def test_tuple_matches():
    assert tuple_matches((13, 13)) == (True, None)
    assert tuple_matches((13, 13), tolerance=1.0e-10, error_definition="absolute") == (
        True,
        None,
    )
    assert tuple_matches((13, 13), tolerance=1.0e-10, error_definition="relative") == (
        True,
        None,
    )
    assert tuple_matches((13, 13), tolerance=1, error_definition="relative") == (
        False,
        "relative tolerance cannot be integer",
    )
    assert tuple_matches((13, 14), tolerance=1, error_definition="absolute") == (
{'fraction_non_alphanumeric': 0.1250352013517319, 'fraction_numerical': 0.022810475922275416, 'mean_word_length': 2.4451988360814743, 'pattern_counts': {'":': 3, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3715527', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1076, 'n_words': 283}