示例#1
0
def test_equal():
    range_a = intrange(1, 5)
    range_b = intrange(10, 15)

    assert intrangeset([range_a, range_b]) == intrangeset([range_a, range_b])
    assert not intrangeset([range_a, range_b]) == intrangeset([range_a])
    assert not intrangeset([range_a]) == "foo"
示例#2
0
def test_equal():
    range_a = intrange(1, 5)
    range_b = intrange(10, 15)

    assert intrangeset([range_a, range_b]) == intrangeset([range_a, range_b])
    assert not intrangeset([range_a, range_b]) == intrangeset([range_a])
    assert not intrangeset([range_a]) == "foo"
示例#3
0
def test_union():
    a = intrangeset([intrange(1, 5), intrange(20, 30)])
    b = intrangeset([intrange(5, 10), intrange(20, 100)])
    union = [intrange(1, 10), intrange(20, 100)]

    assert list(a.union(b)) == union
    assert list(a | b) == union

    with pytest.raises(TypeError):
        intrangeset([]).union(intrange())
    assert intrangeset([]).__or__(intrange()) is NotImplemented
示例#4
0
def test_difference():
    a = intrangeset([intrange(1, 5), intrange(20, 30)])
    b = intrangeset([intrange(5, 10), intrange(20, 100)])
    difference = [intrange(1, 5)]

    assert list(a.difference(b)) == difference
    assert list(a - b) == difference

    with pytest.raises(TypeError):
        intrangeset([]).difference(intrange())
    assert intrangeset([]).__sub__(intrange()) is NotImplemented
示例#5
0
def test_difference():
    a = intrangeset([intrange(1, 5), intrange(20, 30)])
    b = intrangeset([intrange(5, 10), intrange(20, 100)])
    difference = [intrange(1, 5)]

    assert list(a.difference(b)) == difference
    assert list(a - b) == difference

    with pytest.raises(TypeError):
        intrangeset([]).difference(intrange())
    assert intrangeset([]).__sub__(intrange()) is NotImplemented
示例#6
0
def test_union():
    a = intrangeset([intrange(1, 5), intrange(20, 30)])
    b = intrangeset([intrange(5, 10), intrange(20, 100)])
    union = [intrange(1, 10), intrange(20, 100)]

    assert list(a.union(b)) == union
    assert list(a | b) == union

    with pytest.raises(TypeError):
        intrangeset([]).union(intrange())
    assert intrangeset([]).__or__(intrange()) is NotImplemented
示例#7
0
def test_bug3_intersection():
    """
    `Bug #3 <https://github.com/runfalk/spans/issues/3>`_
    """

    range_a = intrange(1, 5)
    range_b = intrange(5, 10)
    range_c = intrange(10, 15)

    rangeset_a = intrangeset([range_a, range_c])
    rangeset_b = intrangeset([range_b])
    rangeset_c = intrangeset([range_c])
    rangeset_empty = intrangeset([])

    assert rangeset_a.intersection(rangeset_b, rangeset_c) == rangeset_empty
示例#8
0
def test_greater_than():
    range_a = intrange(1, 5)
    range_b = intrange(10, 15)

    assert intrangeset([range_a, range_b]) > intrangeset([range_a])
    assert not intrangeset([range_a, range_b]) > intrangeset([range_b])
    assert intrangeset([range_b]) > intrangeset([range_a, range_b])
    assert intrangeset([range_a, range_b]) >= intrangeset([range_a])
示例#9
0
def test_greater_than():
    range_a = intrange(1, 5)
    range_b = intrange(10, 15)

    assert intrangeset([range_a, range_b]) > intrangeset([range_a])
    assert not intrangeset([range_a, range_b]) > intrangeset([range_b])
    assert intrangeset([range_b]) > intrangeset([range_a, range_b])
    assert intrangeset([range_a, range_b]) >= intrangeset([range_a])
示例#10
0
def test_bug3_intersection():
    """
    `Bug #3 <https://github.com/runfalk/spans/issues/3>`_
    """

    range_a = intrange(1, 5)
    range_b = intrange(5, 10)
    range_c = intrange(10, 15)

    rangeset_a = intrangeset([range_a, range_c])
    rangeset_b = intrangeset([range_b])
    rangeset_c = intrangeset([range_c])
    rangeset_empty = intrangeset([])

    assert rangeset_a.intersection(rangeset_b, rangeset_c) == rangeset_empty
示例#11
0
def test_add():
    rset = intrangeset([intrange(1, 15)])
    rset.add(intrange(5, 15))

    assert list(rset) == [intrange(1, 15)]

    with pytest.raises(TypeError):
        rset.add(floatrange(1.0))
示例#12
0
def test_add():
    rset = intrangeset([intrange(1, 15)])
    rset.add(intrange(5, 15))

    assert list(rset) == [intrange(1, 15)]

    with pytest.raises(TypeError):
        rset.add(floatrange(1.0))
