Ejemplo n.º 1
0
def test_job_complete():
    itinerary = Itinerary(234, "3434")

    move_job = itinerary.move_to(33)
    itinerary.job_complete(move_job)

    assert itinerary.is_completed()
    assert itinerary.current_job is None
    assert itinerary.completed_jobs == [move_job]

    pickup = itinerary.pickup("aaaa")
    assert itinerary.current_job == pickup
    assert not itinerary.is_completed()
    assert itinerary.jobs_to_complete == [pickup]
    assert itinerary.next_jobs == []

    dropoff = itinerary.dropoff("aaaa")
    move_job = itinerary.move_to(66666)

    assert itinerary.next_jobs == [dropoff, move_job]

    # jobs can be completed only in the order they planned
    with pytest.raises(Exception):
        itinerary.job_complete(dropoff)

    itinerary.job_complete(pickup)
    assert not itinerary.is_completed()
    assert itinerary.next_jobs == [move_job]
    assert itinerary.current_job == dropoff
    assert itinerary.jobs_to_complete == [dropoff, move_job]

    itinerary.job_complete(dropoff)
    itinerary.job_complete(move_job)
    assert itinerary.is_completed()
Ejemplo n.º 2
0
def test_add_jobs():
    itinerary = Itinerary(45, "2222")

    move_job = itinerary.move_to(123)
    current_job = itinerary.current_job
    assert move_job == current_job
    assert move_job is not None
    assert current_job is not None
    assert itinerary.next_jobs == []
    assert itinerary.jobs_to_complete == [current_job]
    assert not itinerary.is_completed()

    itinerary.pickup("1212")
    assert len(itinerary.next_jobs) == 1
    assert len(itinerary.jobs_to_complete) == 2
    assert itinerary.current_job == current_job
    assert not itinerary.is_completed()

    itinerary.dropoff("333")
    assert len(itinerary.next_jobs) == 2
    assert len(itinerary.jobs_to_complete) == 3
    assert itinerary.current_job == current_job
    assert not itinerary.is_completed()

    itinerary.wait(444)
    assert len(itinerary.next_jobs) == 3
    assert len(itinerary.jobs_to_complete) == 4
    assert itinerary.current_job == current_job
    assert not itinerary.is_completed()

    with pytest.raises(Exception):
        itinerary.add_job("Not a Base")
Ejemplo n.º 3
0
def test_create():
    vehicle = "111"
    clock = Clock()
    clock.tick()
    clock.tick()
    itinerary = Itinerary(clock.now, vehicle)

    assert itinerary.created_at == clock.now
    assert itinerary.next_jobs == []
    assert itinerary.current_job is None
    assert itinerary.jobs_to_complete == []
    # itinerary without jobs
    assert itinerary.is_completed()
    assert itinerary.vehicle == vehicle
Ejemplo n.º 4
0
    itinerary = Itinerary(clock.now, vehicle)
    itinerary.move_to(booking.pickup)
    itinerary.pickup(booking)
    itinerary.move_to(booking.dropoff)
    itinerary.dropoff(booking)

    dispatcher = Dispatcher()
    dispatcher.dispatch(itinerary)

    print(
        f"\nStart simulation at {clock.to_datetime()} ({clock.now} clock time)"
    )

    # run simulation - all state changes and movements will happen here
    # the order of steps in important: fleet -> dispatcher -> clock
    while not itinerary.is_completed():
        fleet.step()
        dispatcher.step()
        clock.tick()

    print(f"Stop simulation at {clock.to_datetime()} ({clock.now} clock time)")

    print("\nObject states after simulation:")
    print(f'Booking state is "{booking.state.value}"')
    print(f'Vehicle state is "{vehicle.state.value}"')

    fleet.stop_vehicles()

    print("\nSimulation state changes log:")
    print(simulation_logs.logs)