Example #1
0
def test_is_intersecting(init_times, durations):
    """Test `is_intersecting` method."""

    init_intervals = []
    for i, init_time in enumerate(init_times):
        init_intervals.append(TimeInterval(init_times[i], durations[i]))

    interval = TimeIntervalList(init_intervals).get_interval(0)

    assert interval.is_intersecting(before) is False
    assert interval.is_intersecting(within) is True
    assert interval.is_intersecting(intersect) is True
    assert interval.is_intersecting(exact) is True
    assert interval.is_intersecting(after) is False
Example #2
0
def test_interval_list_intersection(init_times, durations):
    """Test interval intersection."""

    init_intervals = []
    for i, init_time in enumerate(init_times):
        init_intervals.append(TimeInterval(init_times[i], durations[i]))

    intervals = TimeIntervalList(init_intervals)

    interval_full_intersect = TimeInterval(Time("2020-04-13T00:00:00.000"), 5 * u.min)
    interval_part_intersect = TimeInterval(Time("2020-04-10T23:50:00.000"), 60 * u.min)
    interval_no_intersect = TimeInterval(Time("2020-04-11T12:00:00.000"), 5 * u.min)

    # *** Test TimeIntervalList vs. TimeInterval intersection ***
    assert intervals.is_intersecting(interval_full_intersect) is True
    assert "[ 2020-04-13T00:00:00.000  2020-04-13T00:05:00.000 ]" == str(
        intervals.intersect(interval_full_intersect)
    )

    assert intervals.is_intersecting(interval_part_intersect) is True
    assert "[ 2020-04-11T00:00:00.000  2020-04-11T00:10:00.000 ]" == str(
        intervals.intersect(interval_part_intersect)
    )

    assert intervals.is_intersecting(interval_no_intersect) is False
    assert intervals.intersect(interval_no_intersect) is None

    # *** Test TimeIntervalList vs. TimeIntervalList intersection ***

    test_intervals = TimeIntervalList(
        [interval_full_intersect, interval_part_intersect, interval_no_intersect]
    )

    truth_txt = (
        "[ 2020-04-11T00:00:00.000  2020-04-11T00:10:00.000 ]\n"
        "[ 2020-04-13T00:00:00.000  2020-04-13T00:05:00.000 ]\n"
    )

    assert truth_txt == str(intervals.intersect_list(test_intervals))