def setUp(self): self.myAircraft = Aircraft() self.myAtlas = AirportAtlas() self.myAirport = AirportAtlas() self.myCurrencyAtlas = CountryCurrencyAtlas() self.myBuilder = BuildItinerary(self.myAtlas, self.myCurrencyAtlas, self.myAircraft) self.knownAircraftValues = (("737", 5600, "Boeing", 9012.304), ("A320", 12000, "Airbus", 12000), ("777", 9700, "Boeing")) #code, range, maker, rangeKM self.testPlane1 = Aircraft("737") self.testPlane2 = Aircraft("A320") self.testPlane3 = Aircraft("777") ############### Test Cheapest Fuel Rate ############ self.knownCurrencyDetails = (("DUB to Euro = ", 1, "country =", "IRELAND"), ("GBP to Euro = ", 1.4029, "country =", "UNITED KINGDOM")) self.knownDistances = (("DUB to LHR KM= ", 448.8922295538067), ("SYD to JFK KM= ", 16013.523728949884), ("DUB to DUB KM= ", 0)) self.myCurrency = CountryCurrencyAtlas() self.testAirportCurrencyDUB = self.myCurrency.getCurrency(self.myAirport.airportDic["DUB"].country.upper()) self.testAirportCurrencyLHR = self.myCurrency.getCurrency(self.myAirport.airportDic["LHR"].country.upper()) ########### Test Distances ########## self.testAirportDUB = self.myAirport.airportDic["DUB"] self.testAirportLHR = self.myAirport.airportDic["LHR"] self.testAirportSYD = self.myAirport.airportDic["SYD"] self.testAirportJFK = self.myAirport.airportDic["JFK"] # self.testAirportINVALID = self.myAirport.airportDic["lll"] # self.testAirportINVALID = self.myAirport.airportDic["123"] # self.testAirportINVALID = self.myAirport.airportDic["12"] # self.testAirportINVALID = self.myAirport.airportDic["ll"] # ############### Test Cheapest Fuel Rate ############ # self.knownFuelRates = ((), ()) # self.testRoute1 = self.myBuilder.itineraryList[0] # self.testRoute3 = self.myBuilder.itineraryList[2] ########### Test Permutation number ########## self.testAirportCodes = ["DUB", "MAN", "ORD", "PPP", "ORK"]
def main(): #### instanciating relevant classes myAircraft = Aircraft() myAtlas = AirportAtlas() myCurrencyAtlas = CountryCurrencyAtlas() myItinerary = BuildItinerary(myAtlas, myCurrencyAtlas, myAircraft) #################################################################################################################################################################################### RUN_UI_loopControl = True #Main control loop for the UI. If user chooses to quit, "return = False" will end this. while RUN_UI_loopControl: menuChoice = menu() #To get user's choice, we call menu() function. This returns user's menuChoice. if menuChoice == "Q": #To Quit print("Goodbye, have a nice day") return False #### #### Airport Details if menuChoice == "A" : loop_A = True #Airport loop. Set to False to break loop. while loop_A: #loops until satisfactory input attained airportChoice = str.upper(input("choose Airport ")) if len(airportChoice)<3 or len(airportChoice)>3: #ensures input conforms code naming standard print ("Choice must be 3 digits long. ") elif not airportChoice in myAtlas.airportDic: #Confirms code in AirportDictionary print ("Invalid Airport.... Try again. ") elif airportChoice in myAtlas.airportDic: #If it is, details are returned port = myAtlas.getAirport(airportChoice) print("Chosen Airport: {} {} {} {}".format(port.airportName, port.country, port.latitude, port.longitude,)) ReturnQuit_loopControl = True #enters loop to query if to return to menu or quit. while ReturnQuit_loopControl == True: #loops until satisfactory input attained returnOrQuit = str.upper(input("(R) = Return to Menu. (Q) = Quit ")) if len(returnOrQuit)<1 or len(returnOrQuit)>1: print ("Choice must be 1 letter") elif not returnOrQuit in "RQ": print ("please choose one from menu list") elif returnOrQuit == "R": print("Returning to Menu!") # returnOrQuit = menu() ReturnQuit_loopControl = False #breaks loop querying if to return to menu or quit loop_A = False # breaks Airport loop and breaks the elif returnOrQuit == "Q": print("Goodbye!") return False #### #### Calculate cheapest route if menuChoice == "C": loop_C = True while loop_C: CSVin_loopControl = True while CSVin_loopControl: #loop until satisfactory input achieved. CustomCSV_in = str(input("Please name of .csv file of itineraries you wish to use -- ENDING with .csv ")) if len(CustomCSV_in)<5: #5 covers the .csv + 1 letter required for name. print ("Filename must be atleast 1 letter with .CSV ending.") elif not ".csv" in CustomCSV_in: print ("Filename must be atleast 1 letter with .CSV ending.") else: CSVin_loopControl = False CSVout_loopControl = True while CSVout_loopControl: CustomCSV_out = str(input("Please type .csv file you wish to write to (.csv included) ")) if len(CustomCSV_out)<5: #5 covers the .csv + 1 letter required for name. print ("Filename must be atleast 1 letter with .CSV ending.") elif not ".csv" in CustomCSV_out: print ("Filename must be atleast 1 letter with .CSV ending.") else: custom_cheapest_route = BuildItinerary(myAtlas, myCurrencyAtlas, myAircraft, CustomCSV_in, CustomCSV_out) CSVout_loopControl = False ReturnQuit_loopControl = True while ReturnQuit_loopControl == True: returnOrQuit = str.upper(input("(R) = Return to Menu. (Q) = Quit ")) if len(returnOrQuit)<1 or len(returnOrQuit)>1: print ("Choice must be 1 letter") elif not returnOrQuit in "RQ": print ("please choose one from menu list") elif returnOrQuit == "R": print("Returning to Menu!") ReturnQuit_loopControl = False loop_C = False ### change to loop = false elif returnOrQuit == "Q": print("Goodbye!") RUN_UI_loopControl == False return False #### #### Input custom itinerary if menuChoice == "I" : loop_D = True while loop_D: # customRoute = ["SNN","ORK","MAN","CDG","SIN"] customRoute=[] #appends the user's chosen airports customItinerary = [] #appending each itinerary (made of routes objects and aircraft object) customItineraryList = [] #appends customItinerary to a list, as the method for caluclating shortest # distance will iterate through a list for i in range (0, 5): # 5 airports + the first repeated. userAirport_loopControl = True while userAirport_loopControl: ##If statments allow active string printing when requesting input. if i == 0: whatUserIsEntering = "home airport: " elif i == 1: whatUserIsEntering = "2nd airport: " elif i == 2: whatUserIsEntering = "3rd airport: " elif i == 3: whatUserIsEntering = "4th airport: " elif i == 4: whatUserIsEntering = "5th airport: " userAirport_i_input= str.upper(input("Choose " + str(whatUserIsEntering))) userAirport_input = userAirport_i_input if userAirport_input not in myAtlas.airportDic: print ("Invalid Airport.... Try again") else: # customRoute.append(myAtlas.getAirport(userAirport_input)) customRoute.append(userAirport_input) # print(customRoute) userAirport_loopControl = False userAircraft_loopControl = True print ("List of available Aircrafts:\n" "Airbus = A319, A320, A321, A330, \n" "Boeing = 737, 747, 757, 767, 777, \n" "Other = BAE1, DC8, F50, MD11, A400M, C212, V22") while userAircraft_loopControl: userAircraft_input= str.upper(input("Choose aircraft: " )) if userAircraft_input not in myAircraft.aircraftDic: print ("Invalid Aircraft.... Try again") else: userAircraft_loopControl = False try: customAircraft = userAircraft_input #creating airport and aircraft objects by passing user input through to Itinerary class customItinerary = Itinerary(customRoute, customAircraft, myAtlas) #appending itinerary to list, to allow iteration wheb calculating cheapetest distance. customItineraryList.append(customItinerary) except KeyError: continue #continues with loop if airport code KEY not found #permutates custom route permutatedCustomItineraryList = myItinerary.permutateItineraryList(customItinerary.routes) #calculates cheapest route of all permutations of custom route. cheapestCustomRoute = myItinerary.findCheapestDistance(myAtlas, myCurrencyAtlas, permutatedCustomItineraryList, customItineraryList) cheapestCustomRouteList = [cheapestCustomRoute] exhangeRateRanking_List = myItinerary.rankExchangeRates(myCurrencyAtlas,customItineraryList ) numberToRanking_List = myItinerary.addNumberToRanking(exhangeRateRanking_List) quantityToFuelAtHome_List = myItinerary.efficientFuelingAtHome(myAircraft, myCurrencyAtlas, numberToRanking_List, myAtlas, cheapestCustomRoute, customItineraryList ) myItinerary.printCheapest(cheapestCustomRouteList, customItineraryList, quantityToFuelAtHome_List) ReturnQuit_loopControl = True while ReturnQuit_loopControl == True: returnOrQuit = str.upper(input("(R) = Return to Menu. (Q) = Quit ")) if len(returnOrQuit)<1 or len(returnOrQuit)>1: print ("Choice must be 1 letter") elif not returnOrQuit in "RQ": print ("please choose one from menu list") elif returnOrQuit == "R": print("Returning to Menu!") ReturnQuit_loopControl = False loop_D = False elif returnOrQuit == "Q": print("Goodbye!") return False #### #### Country currencty details if menuChoice == "M" : loop_M = True while loop_M: countryChoice = str.upper(input("Choose country to find it's currency ")) if len(countryChoice)<3: print ("Choice must be atleast 3 letters long") elif countryChoice.isdigit(): #country should be only letters. print ("letters only") #country must be one of the keys to the countryCurrencyDictioanry elif not countryChoice in myCurrencyAtlas.countryCurrencyDic: print ("please choose a Country from the list") elif countryChoice in myCurrencyAtlas.countryCurrencyDic: currency = (myCurrencyAtlas.getCurrency(countryChoice)) print(currency) print("Chosen country: {} currencyName: {} toEuro: {} fromEuro: {} countryCode: {}" .format(currency.countryName, currency.currencyName, currency.toEuro, currency.fromEuro, currency.countryCode)) ReturnQuit_loopControl = True while ReturnQuit_loopControl == True: returnOrQuit = str.upper(input("(R) = Return to Menu. (Q) = Quit ")) if len(returnOrQuit)<1 or len(returnOrQuit)>1: print ("Choice must be 1 letter") elif not returnOrQuit in "RQ": print ("please choose one from menu list") elif returnOrQuit == "R": print("Returning to Menu!") ReturnQuit_loopControl = False loop_M = False elif returnOrQuit == "Q": print("Goodbye!") return False #### #### Aircraft Details if menuChoice == "P": loop_P = True while loop_P: aircraftList = ["A319", "A320", "A321", "A330", "737", "747", "757", "767", "777", "BAE1", "DC8", "F50", "MD11", "A400M", "C212", "V22"] print ("Please choose from the following:\n" "Airbus = 1.A319, 2.A320, 3.A321, 4.A330, \n" "Boeing = 5.737, 6.747, 7.757, 8.767, 9.777, \n" "Other = 10.BAE1, 11.DC8, 12.F50, 13.MD11, 14.A400M, 15.C212, 16.V22") aircraftChoice = str.upper(input("choose Aircraft ")) if len(aircraftChoice)<3 or len(aircraftChoice)>5: print ("Choice must be 3-5 long") ##accounts for all lengths of aircrafts elif not aircraftChoice.isalnum(): print ("letters/ numbers only") #allows numbers and letters elif not aircraftChoice in aircraftList: print ("please choose Aircraft from the list") elif aircraftChoice in aircraftList: craft = (myAircraft.getPlane(aircraftChoice)) print("Chosen Plane: {} Plane Type: {} Imperial/Metric: {} Manufacturer: {} Range: {}" .format(craft[0], craft[1], craft[2], craft[3], craft[4])) ReturnQuit_loopControl = True while ReturnQuit_loopControl == True: returnOrQuit = str.upper(input("(R) = Return to Menu. (Q) = Quit ")) if len(returnOrQuit)<1 or len(returnOrQuit)>1: print ("Choice must be 1 letter") elif not returnOrQuit in "RQ": print ("please choose one from menu list") elif returnOrQuit == "R": print("Returning to Menu!") ReturnQuit_loopControl = False loop_P = False elif returnOrQuit == "Q": print("Goodbye!") return False
class KnownValues (unittest.TestCase): def setUp(self): self.myAircraft = Aircraft() self.myAtlas = AirportAtlas() self.myAirport = AirportAtlas() self.myCurrencyAtlas = CountryCurrencyAtlas() self.myBuilder = BuildItinerary(self.myAtlas, self.myCurrencyAtlas, self.myAircraft) self.knownAircraftValues = (("737", 5600, "Boeing", 9012.304), ("A320", 12000, "Airbus", 12000), ("777", 9700, "Boeing")) #code, range, maker, rangeKM self.testPlane1 = Aircraft("737") self.testPlane2 = Aircraft("A320") self.testPlane3 = Aircraft("777") ############### Test Cheapest Fuel Rate ############ self.knownCurrencyDetails = (("DUB to Euro = ", 1, "country =", "IRELAND"), ("GBP to Euro = ", 1.4029, "country =", "UNITED KINGDOM")) self.knownDistances = (("DUB to LHR KM= ", 448.8922295538067), ("SYD to JFK KM= ", 16013.523728949884), ("DUB to DUB KM= ", 0)) self.myCurrency = CountryCurrencyAtlas() self.testAirportCurrencyDUB = self.myCurrency.getCurrency(self.myAirport.airportDic["DUB"].country.upper()) self.testAirportCurrencyLHR = self.myCurrency.getCurrency(self.myAirport.airportDic["LHR"].country.upper()) ########### Test Distances ########## self.testAirportDUB = self.myAirport.airportDic["DUB"] self.testAirportLHR = self.myAirport.airportDic["LHR"] self.testAirportSYD = self.myAirport.airportDic["SYD"] self.testAirportJFK = self.myAirport.airportDic["JFK"] # self.testAirportINVALID = self.myAirport.airportDic["lll"] # self.testAirportINVALID = self.myAirport.airportDic["123"] # self.testAirportINVALID = self.myAirport.airportDic["12"] # self.testAirportINVALID = self.myAirport.airportDic["ll"] # ############### Test Cheapest Fuel Rate ############ # self.knownFuelRates = ((), ()) # self.testRoute1 = self.myBuilder.itineraryList[0] # self.testRoute3 = self.myBuilder.itineraryList[2] ########### Test Permutation number ########## self.testAirportCodes = ["DUB", "MAN", "ORD", "PPP", "ORK"] def test_results_of_aircraft(self): Aircraft1_range = self.testPlane1.planeRange #tests converted to KM also Aircraft1_manufacturer = self.testPlane1.planeManufacturer Aircraft2_range = self.testPlane2.planeRange Aircraft2_manufacturer = self.testPlane2.planeManufacturer ## the result of the test method "Aircraft1_range" should == the known value tuple position self.assertEqual(self.knownAircraftValues[0][3], Aircraft1_range) self.assertEqual(self.knownAircraftValues[0][2], Aircraft1_manufacturer) ## the result of the test method "Aircraft1_range" should == the known value tuple position self.assertEqual(self.knownAircraftValues[1][3], Aircraft2_range) self.assertEqual(self.knownAircraftValues[1][2], Aircraft2_manufacturer) def test_currency_details(self): DUB_currency_test_toEuro = self.testAirportCurrencyDUB.toEuro DUB_currency_test_country = self.testAirportCurrencyDUB.countryName LHR_currency_test_toEuro = self.testAirportCurrencyLHR.toEuro LHR_currency_test_country = self.testAirportCurrencyLHR.countryName self.assertEqual(self.knownCurrencyDetails[0][1], DUB_currency_test_toEuro) self.assertEqual(self.knownCurrencyDetails[0][3], DUB_currency_test_country) self.assertEqual(self.knownCurrencyDetails[1][1], LHR_currency_test_toEuro) self.assertEqual(self.knownCurrencyDetails[1][3], LHR_currency_test_country) def test_distance_of_airports(self): Airport_distance_LHR_DUB = self.myAtlas.getDistanceBetweenAirports(self.testAirportDUB.airportCode, self.testAirportLHR.airportCode) Airport_distance_SYD_JFK = self.myAtlas.getDistanceBetweenAirports(self.testAirportSYD.airportCode, self.testAirportJFK.airportCode) Airport_distance_DUB_DUB = self.myAtlas.getDistanceBetweenAirports(self.testAirportDUB.airportCode, self.testAirportDUB.airportCode) # Airport_distance_DUB_INVALID = self.myAtlas.getDistanceBetweenAirports(self.testAirportDUB.airportCode, self.testAirportINVALID.airportCode) self.assertEqual(self.knownDistances[0][1], Airport_distance_LHR_DUB) self.assertEqual(self.knownDistances[1][1], Airport_distance_SYD_JFK) self.assertEqual(self.knownDistances[2][1], Airport_distance_DUB_DUB) self.assertEqual(self.knownDistances[2][1], Airport_distance_DUB_DUB) def test_missing_input_file(self): ##Commented out as designed to fail, which it does. ### tests invalid file to FileNotFoundError self.assertRaises(FileNotFoundError, self.myAtlas.buildAirportDic, "cookie.csv") def test_permutation_number(self): Code_Permutation_Tester = self.myBuilder.permutateItineraryList(self.testAirportCodes) self.assertEqual(len(Code_Permutation_Tester), 24) ######## System Test ######### def test_airport_correct_currency(self): Test_Airport_Currency_DUB_EURO = self.myCurrencyAtlas.getCurrency(self.myAtlas.getAirport("DUB").country).currencyName Test_Airport_Currency_DUB_RATE = self.myCurrencyAtlas.getCurrency(self.myAtlas.getAirport("DUB").country).toEuro Test_Airport_Currency_LHR_EURO = self.myCurrencyAtlas.getCurrency(self.myAtlas.getAirport("LHR").country).currencyName Test_Airport_Currency_LHR_RATE = self.myCurrencyAtlas.getCurrency(self.myAtlas.getAirport("LHR").country).toEuro # Test_Airport_Currency_DUB_EURO = self.myCurrencyAtlas.getCurrency(self.testAirportDUB.country()).currencyName # Test_Airport_Currency_DUB_RATE = self.myCurrencyAtlas.getCurrency(self.testAirportDUB.country()).toEuro # Test_Airport_Currency_LHR_EURO = self.myCurrencyAtlas.getCurrency(self.testAirportLHR.country()).currencyName # Test_Airport_Currency_LHR_RATE = self.myCurrencyAtlas.getCurrency(self.testAirportLHR.country()).toEuro self.assertEquals = (Test_Airport_Currency_DUB_EURO, "Euro") self.assertEquals = (Test_Airport_Currency_DUB_RATE, 1) self.assertEquals = (Test_Airport_Currency_LHR_EURO, "British Pound") self.assertEquals = (Test_Airport_Currency_LHR_RATE, 1.4029)