Ejemplo n.º 1
0
def test_query_overlaps_interval_start():
    lapper = setup_nonoverlapping()
    cursor = Cursor(0)
    expected = Interval(20, 30, 0)

    assert expected == next(lapper.find(15, 25))
    assert expected == next(lapper.seek(15, 25, cursor))
    assert list(lapper.find(15, 25)) == list(lapper.seek(15, 25, Cursor(0)))
Ejemplo n.º 2
0
def test_query_overlaps_interval_stop():
    """Test that a query that overlaps the stop of an interval returns that interval"""
    lapper = setup_nonoverlapping()
    cursor = Cursor(0)
    expected = Interval(20, 30, 0)

    assert expected == next(lapper.find(25, 35))
    assert expected == next(lapper.seek(25, 35, cursor))
    assert list(lapper.find(25, 35)) == list(lapper.seek(25, 35, Cursor(0)))
Ejemplo n.º 3
0
def test_overlapping_intervals():
    """Test interval overlaps are working properly"""
    lapper = setup_overlapping()
    cursor = Cursor(0)
    e1 = Interval(0, 15, 0)
    e2 = Interval(10, 25, 0)
    assert [e1, e2] == list(lapper.find(8, 20))
    assert [e1, e2] == list(lapper.seek(8, 20, cursor))
    assert list(lapper.find(8, 20)) == list(lapper.seek(8, 20, Cursor(0)))
Ejemplo n.º 4
0
def test_query_envelops_interval():
    """Test that a query that envolops an interval returns that interval"""
    lapper = setup_nonoverlapping()
    cursor = Cursor(0)
    expected = Interval(20, 30, 0)

    assert expected == next(lapper.find(15, 35))
    assert expected == next(lapper.seek(15, 35, cursor))
    assert list(lapper.find(15, 35)) == list(lapper.seek(15, 35, Cursor(0)))
Ejemplo n.º 5
0
def test_interval_envelops_query():
    """Test that a query that is enveloped by interval returns interval"""
    lapper = setup_nonoverlapping()
    cursor = Cursor(0)
    expected = Interval(20, 30, 0)

    assert expected == next(lapper.find(22, 27))
    assert expected == next(lapper.seek(22, 27, cursor))
    assert list(lapper.find(22, 27)) == list(lapper.seek(22, 27, Cursor(0)))
Ejemplo n.º 6
0
def test_query_start_interval_stop():
    lapper = setup_nonoverlapping()
    cursor = Cursor(0)
    with pytest.raises(StopIteration):
        next(lapper.find(30, 35))
    with pytest.raises(StopIteration):
        next(lapper.seek(30, 35, cursor))
Ejemplo n.º 7
0
def test_find_over_behind_first_match():
    """Test that if lower_bound puts us before the first match, we still return a match"""
    lapper = setup_bad_lapper()
    e1 = Interval(50, 55, 0)
    found = next(lapper.find(50, 55))
    assert found == e1
    assert list(lapper.find(50, 55)) == list(lapper.seek(50, 55, Cursor(0)))
Ejemplo n.º 8
0
def test_seek_over_overlapping():
    """Test that seeking for all intervals over self == len(self)"""
    lapper = setup_overlapping()
    cursor = Cursor(0)
    total = 0
    for iv in lapper:
        for fiv in lapper.seek(iv.start, iv.stop, cursor):
            total += 1
    assert total == 28
Ejemplo n.º 9
0
def test_seek_over_len():
    """Test that it's not possible to induce index out of bounds by pushing the cursor past the end of the lapper."""
    lapper = setup_nonoverlapping()
    single = setup_single()
    cursor = Cursor(0)

    for interval in lapper.intervals:
        for o_interval in single.seek(interval.start, interval.stop, cursor):
            print(o_interval)
Ejemplo n.º 10
0
def main():
    ivs = make_random(200_000, 50_000_000, 3)
    ivs_sorted = sorted(ivs, key=lambda x: x.start)
    lapper = Lapper(ivs)
    print("Lapper find:")
    total = 0
    for iv in ivs:
        found = sum(1 for f in lapper.find(iv.start, iv.stop))
        total += found
    print(total)
    print("Lapper seek")
    total = 0
    cursor = Cursor(0)
    for iv in lapper.intervals:
        total += sum(1 for f in lapper.seek(iv.start, iv.stop, cursor))
    print(total)
Ejemplo n.º 11
0
def test_bad_skips():
    """When there is a very long interval that spans many little intervals, test that the little intevals still get returne properly"""
    data = [
        Interval(25264912, 25264986, 0),
        Interval(27273024, 27273065, 0),
        Interval(27440273, 27440318, 0),
        Interval(27488033, 27488125, 0),
        Interval(27938410, 27938470, 0),
        Interval(27959118, 27959171, 0),
        Interval(28866309, 33141404, 0),
    ]
    lapper = Lapper(data)
    found = list(lapper.find(28974798, 33141355))
    assert found == [Interval(28866309, 33141404, 0)]
    assert list(lapper.find(28974798, 33141355)) == list(
        lapper.seek(28974798, 33141355, Cursor(0)))
Ejemplo n.º 12
0
def test_seek_over_short_stop():
    """Test that seek is not stopping early"""
    lapper = Lapper([
        Interval(0, 1, 0),
        Interval(0, 1, 0),
        Interval(1, 2, 0),
    ])
    cursor = Cursor(0)

    seek_total = 0
    for iv in lapper:
        for fiv in lapper.seek(iv.start, iv.stop, cursor):
            seek_total += 1
    find_total = 0
    for iv in lapper:
        for fiv in lapper.find(iv.start, iv.stop):
            find_total += 1
    assert seek_total == 5
    assert find_total == 5
Ejemplo n.º 13
0
from py_lapper import Interval, Lapper, Cursor

intervals = [Interval(0, 5, True), Interval(4, 8, True), Interval(9, 12, True)]
lapper = Lapper(intervals)

found = [iv for iv in lapper.find(4, 7)]
# found = [Interval(0, 5, True), Interval(4, 8, True)]

# Use seek when you will have many queries in sorted order.
cursor = Cursor(0)
found = [iv for iv in lapper.seek(1, 4, cursor)]
# found = [Interval(0, 5, True)]
# cursor = Cursor(2)

found = [iv for iv in lapper.seek(5, 7, cursor)]
# found = [Interval(4, 8, True)]
# cursor = Cursor(3)