def test_region_fuse(): # Fusing two linear regions r = Region(20, 50, context=Context(100, False, start_index=0)) r2 = Region(51, 70, context=Context(100, False, start_index=0)) assert r.consecutive_with(r2) assert not r2.consecutive_with(r) r.fuse(r2) assert r2.fuse(r) is None r = Region(95, 100, context=Context(100, True, start_index=1)) r2 = Region(1, 70, context=Context(100, True, start_index=1)) assert r.consecutive_with(r2) assert not r2.consecutive_with(r) r.fuse(r2) assert r.start == 95 assert r.end == 70 assert r2.start == 1 assert r2.end == 70 r = Region(1, 100, context=Context(100, False, start_index=1)) r2 = Region(5, 99, context=Context(100, False, start_index=1)) assert not r.consecutive_with(r2) r = Region(20, 50, context=Context(100, False, start_index=0)) r2 = Region(51, 70, context=Context(100, False, start_index=0)) f = r.fuse(r2, inplace=False) assert r is not f
def test_raise_context_error(): with pytest.raises(RegionError): r = Region(10, 50, context=Context(100, True, start_index=0)) r2 = Region(20, 90, context=Context(100, False, start_index=0)) r.consecutive_with(r2) with pytest.raises(RegionError): r = Region(10, 50, context=Context(100, False, start_index=0)) r2 = Region(20, 90, context=Context(101, False, start_index=0)) r.consecutive_with(r2) with pytest.raises(RegionError): r = Region(10, 50, context=Context(100, False, start_index=1)) r2 = Region(20, 90, context=Context(100, False, start_index=0)) r.consecutive_with(r2)
def test_consecutive_with(): # is consecutive r = Region(20, 50, context=Context(100, False, start_index=0)) r2 = Region(51, 70, context=Context(100, False, start_index=0)) assert r.consecutive_with(r2) assert not r2.consecutive_with(r) # has gap r = Region(20, 50, context=Context(100, False, start_index=0)) r2 = Region(52, 70, context=Context(100, False, start_index=0)) assert not r.consecutive_with(r2) assert not r2.consecutive_with(r) # same indices r = Region(20, 50, context=Context(100, False, start_index=0)) r2 = Region(50, 70, context=Context(100, False, start_index=0)) assert not r.consecutive_with(r2) assert not r2.consecutive_with(r) # has overlap r = Region(20, 50, context=Context(100, False, start_index=0)) r2 = Region(49, 70, context=Context(100, False, start_index=0)) assert not r.consecutive_with(r2) assert not r2.consecutive_with(r) # linear regions over origin r = Region(20, 100, context=Context(100, False, start_index=1)) r2 = Region(1, 10, context=Context(100, False, start_index=1)) assert not r.consecutive_with(r2) assert not r2.consecutive_with(r) # linear regions over origin r = Region(1, 10, context=Context(100, False, start_index=1)) r2 = Region(11, 30, context=Context(100, False, start_index=1)) assert r.consecutive_with(r2) assert not r2.consecutive_with(r) # circular regions over origin r = Region(20, 100, context=Context(100, True, start_index=1)) r2 = Region(1, 10, context=Context(100, True, start_index=1)) assert r.consecutive_with(r2) assert not r2.consecutive_with(r) # self consecutive with r = Region(20, 19, context=Context(100, True)) assert r.consecutive_with(r) with pytest.raises(RegionError): r = Region(20, 50, context=Context(100, False, start_index=0)) r2 = Region(51, 70, context=Context(100, False, start_index=1)) r.consecutive_with(r2) r = Region(90, 10, context=Context(100, True, start_index=1)) r2 = Region(11, 20, context=Context(100, True, start_index=1)) assert r.consecutive_with(r2) assert not r2.consecutive_with(r) r = Region(10, 90, direction=Region.REVERSE, context=Context(100, True, start_index=1)) r2 = Region(11, 20, direction=Region.FORWARD, context=Context(100, True, start_index=1)) assert r.consecutive_with(r2) assert not r2.consecutive_with(r) r = Region(10, 90, direction=Region.REVERSE, context=Context(100, True, start_index=1)) r2 = Region(89, 20, direction=Region.REVERSE, context=Context(100, True, start_index=1)) assert not r.consecutive_with(r2) assert r2.consecutive_with(r)