def test_intersect_unable(): # A fits just before B A = TimeSlot('2013-05-12T08:00:00+00:00', '2013-05-12T09:00:00+00:00') B = TimeSlot('2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00') assert A.intersect(B) == None and B.intersect(A) == None # A fits just after B A = TimeSlot('2013-05-12T10:00:00+00:00', '2013-05-12T11:00:00+00:00') B = TimeSlot('2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00') assert A.intersect(B) == None and B.intersect(A) == None
def test_intersect_able(): # A front overlaps B A = TimeSlot('2013-05-12T08:00:00+00:00', '2013-05-12T09:30:00+00:00') B = TimeSlot('2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00') ansAB = TimeSlot('2013-05-12T09:00:00+00:00', '2013-05-12T09:30:00+00:00') ansBA = TimeSlot('2013-05-12T09:00:00+00:00', '2013-05-12T09:30:00+00:00') assert ansAB.equals(A.intersect(B)) and ansBA.equals(B.intersect(A)) # A back overlaps B A = TimeSlot('2013-05-12T09:30:00+00:00', '2013-05-12T12:00:00+00:00') B = TimeSlot('2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00') ansAB = TimeSlot('2013-05-12T09:30:00+00:00', '2013-05-12T10:00:00+00:00') ansBA = TimeSlot('2013-05-12T09:30:00+00:00', '2013-05-12T10:00:00+00:00') assert ansAB.equals(A.intersect(B)) and ansBA.equals(B.intersect(A)) # A same as B A = TimeSlot('2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00') B = TimeSlot('2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00') ansAB = TimeSlot('2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00') ansBA = TimeSlot('2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00') assert ansAB.equals(A.intersect(B)) and ansBA.equals(B.intersect(A)) # A completely overlaps B A = TimeSlot('2013-05-12T08:00:00+00:00', '2013-05-12T12:00:00+00:00') B = TimeSlot('2013-05-12T08:00:00+00:00', '2013-05-12T10:00:00+00:00') ansAB = TimeSlot('2013-05-12T08:00:00+00:00', '2013-05-12T10:00:00+00:00') ansBA = TimeSlot('2013-05-12T08:00:00+00:00', '2013-05-12T10:00:00+00:00') assert ansAB.equals(A.intersect(B)) and ansBA.equals(B.intersect(A))