def test_advance_time_with_delays():
    period = build_match_period(0, 50)
    delays = [
        Delay(time=1, delay=1),
        Delay(time=5, delay=2),
    ]
    clock = MatchPeriodClock(period, delays)
    curr_time = clock.current_time
    assert 0 == curr_time, "Should start at the start of the period"

    clock.advance_time(1)  # plus a delay of 2 at time=1

    curr_time = clock.current_time
    assert 2 == curr_time, "Time should advance by the given amount (1)" \
                           " plus the size of the delay it meets"

    clock.advance_time(2)

    curr_time = clock.current_time
    assert 4 == curr_time, "Time should advance by the given amount (2)" \
                           " only; there are no intervening delays"

    clock.advance_time(2)  # takes us to 6, plus a delay of 2 at time=5

    curr_time = clock.current_time
    assert 8 == curr_time, "Time should advance by the given amount (2)" \
                           " plus the size of the intervening delay (2)"

    clock.advance_time(2)

    curr_time = clock.current_time
    assert 10 == curr_time, "Time should advance by the given amount (2)" \
                            " only; there are no intervening delays"
def test_current_time_start_delayed_twice():
    period = build_match_period(0, 10)
    delays = [
        Delay(time=0, delay=2),
        Delay(time=1, delay=3),
    ]
    clock = MatchPeriodClock(period, delays)

    curr_time = clock.current_time

    assert 5 == curr_time, "Start time should include cumilative delays"
def test_advance_time_touching_delays():
    period = build_match_period(0, 10)
    delays = [
        Delay(time=1, delay=1),  # from 1 -> 2
        Delay(time=2, delay=1),  # from 2 -> 3
    ]
    clock = MatchPeriodClock(period, delays)
    curr_time = clock.current_time
    assert 0 == curr_time, "Should start at the start of the period"

    clock.advance_time(2)  # plus a total delay of 2

    curr_time = clock.current_time
    assert 4 == curr_time, "Time should advance by the given amount (2)" \
                           " plus the size of the intervening delays (1+1)"
def test_advance_time_overlapping_delays():
    period = build_match_period(0, 10)
    delays = [
        Delay(time=1, delay=2),  # from 1 -> 3
        Delay(time=2, delay=1),  # extra at 2, so 1 -> 4
    ]
    clock = MatchPeriodClock(period, delays)
    curr_time = clock.current_time
    assert 0 == curr_time, "Should start at the start of the period"

    clock.advance_time(2)  # plus a total delay of 3

    curr_time = clock.current_time
    assert 5 == curr_time, "Time should advance by the given amount (2)" \
                           " plus the size of the intervening delays (1+2)"
def test_current_time_start_delayed():
    period = build_match_period(0, 4)
    clock = MatchPeriodClock(period, [Delay(time=0, delay=1)])

    curr_time = clock.current_time

    assert 1 == curr_time, "Start time should include delays"
def test_current_time_beyond_max_end_with_delay():
    period = build_match_period(0, 1, 2)
    clock = MatchPeriodClock(period, [Delay(time=1, delay=2)])

    clock.advance_time(1)
    # now at 3
    check_out_of_time(clock)
def test_current_time_at_max_end_with_delay():
    period = build_match_period(0, 1, 2)
    clock = MatchPeriodClock(period, [Delay(time=1, delay=1)])

    clock.advance_time(1)

    curr_time = clock.current_time
    assert 2 == curr_time, "Should be able to query time when at max_end" \
                           " due to delays"
Ejemplo n.º 8
0
def test_timings_with_delays_during_gaps():
    positions = OrderedDict()
    for i in range(16):
        positions['team-{}'.format(i)] = i

    delays = [
        Delay(time=datetime(2014, 3, 27, 13, 20, 15),
              delay=timedelta(minutes=5)),
        Delay(time=datetime(2014, 3, 27, 13, 36), delay=timedelta(minutes=5))
    ]

    scheduler = get_scheduler(positions=positions, delays=delays)
    scheduler.add_knockouts()

    knockout_rounds = scheduler.knockout_rounds
    num_rounds = len(knockout_rounds)

    assert num_rounds == 3, "Should be quarters, semis and finals"

    start_times = [m['A'].start_time for m in scheduler.period.matches]

    expected_times = [
        # Quarter finals
        datetime(2014, 3, 27, 13, 0),
        datetime(2014, 3, 27, 13, 5),
        datetime(2014, 3, 27, 13, 10),
        datetime(2014, 3, 27, 13, 15),

        # 30 second gap
        # first delay

        # Semi finals
        datetime(2014, 3, 27, 13, 25, 30),
        datetime(2014, 3, 27, 13, 30, 30),

        # 30 second gap
        # bonus 12 second gap

        # Final
        datetime(2014, 3, 27, 13, 41, 12)
    ]

    assert expected_times == start_times, "Wrong start times"
def test_slots_delay_after():
    period = build_match_period(0, 4)
    clock = MatchPeriodClock(period, [Delay(time=6, delay=2)])

    curr_time = clock.current_time
    assert 0 == curr_time, "Should start at the start of the period"

    slots = list(clock.iterslots(1))
    expected = list(range(5))
    assert expected == slots
def test_slots_delay_during():
    period = build_match_period(0, 4, 5)
    clock = MatchPeriodClock(period, [Delay(time=1, delay=3)])
    slots = list(clock.iterslots(2))
    expected = [0, 5]
    assert expected == slots