def test_Airplane_goto_new_location_not_enough_fuel(): ''' This is a perfect case! New valid location ''' ap2 = Airplane(1, 1, 39, 97) assert ap2.goto(999, 999) == False
def test_Airplane_goto_new_location(): ''' This is a perfect case! New valid location ''' ap1 = Airplane(1, 1, 3, 97) assert ap1.goto(2, 7)
def test_Airplane_error_consumption_value(): """ Negative consumption error """ with pytest.raises(ValueError, match="Incorrect/invalid consumption with value -10."): Airplane(1, 1, -10, 0)
def test_Airplane_goto_incorrect_location(): """ Negative initY error """ with pytest.raises(ValueError, match="Incorrect/invalid initY with value -1"): ap = Airplane(1, -1, 1, 97)
def main(): #dic = {1:10, 2:20, 3:30, 4:40} #print(sum([v for k,v in dic.items() if not k & 1])) m = AirlineManagerImplementation() airplane1 = Airplane('Alexa', 120, 3000, 2100, 330, 1000, 9, CabinNarrow.FIVEABREAST.value) airplane2 = Airplane('Pico', 130, 5000, 2200, 420, 800, 3, CabinNarrow.FIVEABREAST.value) airplane3 = Airplane('Qive', 110, 4000, 2050, 400, 1040, 5, CabinNarrow.FIVEABREAST.value) m.addAirplane(airplane1) m.addAirplane(airplane2) m.addAirplane(airplane3) m.printListOfAirplanes() print("\n"+"."*20) m.sortByMaxDistance(True) m.printListOfAirplanes() print("\n"+"."*20) m.sortByMaxDistance(False) m.printListOfAirplanes() print(m.countMaxLoadCapacity())
class AirportSim: lax = Airport("LAX", 0.5, 2, 0.3) atl = Airport("ATL", 0.5, 2, 0.3) nyc = Airport("NYC", 0.5, 2, 0.3) iah = Airport("IAH", 0.5, 2, 0.3) chi = Airport("CHI", 0.5, 2, 0.3) plane1 = Airplane("plane1", 506, 640, 1000, 2, 1) plane2 = Airplane("plane2", 147, 583, 1000, 2, 1) plane3 = Airplane("plane3", 314, 562, 1000, 2, 1) plane4 = Airplane("plane4", 277, 541, 1000, 2, 1) plane5 = Airplane("plane5", 290, 567, 1000, 2, 1) plane6 = Airplane("plane6", 506, 640, 1000, 2, 1) plane7 = Airplane("plane7", 147, 583, 1000, 2, 1) plane8 = Airplane("plane8", 314, 562, 1000, 2, 1) plane9 = Airplane("plane9", 277, 541, 1000, 2, 1) plane10 = Airplane("plane10", 290, 567, 1000, 2, 1) airplanes = [ plane1, plane2, plane3, plane4, plane5, plane6, plane7, plane8, plane9, plane10 ] airports = [lax, atl, nyc, iah, chi]
def load_structure(num_elem, damp_ratio): right_wing, left_wing = create_flexible_member(num_elem, damp_ratio) right_wing.elementsVector[0].setH0( np.array([[0], [-0.3], [0], [1], [0], [0], [0], [1], [0], [0], [0], [1]])) left_wing.elementsVector[0].setH0( np.array([[0], [-0.3], [0], [1], [0], [0], [0], [1], [0], [0], [0], [1]])) right_wing.update() left_wing.update() fus = Fuselage( m=10, pcm=np.array([0, 0, 0]), I=np.zeros((3, 3)) + 0 * np.array([[0.2**2 * 10, 0, 0], [0, 0, 0], [0, 0, 0.2**2 * 10]])) Fmax = 1 V0 = 1 rho0 = 1 nv = -1 nrho = 0 alphaf = 0 betaf = 0 numPI = 1 numMEMB = 1 numELEM = 1 numNODE = 1 motor1 = Engine(numPI, numMEMB, numELEM, numNODE, Fmax, rho0, V0, nrho, nv, alphaf, betaf) airp = Airplane(np.array([right_wing, left_wing]), np.array([motor1]), fus) # flexible_member = create_flexible_member(numele, damp_ratio) # # flexible_member.elementsVector[0].setH0(np.array([[0], [-0.0], [0], [1], [0], [0], [0], [1], [0], [0], [0], [1]])) # flexible_member.update() # # fus = Fuselage(m=0, pcm=np.array([0, 0, 0]), I=np.zeros((3, 3)) + 0 * np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])) # no fuselage # motor1 = Engine(0, 0, 0, 0) # no engines # airp = Airplane(np.array([flexible_member]), np.array([motor1]), fus) return airp
def add_airplane(): name = request.json['name'] seatsNumber = request.json['seatsNumber'] maxLoadCapacity = request.json['maxLoadCapacity'] maxDistance = request.json['maxDistance'] maxSpeed = request.json['maxSpeed'] flightRange = request.json['flightRange'] fuselageDiameter = request.json['fuselageDiameter'] cabinNarrow = request.json['cabinNarrow'] new_airplane = Airplane(name, seatsNumber, maxLoadCapacity, maxDistance, maxSpeed, flightRange, fuselageDiameter, cabinNarrow) db.session.add(new_airplane) db.session.commit() return airplane_schema.jsonify(new_airplane)
def load_structure(num_elem, damp_ratio, rho, E, G, c, t, L, rootSweepAng, rootTwistAng): flexible_member = create_flexible_member(num_elem, damp_ratio, rho, E, G, c, t, L, rootSweepAng, rootTwistAng) flexible_member.elementsVector[0].setH0( np.array([[0], [-0.0], [0], [1], [0], [0], [0], [1], [0], [0], [0], [1]])) flexible_member.update() fus = Fuselage( m=0, pcm=np.array([0, 0, 0]), I=np.zeros((3, 3)) + 0 * np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])) # no fuselage motor1 = Engine(0, 0, 0, 0) # no engines airp = Airplane(np.array([flexible_member]), np.array([motor1]), fus) return airp
def select_vehicle(): while True: print("\nSELECT A VEHICLE") print("[1] Bicycle") print("[2] Car") print("[3] Boat") print("[4] Hovercraft") print("[5] Train") print("[6] Airplane\n") try: selection = int(input("YOUR SELECTION: ")) except ValueError: print("Only numbers please") else: command = selection break if command == 1: return Bicycle.add_to_reservation() elif command == 2: return Car.add_to_reservation() elif command == 3: return Boat.add_to_reservation() elif command == 4: return Hovercraft.add_to_reservation() elif command == 5: return Train.add_to_reservation() elif command == 6: return Airplane.add_to_reservation() else: print("Please select a number from 1 to 6")
def main(): atlas = AirportAtlas("/home/hugh/20230/project/data/airport.csv") distance = atlas.getDistance("ORK", "GWY") print(distance) print(atlas.atlas["ORK"]) print(atlas.atlas['GWY'].country) for i in atlas.atlas: if atlas.atlas[i].country == "Ireland": print(atlas.atlas[i].code) newER = ExchangeRate("/home/hugh/20230/project/data/countrycurrency.csv", "/home/hugh/20230/project/data/currencyrates.csv") newAirplane = Airplane("12345") cost = atlas.getPrice(newER, 'ORK', 'GWY', newAirplane) print("cost of flight =", cost)
def main(airport, er, currency, aircraft): newEr = ExchangeRate(currency, er) newAtlas = AirportAtlas(airport) newAirplaneList = Aircraft(aircraft) newAirplane = Airplane("12345") user_input = 0 country_search = 0 while user_input != 6: print("Please select and option: ") print("[1] Get list of airports in a particular country") print("[2] Get the aiport code of a specific airport") print( "[3] Get distance between 2 aiports (using their relevant aiport codes" ) print("[4] Get fuel cost of a journey between 2 aiports") print("[5] Get fuel price for a specific route") print("[6] Exit") print() user_input = int(input(" 1, 2, 3, 4 or 5\n")) if user_input == 1: country = input( "Please enter the country for which you want a list of airports\n" ) country_search = input( "If you would like to restrict search results to aiports starting with a specific letter, please enter letter now or press enter to skip this option" ) found_country = False found_letter = False if country_search != "": for i in newAtlas._atlas: if newAtlas._atlas[i].country == country: found_country = True if newAtlas._atlas[i].name[0] == country_search.upper( ): found_letter = True print(newAtlas._atlas[i].name) if not found_country: found_letter = True print( "Sorry we could not find a record of the country you entered\n" ) if not found_letter: print( "No airport could be found beginning withe letter '%s'" % country_search.upper()) again = repeat() if again: user_input = 0 else: user_input = 5 else: for i in newAtlas._atlas: if newAtlas._atlas[i].country == country: found = True print(newAtlas._atlas[i].name) if not found: print( "Sorry we could not find a record of the country you entered\n" ) again = repeat() if again: user_input = 0 else: user_input = 5 elif user_input == 2: name = input( "Please enter the airport for which you want a code\n") print() found = False for i in newAtlas._atlas: if newAtlas._atlas[i].name == name: print(newAtlas._atlas[i].code) found = True if not found: print( "We're sorry but we could not find an airport with the name", name, "in our database") print() print( "Please try and use the services provided to find the exact name of the airport in our database if you wish" ) again = repeat() if again: user_input = 0 else: user_input = 5 elif user_input == 3: code1 = input( "Please enter airport code of the original airport\n") code2 = input("Please enter airport code of destination airport\n") found1 = False found2 = False for i in newAtlas._atlas: if newAtlas._atlas[i].code == code1: found1 = True elif newAtlas._atlas[i].code == code2: found2 = True if found1 and found2: distance = newAtlas.getDistance(code1, code2) print("Distance between 2 airports:", distance, "km") elif not found1 and found2: print("Sorry but we could not find", code1, "in our records") elif not found2 and found1: print("Sorry but we could not find", code2, "in our records") else: print("Sorry we could not find either", code1, "or", code2, "in our records") again = repeat() if again: user_input = 0 else: user_input = 5 elif user_input == 4: code1 = input( "Please enter the airport code of the first airport\n") code2 = input( "Please enter the airport code of the destination aiport\n") airplane = input( "Please enter the code of the aircraft for the journey") newAircraft = AircraftList.createNewAircraft(airplane) if not newAircraft: again = repeat() else: found1 = False found2 = False for i in newAtlas._atlas: if newAtlas._atlas[i].code == code1: found1 = True elif newAtlas._atlas[i].code == code2: found2 = True if found1 and found2: distance = newAtlas.getDistance(code1, code2) a_range = newAircraft.getRange() if a_range >= distance: cost = newAtlas.getPrice(newEr, code1, code2, newAirplane) for i in newAtlas._atlas: if newAtlas._atlas[i].code == code1: country = newAtlas._atlas[i].country print("Fuel cost between 2 airports:", cost, "EUR") else: print( "Aircraft selected does not have the range for this journey" ) elif not found1 and found2: print("Sorry but we could not find", code1, "in our records") elif not found2 and found1: print("Sorry but we could not find", code2, "in our records") else: print("Sorry we could not find either", code1, "or", code2, "in our records") again = repeat() if again: user_input = 0 else: user_input = 5 elif user_input == 5: airport_list = [] count = 1 airport = "first" while airport != "": airport = input("Please enter airport code #" + str(count) + " or hit enter to submit") if airport != "": airport_list.append(airport) print(airport_list) i = 0 total = 0 while i < len(airport_list) - 1: found1 = False found2 = False for j in newAtlas._atlas: if newAtlas._atlas[j].code == airport_list[i]: found1 = True elif newAtlas._atlas[j].code == airport_list[i + 1]: found2 = True if found1 and found2: cost = newAtlas.getPrice(newEr, airport_list[i], airport_list[i + 1], newAirplane) total += cost elif not found1: print("Sorry we could not find a airport with the code", airport_list[i], "in our database") break else: print("Sorry we could not find a airport with the code", airport_list[i + 1], "in our database") break i += 1 if found1 and found2: for i in newAtlas._atlas: if newAtlas._atlas[i].code == airport_list[0]: country = newAtlas._atlas[i].country currency = newEr._currencyInfo[country] print("total cost:", total, currency) again = repeat() if again: user_input = 0 else: user_input = 5 elif user_input == 6: exit() else: print( "Sorry that was not a valid option, would you like to try again?" ) user_input = input("y/n?\n") if user_input == "n": user_input = 6
# coding=utf-8 import pytest from Airplane import Airplane ap = Airplane(1, 1, 1, 1) def test_Airplane_error_consumption_value(): """ Negative consumption error """ with pytest.raises(ValueError, match="Incorrect/invalid consumption with value -10."): Airplane(1, 1, -10, 0) def test_Airplane_errorr_refuel(): """ Negative refuel error """ with pytest.raises(ValueError, match="Incorrect/invalid fuel_level with value 0."): ap.refuel(0) def test_Airplane_refuel(): """ This is a perfect case! Trying to refuel correctly """ ap.refuel(99)
#!/usr/bin/python2 class Corrector(object): def __init__(self, max_correction=7.0): self._max_correction = max_correction def correct(self, angle): if angle > self._max_correction: return -self._max_correction elif angle < -self._max_correction: return self._max_correction else: return -angle if __name__ == "__main__": from Airplane import Airplane airplane = Airplane() while True: try: airplane.fly() print airplane except KeyboardInterrupt: airplane.land() break
def run(): airplanes = [] destroyed_airplanes = [] airplane = Airplane(position_vector=(70, 170), speed_vector=(50, 0), num_img=0) # Cоздаем объект airplane.set_keys(pygame.K_a, pygame.K_d, pygame.K_w, pygame.K_s, pygame.K_SPACE) second_airplane = Airplane(position_vector=(1000, 170), speed_vector=(-50, 0), num_img=1) # Cоздаем объект second_airplane.set_keys(pygame.K_LEFT, pygame.K_RIGHT, pygame.K_UP, pygame.K_DOWN, pygame.K_KP0) airplanes.append(airplane) airplanes.append(second_airplane) clock = pygame.time.Clock() # Создаем таймер для контроля фпс button_pause = Button(pos=(535, 5), path='images/buttons', image_names=('pause_off.png', 'pause_hover.png', 'pause_click.png'), function=pause, text='', w=30, h=35) interface = load_image('interface2.png', alpha_cannel=1) while len(airplanes) > 1: # главный цикл программы for e in pygame.event.get(): # цикл обработки очереди событий окна button_pause.event(e) for airplane in airplanes: airplane.event(e) if e.type == pygame.QUIT: sys.exit() # Закрытие окна программы dt = clock.tick(FPS) # Устанавливаем FPS if GAME_STATUS: for airplane in airplanes: airplane.update(dt) screen.blit(BACKGROUND, (0, 0)) if len(airplanes) > 1: airplanes[0].collide_bullet_with_airplane(airplanes[1]) airplanes[1].collide_bullet_with_airplane(airplanes[0]) for airplane in airplanes: airplane.render(screen) for airplane in airplanes: if airplane.status_airplane == False: destroyed_airplanes.append(airplane) airplanes.remove(airplane) for airplane in destroyed_airplanes: airplane.render(screen) screen.blit(interface, (0, 0)) button_pause.update(dt) button_pause.render(screen) for airplane in airplanes: airplane.render_hp(screen) pygame.display.flip() # отображаем на мониторе все, что нарисовали на экране start_game()
def __createAirplaneFromData(data): # Create an airplane from data coming from the database available_seats = AirplaneRepository.__availableSeats(data[0]) airplane = Airplane(data[0], data[1], data[2], data[3], data[4], data[5], data[6], available_seats) return airplane