def test_get_position_station():
    """Test get_position for a simple station.
    """
    stations = create_stations('stations.json')
    test_id = '6023'
    assert test_id in stations

    station = stations[test_id]
    time = datetime(2017, 9, 1, 0, 0, 0)  # Note: the time shouldn't matter.
    assert station.get_position(time) == (-73.54983, 45.51086)
def test_create_stations_simple():
    """Test reading in a station from provided sample stations.json.
    """
    stations = create_stations('stations.json')
    test_id = '6023'
    assert test_id in stations

    station = stations[test_id]
    assert isinstance(station, Station)
    assert station.name == 'de la Commune / Berri'
    assert station.location == (-73.54983, 45.51086)  # NOTE: (long, lat)
    # coordinates!
    assert station.num_bikes == 18
    assert station.capacity == 39
def test_create_rides_simple():
    """Test reading in a rides file from provided sample sample_rides.csv.

    NOTE: This test relies on test_create_stations working correctly.
    """
    stations = create_stations('stations.json')
    rides = create_rides('sample_rides.csv', stations)

    # Check the first ride
    ride = rides[0]
    assert isinstance(ride, Ride)
    assert ride.start is stations['6134']
    assert ride.end is stations['6721']
    assert ride.start_time == datetime(2017, 6, 1, 7, 31, 0)
    assert ride.end_time == datetime(2017, 6, 1, 7, 54, 0)
def test_get_position_ride():
    """Test get_position for a simple ride.
    """
    stations = create_stations('stations.json')
    rides = create_rides('sample_rides.csv', stations)

    ride = rides[0]

    # Check ride endpoints. We use pytest's approx function to
    # avoid floating point issues.
    assert ride.get_position(ride.start_time) == approx(ride.start.location)
    assert ride.get_position(ride.end_time) == approx(ride.end.location)

    # Manually check a time during the ride.
    # Note that this ride lasts *23 minutes*, and
    # goes from (-73.562643, 45.537964) to
    # (-73.54628920555115, 45.57713595014113).
    # We're checking the position after 10 minutes have passed.
    assert (ride.get_position(datetime(2017, 6, 1, 7, 41, 0)) == approx(
        (-73.5555326546, 45.5549952827), abs=1e-5))