Exemplo n.º 1
0
def test_interval_list_union(init_times, durations):
    """Test interval union."""

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

    intervals = TimeIntervalList(
        init_intervals,
        start_valid=Time("2020-04-11T00:00:00.000"),
        end_valid=Time("2020-04-14T00:00:00.000"),
    )

    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)
    interval_full_intersect = TimeInterval(Time("2020-04-13T00:00:00.000"), 5 * u.min)
    interval_outside = TimeInterval(Time("2020-04-13T23:50:00.000"), 15 * u.min)

    # *** Test TimeIntervalList vs. TimeInterval intersection ***
    assert "[ 2020-04-13T00:00:00.000  2020-04-13T00:30:00.000 ]" == str(
        intervals.union(interval_full_intersect)
    )

    assert "[ 2020-04-10T23:50:00.000  2020-04-11T00:50:00.000 ]" == str(
        intervals.union(interval_part_intersect)
    )

    assert intervals.union(interval_no_intersect) is None

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

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

    # print(intervals.union_list(test_intervals))
    truth_txt = (
        "[ 2020-04-11T00:00:00.000  2020-04-11T00:50:00.000 ]\n"
        "[ 2020-04-11T12:00:00.000  2020-04-11T12:05:00.000 ]\n"
        "[ 2020-04-12T00:00:00.000  2020-04-12T00:20:00.000 ]\n"
        "[ 2020-04-13T00:00:00.000  2020-04-13T00:30:00.000 ]\n"
        "[ 2020-04-13T23:50:00.000  2020-04-14T00:00:00.000 ]\n"
    )

    assert truth_txt == str(intervals.union_list(test_intervals))
Exemplo n.º 2
0
def test_union(init_times, durations):
    """Test `union` 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.union(before) is None
    assert interval.union(within).is_equal(interval)
    assert interval.union(intersect).is_equal(
        TimeInterval(intersect.start, interval.end))
    assert interval.union(exact).is_equal(interval)
    assert interval.union(after) is None