def test_elevator_will_not_alight_passengers_at_wrong_floor(): elevator = Elevator(name="Elevator 1") passenger_1 = Passenger(destination=2) passenger_2 = Passenger(destination=2) elevator.open_doors() elevator.load_passengers([passenger_1, passenger_2]) elevator.goto_floor(3) elevator.unload_passengers() assert len(elevator.passengers) == 2
def test_elevator_can_carry_passengers_to_one_floor(capsys): elevator = Elevator(name="Elevator 1") passenger_1 = Passenger(destination=2) passenger_2 = Passenger(destination=2) elevator.open_doors() elevator.load_passengers([passenger_1, passenger_2]) assert passenger_1 in elevator.passengers assert passenger_2 in elevator.passengers elevator.goto_floor(2) elevator.unload_passengers() assert len(elevator.passengers) == 0
def test_single_elevator(self): passengers = [ Passenger(0, 2), Passenger(1, 2), Passenger(1, 0), Passenger(2, 1), Passenger(2, 0) ] s = Simulation.manual_setup(5, 1, 3, passengers) events = s.sim_loop() assert check_passenger_movement(passengers, events)
def test_elevator_can_alight_different_passengers_at_different_floors(): elevator = Elevator(name="Elevator 1") passenger_1 = Passenger(destination=2) passenger_2 = Passenger(destination=3) elevator.open_doors() elevator.load_passengers([passenger_1, passenger_2]) elevator.goto_floor(2) elevator.unload_passengers() assert passenger_1 not in elevator.passengers assert passenger_2 in elevator.passengers assert len(elevator.passengers) == 1 elevator.goto_floor(3) elevator.unload_passengers() assert passenger_1 not in elevator.passengers assert passenger_2 not in elevator.passengers assert len(elevator.passengers) == 0
def test_passenger_weight_cannot_be_negative(): try: Passenger(destination=2, weight=-9001) assert False, "No exception was thrown" except ValueError as ex: assert str( ex ) == "You tried to assign weight of passenger to a non-positive number: {}".format( -9001)
def test_elevator_can_only_carry_passengers_when_door_is_open(): elevator = Elevator(name="Elevator 1") assert elevator.door_status == "closed" passenger_1 = Passenger(destination=2) try: elevator.load_passengers([passenger_1]) assert False, "No Exception was thrown" except Exception as ex: assert str(ex) == "You tried to load passengers into {} while it was in state {}!".format(elevator.name, elevator.state)
async def test_will_only_take_passengers_in_the_same_direction(capsys): elevator = SimpleElevator(name="test", starting_floor=5) elevator.intended_direction = "up" print(elevator.floor) await elevator.open_doors() passengers = [ Passenger(destination=1), Passenger(destination=2), Passenger(destination=3), Passenger(destination=4), Passenger(destination=6), Passenger(destination=7) ] rejected_passengers = await elevator.load_passengers(passengers) assert len(rejected_passengers) == 4 for passenger in rejected_passengers: assert passenger.destination < 5