示例#13
0
def test_less_than():
    range_a = intrange(1, 5)
    range_b = intrange(10, 15)

    assert not intrangeset([range_a, range_b]) < intrangeset([range_a])
    assert intrangeset([range_a, range_b]) < intrangeset([range_b])
    assert not intrangeset([range_a, range_b]) <= intrangeset([range_a])
    assert not intrangeset([range_a]) == "foo"
示例#14
0
def test_less_than():
    range_a = intrange(1, 5)
    range_b = intrange(10, 15)

    assert not intrangeset([range_a, range_b]) < intrangeset([range_a])
    assert intrangeset([range_a, range_b]) < intrangeset([range_b])
    assert not intrangeset([range_a, range_b]) <= intrangeset([range_a])
    assert not intrangeset([range_a]) == "foo"
示例#15
0
def test_remove():
    rset = intrangeset([intrange(upper=1), intrange(5)])
    rset.remove(intrange(10, 15))

    assert rset == intrangeset([intrange(upper=1), intrange(5, 10), intrange(15)])

    # Test deletion of empty set
    temp = rset.copy()
    temp.remove(intrange.empty())
    assert rset == temp

    # Test total deletion
    rset.remove(intrange())
    assert rset == intrangeset([])

    # Test deletion on empty set
    temp = intrangeset([])
    temp.remove(intrange(1, 5))
    assert temp == intrangeset([])

    with pytest.raises(TypeError):
        rset.remove(floatrange(1.0))
示例#16
0
def intervals_for_chrom(islands_chrom_df, chrom_len):
    shore_limit = 2000
    shelf_limit = shore_limit + 2000
    chrom_interval = spans.intrange(0, chrom_len)
    intervals = {
        SEA_KEY: spans.intrangeset([chrom_interval]),
        SHELF_KEY: spans.intrangeset([]),
        SHORE_KEY: spans.intrangeset([]),
        ISLAND_KEY: spans.intrangeset([])
    }
    for _, island in islands_chrom_df.iterrows():
        add_to_interval(intervals[ISLAND_KEY], island[START_KEY],
                        island[STOP_KEY], 0, chrom_interval)
        add_to_interval(intervals[SHORE_KEY], island[START_KEY],
                        island[STOP_KEY], shore_limit, chrom_interval)
        add_to_interval(intervals[SHELF_KEY], island[START_KEY],
                        island[STOP_KEY], shelf_limit, chrom_interval)
    intervals[SEA_KEY] = intervals[SEA_KEY].difference(intervals[SHELF_KEY])
    intervals[SHELF_KEY] = intervals[SHELF_KEY].difference(
        intervals[SHORE_KEY])
    intervals[SHORE_KEY] = intervals[SHORE_KEY].difference(
        intervals[ISLAND_KEY])
    return intervals
示例#17
0
def test_intersection():
    a = intrangeset([intrange(1, 5), intrange(20, 30)])
    b = intrangeset([intrange(5, 10), intrange(20, 100)])
    intersection = [intrange(20, 30)]

    assert list(a.intersection(b)) == intersection
    assert list(a & b) == intersection
    assert not intrangeset([intrange(1, 5)]).intersection(
        intrangeset([intrange(5, 10)]))

    with pytest.raises(TypeError):
        intrangeset([]).intersection(intrange())
    assert intrangeset([]).__and__(intrange()) is NotImplemented
示例#18
0
def test_intersection():
    a = intrangeset([intrange(1, 5), intrange(20, 30)])
    b = intrangeset([intrange(5, 10), intrange(20, 100)])
    intersection = [intrange(20, 30)]

    assert list(a.intersection(b)) == intersection
    assert list(a & b) == intersection
    assert not intrangeset([intrange(1, 5)]).intersection(
        intrangeset([intrange(5, 10)]))

    with pytest.raises(TypeError):
        intrangeset([]).intersection(intrange())
    assert intrangeset([]).__and__(intrange()) is NotImplemented
示例#19
0
def test_remove():
    rset = intrangeset([intrange(upper=1), intrange(5)])
    rset.remove(intrange(10, 15))

    assert rset == intrangeset(
        [intrange(upper=1), intrange(5, 10),
         intrange(15)])

    # Test deletion of empty set
    temp = rset.copy()
    temp.remove(intrange.empty())
    assert rset == temp

    # Test total deletion
    rset.remove(intrange())
    assert rset == intrangeset([])

    # Test deletion on empty set
    temp = intrangeset([])
    temp.remove(intrange(1, 5))
    assert temp == intrangeset([])

    with pytest.raises(TypeError):
        rset.remove(floatrange(1.0))
示例#20
0
def test_values():
    values = intrangeset([intrange(1, 5), intrange(10, 15)]).values()
    assert list(values) == list(range(1, 5)) + list(range(10, 15))
