<commit_before>from lexos.helpers.error_messages import SEG_NON_POSITIVE_MESSAGE, \
    OVERLAP_LARGE_MESSAGE, PROP_NEGATIVE_MESSAGE, OVERLAP_NEGATIVE_MESSAGE
from lexos.processors.prepare.cutter import cut_by_words


def test_cut_by_words():
    assert cut_by_words(" ", 1, 0, .5) == [" "]
    assert cut_by_words("test test", 1, 0, .5) == ["test ", "test"]
    assert cut_by_words("abc abc abc abc abc abc abc abc abc abc abc abc abc "
                        "abc abc abc abc abc abc abc abc abc", 4, 0, .5) == [
        "abc abc abc abc ", "abc abc abc abc ", "abc abc abc abc ",
        "abc abc abc abc ", "abc abc abc abc ", "abc abc"]


def test_cut_by_words_no_whitespace():
    assert cut_by_words("testtest", 1, 0, .5) == ["testtest"]
    assert cut_by_words("helloworld helloworld", 1, 0, .5) == ["helloworld ",
                                                               "helloworld"]


def test_cut_by_words_zero_chunks_precondition():
    try:
        _ = cut_by_words(" ", 0, 0, .5)
        raise AssertionError("zero_division error did not raise")
    except AssertionError as error:
        assert str(error) == SEG_NON_POSITIVE_MESSAGE

    try:
        _ = cut_by_words("test test", 0, 0, .5)
        raise AssertionError("zero_division error did not raise")
    except AssertionError as error:
        assert str(error) == SEG_NON_POSITIVE_MESSAGE


def test_cut_by_words_overlap():
    try:
        _ = cut_by_words("test test", 1, 1, .5)
        raise AssertionError("did not throw error")
    except AssertionError as error:
        assert str(error) == OVERLAP_LARGE_MESSAGE

    assert cut_by_words("test test test", 2, 1, .5) == ["test test ",
                                                        "test test"]
    try:
        _ = cut_by_words("test test test", 1, 2, .5)
        raise AssertionError("did not throw error")
    except AssertionError as error:
        assert str(error) == OVERLAP_LARGE_MESSAGE


def test_cut_by_words_proportion():
    assert cut_by_words("test test test", 2, 0, 0) == ["test test ", "test"]
    assert cut_by_words("test test test", 2, 0, .5) == ["test test ", "test"]
    assert cut_by_words("test test test", 2, 0, 1) == ["test test test"]
    assert cut_by_words("test test test", 2, 0, 1.5) == ["test test test"]
    assert cut_by_words("test test test", 2, 0, 2) == ["test test test"]
    assert cut_by_words("test test test test", 2, 0, .5) == ["test test ",
                                                             "test test"]
    assert cut_by_words("test test test test", 2, 0, 1) == ["test test ",
                                                            "test test"]
    assert cut_by_words("test test test test test", 2, 0, .5) == [
        "test test ", "test test ", "test"]
    assert cut_by_words("test test test test test", 2, 0, 1) == [
        "test test ", "test test test"]
    assert cut_by_words("test test test test test", 3, 0, 1) == [
        "test test test test test"]


def test_cut_by_words_neg_chunk_precondition():
    try:
        _ = cut_by_words("test", -1, 0, .5)
        raise AssertionError("did not throw error")
    except AssertionError as error:
        assert str(error) == SEG_NON_POSITIVE_MESSAGE


def test_cut_by_words_neg_prop_precondition():
    try:
        _ = cut_by_words("test", 1, 0, -1)
        raise AssertionError("did not throw error")
    except AssertionError as error:
        assert str(error) == PROP_NEGATIVE_MESSAGE


def test_cut_by_words_neg_overlap_precondition():
    try:
        _ = cut_by_words("test", 1, 0, -1)
        raise AssertionError("did not throw error")
    except AssertionError as error:
        assert str(error) == OVERLAP_NEGATIVE_MESSAGE<commit_msg>Fixed error in parameter that made pull request fail<commit_after>from lexos.helpers.error_messages import SEG_NON_POSITIVE_MESSAGE, \
    OVERLAP_LARGE_MESSAGE, PROP_NEGATIVE_MESSAGE, OVERLAP_NEGATIVE_MESSAGE
