def test_delete(): t = IntervalTree.from_tuples(data.ivs1.data) try: t.remove(Interval(1, 3, "Doesn't exist")) except ValueError: pass else: raise AssertionError("Expected ValueError") try: t.remove(Interval(500, 1000, "Doesn't exist")) except ValueError: pass else: raise AssertionError("Expected ValueError") orig = t.print_structure(True) t.discard(Interval(1, 3, "Doesn't exist")) t.discard(Interval(500, 1000, "Doesn't exist")) assert orig == t.print_structure(True) assert match.set_data(t[14]) == set(['[8,15)', '[14,15)']) t.remove(Interval(14, 15, '[14,15)')) assert match.set_data(t[14]) == set(['[8,15)']) t.verify() t.discard(Interval(8, 15, '[8,15)')) assert match.set_data(t[14]) == set() t.verify() assert t[5] t.remove_overlap(5) t.verify() assert not t[5]
def test_point_queries(): t = IntervalTree.from_tuples(data.ivs1.data) assert match.set_data(t[4]) == set(['[4,7)']) assert match.set_data(t.at(4)) == set(['[4,7)']) assert match.set_data(t[9]) == set(['[6,10)', '[8,10)', '[8,15)']) assert match.set_data(t.at(9)) == set(['[6,10)', '[8,10)', '[8,15)']) assert match.set_data(t[15]) == set() assert match.set_data(t.at(15)) == set() assert match.set_data(t[5]) == set(['[4,7)', '[5,9)']) assert match.set_data(t.at(5)) == set(['[4,7)', '[5,9)']) assert match.set_data(t[4:5]) == set(['[4,7)'])
def test_envelop_vs_overlap_queries(): t = IntervalTree.from_tuples(data.ivs1.data) assert match.set_data(t.envelop(4, 5)) == set() assert match.set_data(t.overlap(4, 5)) == set(['[4,7)']) assert match.set_data(t.envelop(4, 6)) == set() assert match.set_data(t.overlap(4, 6)) == set(['[4,7)', '[5,9)']) assert match.set_data(t.envelop(6, 10)) == set(['[6,10)', '[8,10)']) assert match.set_data(t.overlap(6, 10)) == set([ '[4,7)', '[5,9)', '[6,10)', '[8,10)', '[8,15)']) assert match.set_data(t.envelop(6, 11)) == set(['[6,10)', '[8,10)']) assert match.set_data(t.overlap(6, 11)) == set([ '[4,7)', '[5,9)', '[6,10)', '[8,10)', '[8,15)', '[10,12)'])
def test_insert_to_filled_tree(): t = IntervalTree.from_tuples(data.ivs1.data) orig = t.print_structure(True) # original structure record assert match.set_data(t[1]) == set(['[1,2)']) t.add(Interval(1, 2, '[1,2)')) # adding duplicate should do nothing assert match.set_data(t[1]) == set(['[1,2)']) assert orig == t.print_structure(True) t[1:2] = '[1,2)' # adding duplicate should do nothing assert match.set_data(t[1]) == set(['[1,2)']) assert orig == t.print_structure(True) assert Interval(2, 4, '[2,4)') not in t t.add(Interval(2, 4, '[2,4)')) assert match.set_data(t[2]) == set(['[2,4)']) t.verify() t[13:15] = '[13,15)' assert match.set_data(t[14]) == set(['[8,15)', '[13,15)', '[14,15)']) t.verify()
def test_queries(): t = IntervalTree.from_tuples(data.ivs1.data) assert match.set_data(t[4]) == set(['[4,7)']) assert match.set_data(t[4:5]) == set(['[4,7)']) assert match.set_data(t[4:6]) == set(['[4,7)', '[5,9)']) assert match.set_data(t[9]) == set(['[6,10)', '[8,10)', '[8,15)']) assert match.set_data(t[15]) == set() assert match.set_data(t.search(5)) == set(['[4,7)', '[5,9)']) assert match.set_data(t.search(6, 11, strict=True)) == set(['[6,10)', '[8,10)'])
def test_same_range_insert(): t = IntervalTree.from_tuples(data.ivs1.data) t.add(Interval(14, 15, '[14,15)####')) assert match.set_data(t[14]) == set(['[8,15)', '[14,15)', '[14,15)####']) t.verify()