Example #1
0
def test_repeat():
    lines = Lines([
        "aaa",
    ])
    term = "aa"
    assert list(search(lines, term)) == [
        (0, [(0, 2)]),
    ]
Example #2
0
def test_incorrect_mark_bug():
    lines = Lines([
        "/tests/test",
    ])
    term = "/test"
    assert list(search(lines, term)) == [
        (0, [(0, 5), (6, 11)]),
    ]
Example #3
0
def test_repeat():
    lines = [
        "aaa",
    ]
    term = "aa"
    assert list(search(lines, term)) == [
        (0, [(0, 2)]),
    ]
Example #4
0
def test_incorrect_mark_bug():
    lines = [
        "/tests/test",
    ]
    term = "/test"
    assert list(search(lines, term)) == [
        (0, [(0, 5), (6, 11)]),
    ]
Example #5
0
def test_multiple_terms():
    lines = Lines([
        "one of them",
        "two",
    ])
    term = "ne th"
    assert list(search(lines, term)) == [
        (0, [(1, 3), (7, 9)]),
    ]
Example #6
0
def test_uses_case():
    lines = Lines([
        "hone",
        "tHree",
    ])
    term = "H"
    assert list(search(lines, term)) == [
        (1, [(1, 2)]),
    ]
Example #7
0
def test_multiple_terms():
    lines = [
        "one of them",
        "two",
    ]
    term = "ne th"
    assert list(search(lines, term)) == [
        (0, [(1, 3), (7, 9)]),
    ]
Example #8
0
def test_uses_case():
    lines = [
        "hone",
        "tHree",
    ]
    term = "H"
    assert list(search(lines, term)) == [
        (1, [(1, 2)]),
    ]
Example #9
0
def test_ignores_case():
    lines = Lines([
        "hone",
        "tHree",
    ])
    term = "h"
    assert list(search(lines, term)) == [
        (0, [(0, 1)]),
        (1, [(1, 2)]),
    ]
Example #10
0
def test_re():
    lines = Lines([
        "one",
        "some].*chars",
        "three",
    ])
    term = "].*"
    assert list(search(lines, term)) == [
        (1, [(4, 7)]),
    ]
Example #11
0
def test_ignores_case():
    lines = [
        "hone",
        "tHree",
    ]
    term = "h"
    assert list(search(lines, term)) == [
        (0, [(0, 1)]),
        (1, [(1, 2)]),
    ]
Example #12
0
def test_re():
    lines = [
        "one",
        "some].*chars",
        "three",
    ]
    term = "].*"
    assert list(search(lines, term)) == [
        (1, [(4, 7)]),
    ]
Example #13
0
def test_filter():
    lines = Lines([
        "one",
        "two",
        "three",
    ])
    term = "t"
    assert list(search(lines, term)) == [
        (1, [(0, 1)]),
        (2, [(0, 1)]),
    ]
Example #14
0
def test_filter():
    lines = [
        "one",
        "two",
        "three",
    ]
    term = "t"
    assert list(search(lines, term)) == [
        (1, [(0, 1)]),
        (2, [(0, 1)]),
    ]
Example #15
0
def time_search(number_of_lines, line_fn, term, max_results):
    results = []
    for _ in range(NUMBER_OF_MEASUREMENTS):
        stdin = StringIO.StringIO("\n".join([
            line_fn(index)
            for index
            in range(number_of_lines)
        ]))
        t1 = timeit.default_timer()
        list(itertools.islice(search(read(stdin), term), max_results))
        t2 = timeit.default_timer()
        results.append(t2 - t1)
    return min(results)