from lexos.processors.prepare.cutter import cut_by_words


def test_cut_by_words():
    assert cut_by_words(" ", 1, 0, .5) == [" "]
    assert cut_by_words("test test", 1, 0, .5) == ["test ", "test"]
    assert cut_by_words("abc abc abc abc abc abc abc abc abc abc abc abc abc "
                        "abc abc abc abc abc abc abc abc abc", 4, 0, .5) == [
        "abc abc abc abc ", "abc abc abc abc ", "abc abc abc abc ",
        "abc abc abc abc ", "abc abc abc abc ", "abc abc"]


def test_cut_by_words_no_whitespace():
    assert cut_by_words("testtest", 1, 0, .5) == ["testtest"]
    assert cut_by_words("helloworld helloworld", 1, 0, .5) == ["helloworld ",
                                                               "helloworld"]


def test_cut_by_words_zero_chunks_precondition():
    try:
        _ = cut_by_words(" ", 0, 0, .5)
        raise AssertionError("zero_division error did not raise")
    except AssertionError as error:
        assert str(error) == SEG_NON_POSITIVE_MESSAGE

    try:
        _ = cut_by_words("test test", 0, 0, .5)
        raise AssertionError("zero_division error did not raise")
    except AssertionError as error:
        assert str(error) == SEG_NON_POSITIVE_MESSAGE


def test_cut_by_words_overlap():
    try:
        _ = cut_by_words("test test", 1, 1, .5)
        raise AssertionError("did not throw error")
    except AssertionError as error:
        assert str(error) == OVERLAP_LARGE_MESSAGE

    assert cut_by_words("test test test", 2, 1, .5) == ["test test ",
                                                        "test test"]
    try:
        _ = cut_by_words("test test test", 1, 2, .5)
        raise AssertionError("did not throw error")
    except AssertionError as error:
        assert str(error) == OVERLAP_LARGE_MESSAGE


def test_cut_by_words_proportion():
    assert cut_by_words("test test test", 2, 0, 0) == ["test test ", "test"]
    assert cut_by_words("test test test", 2, 0, .5) == ["test test ", "test"]
    assert cut_by_words("test test test", 2, 0, 1) == ["test test test"]
    assert cut_by_words("test test test", 2, 0, 1.5) == ["test test test"]
    assert cut_by_words("test test test", 2, 0, 2) == ["test test test"]
    assert cut_by_words("test test test test", 2, 0, .5) == ["test test ",
                                                             "test test"]
    assert cut_by_words("test test test test", 2, 0, 1) == ["test test ",
                                                            "test test"]
    assert cut_by_words("test test test test test", 2, 0, .5) == [
        "test test ", "test test ", "test"]
    assert cut_by_words("test test test test test", 2, 0, 1) == [
        "test test ", "test test test"]
    assert cut_by_words("test test test test test", 3, 0, 1) == [
        "test test test test test"]


def test_cut_by_words_neg_chunk_precondition():
    try:
        _ = cut_by_words("test", -1, 0, .5)
        raise AssertionError("did not throw error")
    except AssertionError as error:
        assert str(error) == SEG_NON_POSITIVE_MESSAGE


def test_cut_by_words_neg_prop_precondition():
    try:
        _ = cut_by_words("test", 1, 0, -1)
        raise AssertionError("did not throw error")
    except AssertionError as error:
        assert str(error) == PROP_NEGATIVE_MESSAGE


def test_cut_by_words_neg_overlap_precondition():
    try:
        _ = cut_by_words("test", 1, -1, .5)
        raise AssertionError("did not throw error")
    except AssertionError as error:
        assert str(error) == OVERLAP_NEGATIVE_MESSAGE
{'fraction_non_alphanumeric': 0.11659973226238286, 'fraction_numerical': 0.018741633199464525, 'mean_word_length': 2.530718336483932, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '103197', 'n_tokens_mistral': 2487, 'n_tokens_neox': 2401, 'n_words': 715}