예제 #1
0
def basic_test_close():
    """
    Example close times from the algorithm description webpage
    """
    assert acp_times.close_time(60, 200, sample_time).replace(second=0, microsecond=0) == sample_time.shift(hours=4)
    assert acp_times.close_time(120, 200, sample_time).replace(second=0, microsecond=0) == sample_time.shift(hours=8)
    assert acp_times.close_time(175, 200, sample_time).replace(second=0, microsecond=0) == sample_time.shift(hours=11,
                                                                                                             minutes=40)
def test_high_3():
    """
    Tests overkill values that exceed brevet distance by only one
    """
    # Both should be identical to high_1 results
    assert a_same(open_time(201, 200, d_arrow), arrow.get('2000-01-01 05:53:00', 'YYYY-MM-DD HH:mm:ss'))
    assert a_same(open_time(401, 400, d_arrow), arrow.get('2000-01-01 12:08:00', 'YYYY-MM-DD HH:mm:ss'))
    assert a_same(close_time(1001, 1000, d_arrow), arrow.get('2000-01-04 03:00:00', 'YYYY-MM-DD HH:mm:ss'))
    assert a_same(close_time(601, 600, d_arrow), arrow.get('2000-01-02 16:00:00', 'YYYY-MM-DD HH:mm:ss'))
def test_high_1():
    """
    Tests non-overkill values (where control distance = brevet distance)
    """
    # Should have no effect on either set
    assert a_same(open_time(200, 200, d_arrow), arrow.get('2000-01-01 05:53:00', 'YYYY-MM-DD HH:mm:ss'))
    assert a_same(open_time(400, 400, d_arrow), arrow.get('2000-01-01 12:08:00', 'YYYY-MM-DD HH:mm:ss'))
    assert a_same(close_time(1000, 1000, d_arrow), arrow.get('2000-01-04 03:00:00', 'YYYY-MM-DD HH:mm:ss'))
    assert a_same(close_time(600, 600, d_arrow), arrow.get('2000-01-02 16:00:00', 'YYYY-MM-DD HH:mm:ss'))
예제 #4
0
def longer_distance_close():
    """
    Testing close times at distances farther than 200km, taken from the algorithm description webpage
    """
    assert acp_times.close_time(550, 1000, sample_time).replace(second=0, microsecond=0) == sample_time.shift(hours=36,
                                                                                                              minutes=40)
    assert acp_times.close_time(600, 1000, sample_time).replace(second=0, microsecond=0) == sample_time.shift(hours=40)
    assert acp_times.close_time(890, 1000, sample_time).replace(second=0, microsecond=0) == sample_time.shift(hours=65,
                                                                                                              minutes=23)
def test_high_2():
    """
    Tests overkill values (control values that exceed
    the brevet distance by 20% or less)
    """
    # Both should be identical to high_1 results
    assert a_same(open_time(240, 200, d_arrow), arrow.get('2000-01-01 05:53:00', 'YYYY-MM-DD HH:mm:ss'))
    assert a_same(open_time(480, 400, d_arrow), arrow.get('2000-01-01 12:08:00', 'YYYY-MM-DD HH:mm:ss'))
    assert a_same(close_time(1200, 1000, d_arrow), arrow.get('2000-01-04 03:00:00', 'YYYY-MM-DD HH:mm:ss'))
    assert a_same(close_time(720, 600, d_arrow), arrow.get('2000-01-02 16:00:00', 'YYYY-MM-DD HH:mm:ss'))
def test_random():
    """
    Tests a small variety of non-special values
    """
    # open_time
    assert a_same(open_time(144, 200, d_arrow), arrow.get('2000-01-01 04:14:00', 'YYYY-MM-DD HH:mm:ss'))
    assert a_same(open_time(453, 600, d_arrow), arrow.get('2000-01-01 13:54:00', 'YYYY-MM-DD HH:mm:ss'))
    assert a_same(open_time(200, 400, d_arrow), arrow.get('2000-01-01 05:53:00', 'YYYY-MM-DD HH:mm:ss'))
    # close_time
    assert a_same(close_time(888, 1000, d_arrow), arrow.get('2000-01-03 17:12:00', 'YYYY-MM-DD HH:mm:ss'))
    assert a_same(close_time(81, 300, d_arrow), arrow.get('2000-01-01 05:24:00', 'YYYY-MM-DD HH:mm:ss'))
    assert a_same(close_time(347, 600, d_arrow), arrow.get('2000-01-01 23:08:00', 'YYYY-MM-DD HH:mm:ss'))
