def testD(sd0, sd1, sd2, sd3): """Test procedure for Part D sd0: 'USD' 'USA' 'USD' '' sd1: src='USD', dst='CUP', amt=2.5 src='USA', dst='BBB', amt='steve' src='USD', dst='CUP', amt=2.5 src='', dst='', amt='' """ a1.is_currency(sd0) a1.exchange(sd1, sd2, sd3)
def testD(): """ Test procedure for Part D """ #tests valid currency result = a1.is_currency('USD') introcs.assert_equals(True, result) #tests invalid currency result = a1.is_currency('CBD') introcs.assert_equals(False, result) #testing exchange result = a1.exchange('USD', 'CUP', 2.5) introcs.assert_floats_equal(64.375, result) #testing longer exchange result = a1.exchange('TTD', 'JMD', 2.5) introcs.assert_floats_equal(48.690190282653, result)
def testD(): """ Test functions iscurrency(), and exchange() """ #test valid currency introcs.assert_true(a1.is_currency("USD")) #test invalid currency introcs.assert_equals(False, a1.is_currency("ABC")) #test invalid currency (>3 letters) introcs.assert_equals(False, a1.is_currency("invalid")) #test invalid currency (<3 letters) introcs.assert_equals(False, a1.is_currency("hi")) #testing a valid currency to a different valid currency introcs.assert_equals(64.375, a1.exchange("USD", "CUP", 2.5)) #testing a valid to itself introcs.assert_equals(2.5, a1.exchange("USD", "USD", 2.5))
def testD(): """ Test procedure for Part D """ #test procedures for a1.is_currency: a1.is_currency returns #True if currency #is a valid (3 letter code for a currency. It returns False otherwise. #For example, #for the strings "USD", "HKD", "EUR", they are valid three letter, #all capitalized #abbreviations of currency, so the function a1.is_currency returns True. #For the strings #"ABC", "usd", "Euros", they are not valid forms of currency, #not properly capitalized, #nor abbreviated properly, respectively. introcs.assert_equals(True, a1.is_currency("USD")) #same as above for HKD introcs.assert_equals(True, a1.is_currency("HKD")) #same as above for EUR introcs.assert_equals(True, a1.is_currency("EUR")) #same as above for ABC introcs.assert_equals(False, a1.is_currency("ABC")) #same as above for usd introcs.assert_equals(False, a1.is_currency("usd")) #same as above for Euros introcs.assert_equals(False, a1.is_currency("Euros")) #test procedures for a1.exchange: a1.exchange returns the amount of #currency received in the given exchange. The user is changing amount #_from money in currency currency_from to the currency currency_to. #The float value returned represents the amount in currency currency_to. #When exchanging 100.0 Euros to Hong Kong Dollars, the function a1.exchange #returns 882.72655789045 Hong Kong Dollars. When exchanging 100.0 United #States Dollars to Hong Kong Dollars, the function a1.exchange returns #782.455 Hong Kong Dollars. introcs.assert_equals(882.72655789045, a1.exchange("EUR", "HKD", 100.0)) #same as above different exchanges introcs.assert_equals(782.455, a1.exchange("USD", "HKD", 100.0))
src = input('Enter source currency: ') dst = input('Enter target currency: ') amt = input('Enter original amount: ') """src_bool=a1.is_currency(src) print('Source currency has Error: '+str(src_bool)) dst_bool=a1.is_currency(dst) print('Destination Currency has Error: '+str(dst_bool)) if src_bool==True: print('Please Re-Enter.') elif dst_bool==True: print('Please Re-Enter.') else: a,b=a1.exchange(src,dst,amt) print ('You can exchange '+a+' for '+b)""" while a1.is_currency(src) == True: print('Source currency has Error: ' + str(a1.is_currency(src))) print('Please Re-Enter') src = input('Enter source currency: ') while a1.is_currency(dst) == True: print('Destination Currency has Error: ' + str(a1.is_currency(dst))) print('Please Re-Enter') dst = input('Enter target currency: ') while a1.amt_has_error(src, dst, amt) == True: print('Currency amount is not a numerical value. Please Re-Enter.') amt = input('Enter original amount: ') a1.amt_has_error(src, dst, amt) while a1.amt_has_error(src, dst, amt) == False: if float(amt) < 0: print('Currency amount invalid. Please Re-Enter: ')