示例#21
0
def test_pickling():
    span = intrangeset([intrange(1, 10), intrange(20, 30)])
    assert span == pickle.loads(pickle.dumps(span))
示例#22
0
def test_bug4_empty_set_iteration():
    """
    `Bug #4 <https://github.com/runfalk/spans/issues/4>`_
    """

    assert list(intrangeset([])) == []
示例#23
0
def test_not_contains(value):
    assert not intrangeset([intrange(1, 10)]).contains(value)
示例#24
0
def test_non_empty():
    assert intrangeset([intrange(1, 5)])
示例#25
0
def test_not_contains(value):
    assert not intrangeset([intrange(1, 10)]).contains(value)
示例#26
0
def test_iteration():
    ranges = [intrange(1, 5), intrange(10, 15)]
    assert list(intrangeset(ranges)) == ranges
示例#27
0
def test_non_empty():
    assert intrangeset([intrange(1, 5)])
示例#28
0
def test_copy():
    rset = intrangeset([intrange(1, 5), intrange(10, 15)])
    rcopy = rset.copy()

    assert list(rset) == list(rcopy)
    assert rset._list is not rcopy._list
示例#29
0
def test_invert():
    rset = intrangeset([intrange(1, 5), intrange(10, 15)])
    rset_inv = intrangeset([intrange(upper=1), intrange(5, 10), intrange(15)])

    assert ~rset == rset_inv
    assert rset == ~~rset
示例#30
0
def test_invert():
    rset = intrangeset([intrange(1, 5), intrange(10, 15)])
    rset_inv = intrangeset([intrange(upper=1), intrange(5, 10), intrange(15)])

    assert ~rset == rset_inv
    assert rset == ~~rset
示例#31
0
def test_empty():
    assert not intrangeset([])
示例#32
0
def test_bug4_empty_set_iteration():
    """
    `Bug #4 <https://github.com/runfalk/spans/issues/4>`_
    """

    assert list(intrangeset([])) == []
示例#33
0
def test_iteration():
    ranges = [intrange(1, 5), intrange(10, 15)]
    assert list(intrangeset(ranges)) == ranges
示例#34
0
def test_copy():
    rset = intrangeset([intrange(1, 5), intrange(10, 15)])
    rcopy = rset.copy()

    assert list(rset) == list(rcopy)
    assert rset._list is not rcopy._list
示例#35
0
def test_values():
    values = intrangeset([intrange(1, 5), intrange(10, 15)]).values()
    assert list(values) == list(range(1, 5)) + list(range(10, 15))
示例#36
0
def test_contains_type_check():
    with pytest.raises(ValueError):
        intrangeset([]).contains(1.0)

    with pytest.raises(ValueError):
        intrangeset([]).contains(floatrangeset([]))
示例#37
0
def test_pickling():
    span = intrangeset([intrange(1, 10), intrange(20, 30)])
    assert span == pickle.loads(pickle.dumps(span))
示例#38
0
def test_empty():
    assert not intrangeset([])
示例#39
0
def test_contains_type_check():
    with pytest.raises(ValueError):
        intrangeset([]).contains(1.0)

    with pytest.raises(ValueError):
        intrangeset([]).contains(floatrangeset([]))
示例#40
0
from spans import \
    daterangeset, datetimerangeset, floatrange, floatrangeset, intrange, \
    intrangeset, strrangeset, timedeltarangeset


def test_empty():
    assert not intrangeset([])


def test_non_empty():
    assert intrangeset([intrange(1, 5)])


@pytest.mark.parametrize("rangeset, span", [
    (intrangeset([intrange(1, 5), intrange(10, 15)]), intrange(1, 15)),
    (intrangeset([]), intrange.empty()),
])
def test_span(rangeset, span):
    assert rangeset.span() == span


def test_iteration():
    ranges = [intrange(1, 5), intrange(10, 15)]
    assert list(intrangeset(ranges)) == ranges


def test_copy():
    rset = intrangeset([intrange(1, 5), intrange(10, 15)])
    rcopy = rset.copy()
示例#41
0
from spans import \
    daterangeset, datetimerangeset, floatrange, floatrangeset, intrange, \
    intrangeset, strrangeset, timedeltarangeset


def test_empty():
    assert not intrangeset([])


def test_non_empty():
    assert intrangeset([intrange(1, 5)])


@pytest.mark.parametrize("rangeset, span", [
    (intrangeset([intrange(1, 5), intrange(10, 15)]), intrange(1, 15)),
    (intrangeset([]), intrange.empty()),
])
def test_span(rangeset, span):
    assert rangeset.span() == span


def test_iteration():
    ranges = [intrange(1, 5), intrange(10, 15)]
    assert list(intrangeset(ranges)) == ranges


def test_copy():
    rset = intrangeset([intrange(1, 5), intrange(10, 15)])
    rcopy = rset.copy()