예제 #7
0
def test_close_under_60():
    assert str(acp_times.close_time(
        0, 200,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T01:00:00+00:00"
    assert str(acp_times.close_time(
        10, 200,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T01:30:00+00:00"
    assert str(acp_times.close_time(
        34, 200,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T02:42:00+00:00"
    assert str(acp_times.close_time(
        59, 200,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T03:57:00+00:00"
def test_low_2():
    """
    Tests <= 60km values (special cases) for
    control distances in both. Should create
    special exceptions for close_time and
    not do so for open_time
    """
    # open_time should calculate as normal
    assert a_same(open_time(50, 400, d_arrow), arrow.get('2000-01-01 01:28:00', 'YYYY-MM-DD HH:mm:ss'))
    assert a_same(close_time(20, 300, d_arrow), arrow.get('2000-01-01 02:00:00', 'YYYY-MM-DD HH:mm:ss'))
    assert a_same(close_time(40, 400, d_arrow), arrow.get('2000-01-01 03:00:00', 'YYYY-MM-DD HH:mm:ss'))
    assert a_same(close_time(60, 600, d_arrow), arrow.get('2000-01-01 04:00:00', 'YYYY-MM-DD HH:mm:ss'))
    # Should use updated formula past 61
    assert a_same(close_time(61, 1000, d_arrow), arrow.get('2000-01-01 04:04:00', 'YYYY-MM-DD HH:mm:ss'))
예제 #9
0
def test_close_600():
    assert str(acp_times.close_time(
        400, 600,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-02T02:40:00+00:00"
    assert str(acp_times.close_time(
        401, 600,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-02T02:44:00+00:00"
    assert str(acp_times.close_time(
        599, 600,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-02T15:56:00+00:00"
    assert str(acp_times.close_time(
        600, 600,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-02T16:00:00+00:00"
    assert str(acp_times.close_time(
        601, 600,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-02T16:00:00+00:00"
예제 #10
0
def test_controle_close_to_start():
    """
    Tests open/close times for controle locations for 60 km and under
	"""
    assert acp_times.open_time(0, 1000, sample_time).replace(second=0, microsecond=0) == sample_time
    assert acp_times.close_time(0, 1000, sample_time).replace(second=0, microsecond=0) == sample_time.shift(hours=1)

    assert acp_times.open_time(5, 1000, sample_time).replace(second=0, microsecond=0) == sample_time.shift(minutes=9)
    assert acp_times.close_time(5, 1000, sample_time).replace(second=0, microsecond=0) == sample_time.shift(hours=1,
                                                                                                            minutes=15)

    assert acp_times.open_time(20, 1000, sample_time).replace(second=0, microsecond=0) == sample_time.shift(minutes=35)
    assert acp_times.close_time(20, 1000, sample_time).replace(second=0, microsecond=0) == sample_time.shift(hours=2)

    assert acp_times.open_time(30, 1000, sample_time).replace(second=0, microsecond=0) == sample_time.shift(minutes=53)
    assert acp_times.close_time(30, 1000, sample_time).replace(second=0, microsecond=0) == sample_time.shift(hours=2,
                                                                                                             minutes=30)

    assert acp_times.open_time(60, 1000, sample_time).replace(second=0, microsecond=0) == sample_time.shift(hours=1,
                                                                                                            minutes=46)
    assert acp_times.close_time(60, 1000, sample_time).replace(second=0, microsecond=0) == sample_time.shift(hours=4)
예제 #11
0
def test_close_300():
    assert str(acp_times.close_time(
        200, 300,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T13:20:00+00:00"
    assert str(acp_times.close_time(
        201, 300,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T13:24:00+00:00"
    assert str(acp_times.close_time(
        250, 300,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T16:40:00+00:00"
    assert str(acp_times.close_time(
        299, 300,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T19:56:00+00:00"
    assert str(acp_times.close_time(
        300, 300,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T20:00:00+00:00"
    assert str(acp_times.close_time(
        301, 300,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T20:00:00+00:00"
예제 #12
0
def test_close_over_60():
    assert str(acp_times.close_time(
        60, 200,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T04:00:00+00:00"
    assert str(acp_times.close_time(
        61, 200,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T04:04:00+00:00"
    assert str(acp_times.close_time(
        100, 200,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T06:40:00+00:00"
    assert str(acp_times.close_time(
        199, 200,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T13:16:00+00:00"
    assert str(acp_times.close_time(
        200, 200,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T13:30:00+00:00"
    assert str(acp_times.close_time(
        206, 200,
        arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T13:30:00+00:00"
def test_low_1():
    """
    Tests 0km control distances
    """
    assert a_same(open_time(0, 200, d_arrow), d_arrow)
    assert a_same(close_time(0, 200, d_arrow), arrow.get('2000-01-01 01:00:00', 'YYYY-MM-DD HH:mm:ss'))
예제 #14
0
def test_close_400():
    assert str(acp_times.close_time(300, 400, arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T20:00:00+00:00"
    assert str(acp_times.close_time(301, 400, arrow.get('2020-01-01T00:00:00'))) == "2020-01-01T20:04:00+00:00"
    assert str(acp_times.close_time(399, 400, arrow.get('2020-01-01T00:00:00'))) == "2020-01-02T02:36:00+00:00"
    assert str(acp_times.close_time(400, 400, arrow.get('2020-01-01T00:00:00'))) == "2020-01-02T03:00:00+00:00"
    assert str(acp_times.close_time(401, 400, arrow.get('2020-01-01T00:00:00'))) == "2020-01-02T03:00:00+00:00"
예제 #15
0
def test_close_1000():
    assert str(acp_times.close_time(600, 1000, arrow.get('2020-01-01T00:00:00'))) == "2020-01-02T16:00:00+00:00"
    assert str(acp_times.close_time(601, 1000, arrow.get('2020-01-01T00:00:00'))) == "2020-01-02T16:05:00+00:00"
    assert str(acp_times.close_time(999, 1000, arrow.get('2020-01-01T00:00:00'))) == "2020-01-04T02:55:00+00:00"
    assert str(acp_times.close_time(1000, 1000, arrow.get('2020-01-01T00:00:00'))) == "2020-01-04T03:00:00+00:00"
    assert str(acp_times.close_time(1001, 1000, arrow.get('2020-01-01T00:00:00'))) == "2020-01-04T03:00:00+00:00"