Esempio n. 1
0
def test_merge_unable():
    # A before B
    A = TimeSlot('A', '2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00')
    B = TimeSlot('B', '2013-05-12T10:01:00+00:00', '2013-05-12T11:00:00+00:00')
    assert A.merge(B) == None and B.merge(A) == None

    # A after B
    A = TimeSlot('A', '2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00')
    B = TimeSlot('B', '2013-05-12T08:00:00+00:00', '2013-05-12T08:59:00+00:00')
    assert A.merge(B) == None and B.merge(A) == None
Esempio n. 2
0
def test_merge_able():
    # A fits just before B
    A = TimeSlot('A', '2013-05-12T08:00:00+00:00', '2013-05-12T09:00:00+00:00')
    B = TimeSlot('B', '2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00')
    ansAB = TimeSlot([{
        'summary': 'A',
        'begin_datetime': '2013-05-12T08:00:00+00:00',
        'end_datetime': '2013-05-12T09:00:00+00:00'
    }, {
        'summary': 'B',
        'begin_datetime': '2013-05-12T09:00:00+00:00',
        'end_datetime': '2013-05-12T10:00:00+00:00'
    }], '2013-05-12T08:00:00+00:00', '2013-05-12T10:00:00+00:00')
    ansBA = TimeSlot([{
        'summary': 'B',
        'begin_datetime': '2013-05-12T09:00:00+00:00',
        'end_datetime': '2013-05-12T10:00:00+00:00'
    }, {
        'summary': 'A',
        'begin_datetime': '2013-05-12T08:00:00+00:00',
        'end_datetime': '2013-05-12T09:00:00+00:00'
    }], '2013-05-12T08:00:00+00:00', '2013-05-12T10:00:00+00:00')
    assert ansAB.equals(A.merge(B)) and ansBA.equals(B.merge(A))

    # A fits just after B
    A = TimeSlot('A', '2013-05-12T10:00:00+00:00', '2013-05-12T11:00:00+00:00')
    B = TimeSlot('B', '2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00')
    ansAB = TimeSlot([{
        'summary': 'A',
        'begin_datetime': '2013-05-12T10:00:00+00:00',
        'end_datetime': '2013-05-12T11:00:00+00:00'
    }, {
        'summary': 'B',
        'begin_datetime': '2013-05-12T09:00:00+00:00',
        'end_datetime': '2013-05-12T10:00:00+00:00'
    }], '2013-05-12T09:00:00+00:00', '2013-05-12T11:00:00+00:00')
    ansBA = TimeSlot([{
        'summary': 'B',
        'begin_datetime': '2013-05-12T09:00:00+00:00',
        'end_datetime': '2013-05-12T10:00:00+00:00'
    }, {
        'summary': 'A',
        'begin_datetime': '2013-05-12T10:00:00+00:00',
        'end_datetime': '2013-05-12T11:00:00+00:00'
    }], '2013-05-12T09:00:00+00:00', '2013-05-12T11:00:00+00:00')
    assert ansAB.equals(A.merge(B)) and ansBA.equals(B.merge(A))

    # A front overlaps B
    A = TimeSlot('A', '2013-05-12T08:00:00+00:00', '2013-05-12T09:30:00+00:00')
    B = TimeSlot('B', '2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00')
    ansAB = TimeSlot([{
        'summary': 'A',
        'begin_datetime': '2013-05-12T08:00:00+00:00',
        'end_datetime': '2013-05-12T09:30:00+00:00'
    }, {
        'summary': 'B',
        'begin_datetime': '2013-05-12T09:00:00+00:00',
        'end_datetime': '2013-05-12T10:00:00+00:00'
    }], '2013-05-12T08:00:00+00:00', '2013-05-12T10:00:00+00:00')
    ansBA = TimeSlot([{
        'summary': 'B',
        'begin_datetime': '2013-05-12T09:00:00+00:00',
        'end_datetime': '2013-05-12T10:00:00+00:00'
    }, {
        'summary': 'A',
        'begin_datetime': '2013-05-12T08:00:00+00:00',
        'end_datetime': '2013-05-12T09:30:00+00:00'
    }], '2013-05-12T08:00:00+00:00', '2013-05-12T10:00:00+00:00')
    assert ansAB.equals(A.merge(B)) and ansBA.equals(B.merge(A))

    # A back overlaps B
    A = TimeSlot('A', '2013-05-12T09:30:00+00:00', '2013-05-12T12:00:00+00:00')
    B = TimeSlot('B', '2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00')
    ansAB = TimeSlot([{
        'summary': 'A',
        'begin_datetime': '2013-05-12T09:30:00+00:00',
        'end_datetime': '2013-05-12T12:00:00+00:00'
    }, {
        'summary': 'B',
        'begin_datetime': '2013-05-12T09:00:00+00:00',
        'end_datetime': '2013-05-12T10:00:00+00:00'
    }], '2013-05-12T09:00:00+00:00', '2013-05-12T12:00:00+00:00')
    ansBA = TimeSlot([{
        'summary': 'B',
        'begin_datetime': '2013-05-12T09:00:00+00:00',
        'end_datetime': '2013-05-12T10:00:00+00:00'
    }, {
        'summary': 'A',
        'begin_datetime': '2013-05-12T09:30:00+00:00',
        'end_datetime': '2013-05-12T12:00:00+00:00'
    }], '2013-05-12T09:00:00+00:00', '2013-05-12T12:00:00+00:00')
    assert ansAB.equals(A.merge(B)) and ansBA.equals(B.merge(A))

    # A same as B
    A = TimeSlot('A', '2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00')
    B = TimeSlot('B', '2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00')
    ansAB = TimeSlot([{
        'summary': 'A',
        'begin_datetime': '2013-05-12T09:00:00+00:00',
        'end_datetime': '2013-05-12T10:00:00+00:00'
    }, {
        'summary': 'B',
        'begin_datetime': '2013-05-12T09:00:00+00:00',
        'end_datetime': '2013-05-12T10:00:00+00:00'
    }], '2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00')
    ansBA = TimeSlot([{
        'summary': 'B',
        'begin_datetime': '2013-05-12T09:00:00+00:00',
        'end_datetime': '2013-05-12T10:00:00+00:00'
    }, {
        'summary': 'A',
        'begin_datetime': '2013-05-12T09:00:00+00:00',
        'end_datetime': '2013-05-12T10:00:00+00:00'
    }], '2013-05-12T09:00:00+00:00', '2013-05-12T10:00:00+00:00')
    assert ansAB.equals(A.merge(B)) and ansBA.equals(B.merge(A))

    # A completely overlaps B
    A = TimeSlot('A', '2013-05-12T08:00:00+00:00', '2013-05-12T12:00:00+00:00')
    B = TimeSlot('B', '2013-05-12T08:00:00+00:00', '2013-05-12T10:00:00+00:00')
    ansAB = TimeSlot([{
        'summary': 'A',
        'begin_datetime': '2013-05-12T08:00:00+00:00',
        'end_datetime': '2013-05-12T12:00:00+00:00'
    }, {
        'summary': 'B',
        'begin_datetime': '2013-05-12T08:00:00+00:00',
        'end_datetime': '2013-05-12T10:00:00+00:00'
    }], '2013-05-12T08:00:00+00:00', '2013-05-12T12:00:00+00:00')
    ansBA = TimeSlot([{
        'summary': 'B',
        'begin_datetime': '2013-05-12T08:00:00+00:00',
        'end_datetime': '2013-05-12T10:00:00+00:00'
    }, {
        'summary': 'A',
        'begin_datetime': '2013-05-12T08:00:00+00:00',
        'end_datetime': '2013-05-12T12:00:00+00:00'
    }], '2013-05-12T08:00:00+00:00', '2013-05-12T12:00:00+00:00')
    assert ansAB.equals(A.merge(B)) and ansBA.equals(B.merge(A))
def test_merge_able():
    # 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')
    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.merge(B)) and ansBA.equals(B.merge(A))

    # 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')
    ansAB = TimeSlot('2013-05-12T09:00:00+00:00', '2013-05-12T11:00:00+00:00')
    ansBA = TimeSlot('2013-05-12T09:00:00+00:00', '2013-05-12T11:00:00+00:00')
    assert ansAB.equals(A.merge(B)) and ansBA.equals(B.merge(A))

    # 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-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.merge(B)) and ansBA.equals(B.merge(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:00:00+00:00', '2013-05-12T12:00:00+00:00')
    ansBA = TimeSlot('2013-05-12T09:00:00+00:00', '2013-05-12T12:00:00+00:00')
    assert ansAB.equals(A.merge(B)) and ansBA.equals(B.merge(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.merge(B)) and ansBA.equals(B.merge(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-12T12:00:00+00:00')
    ansBA = TimeSlot('2013-05-12T08:00:00+00:00', '2013-05-12T12:00:00+00:00')
    assert ansAB.equals(A.merge(B)) and ansBA.equals(B.merge(A))