def testD(): "test procedure for part D" # Test is_currency cornell.assert_equals(True, a1.iscurrency('USD')) cornell.assert_equals(True, a1.iscurrency('SAR')) cornell.assert_equals(False, a1.iscurrency(' ')) cornell.assert_equals(False, a1.iscurrency('sar')) #Test Exchange cornell.assert_floats_equal(112.518, a1.exchange('USD', 'SAR', 30))
def testD(): """ Test procedure for Part D """ print('Testing function iscurrency(currency)') result = a1.iscurrency('United') introcs.assert_equals(False, result) result = a1.iscurrency('USD') introcs.assert_equals(True, result) print('The module is working correctly') print('Testing function exchange(currency_from, currency_to, amount_from)') result = a1.exchange('USD', 'EUR', 2.0) introcs.assert_floats_equal(1.727138, result) print('The module is working correctly')
def testD(): """Test procedure for functions iscurrency and exchange""" #Test case for valid iscurrency result24 = a1.iscurrency('USD') cornell.assert_equals = (True, result24) #test case for invalid iscurrency result25 = a1.iscurrency('AAA') cornell.assert_equals = (False, result25) #Test case for invalid iscurrency result26 = a1.iscurrency('usd') cornell.assert_equals = (False, result26) #Test case for valid exchange result27 = a1.exchange('USD','HKD',1.0) cornell.assert_floats_equal(7.82541, result27)
def testD(): # TEST ONE print 'Testing function iscurrency 1' result = a1.iscurrency('USD') cornelltest.assert_equals(True, result) # TEST TWO print 'Testing function iscurrency 2' result = a1.iscurrency('ZZK') cornelltest.assert_equals(False, result) # TEST ONE print 'Testing function exchange 1' result = a1.exchange('USD', 'EUR', 2.5) cornelltest.assert_equals(2.24075, result) # TEST ONE print 'Testing function exchange 2' result = a1.exchange('GEL', 'SOS', 0.0) cornelltest.assert_equals(0.0, result)
def testD(): """Test procedure for Part A""" result = a1.iscurrency('USD') cornell.assert_true(True) result = a1.iscurrency('') cornell.assert_equals(False, result) result = a1.iscurrency('E') cornell.assert_equals(False, result) result = a1.iscurrency('zxcvbn') cornell.assert_equals(False, result) result = a1.exchange('USD', 'EUR', 2.5) cornell.assert_floats_equal(2.0952375, result) result = a1.exchange('SVC', 'GEL', 3.5254023347401) cornell.assert_floats_equal(1, result) result = a1.exchange('USD', 'EUR', 3) cornell.assert_floats_equal(2.514285, result)
def testD(): result = a1.iscurrency('AED') cornelltest.assert_true(result == True) result = a1.iscurrency('LOL') cornelltest.assert_true(result == False) result = a1.iscurrency('MOM') cornelltest.assert_true(result == False) result = a1.iscurrency('USD') cornelltest.assert_true(result == True) #Test exchange(currency_from, currency_to, amount_from) result = a1.exchange('USD', 'EUR', 2.5) cornelltest.assert_floats_equal(2.24075, result) result = a1.exchange('CAD', 'CNY', 1.0) cornelltest.assert_floats_equal(5.1369278716282, result) result = a1.exchange('CAD', 'CNY', 1.09) cornelltest.assert_floats_equal(5.5992513800748, result) result = a1.exchange('CAD', 'CNY', 1.09999) cornelltest.assert_floats_equal(5.6505692895124, result)
def testD(): """Prints: "Module al passed all tests" if all tests successful. Precondition: a1 is a module that contains functions iscurrency() and exchange()""" print "Testing functions iscurrency() and exchange()" A = "LOL" B = "USD" C = "XBT" D = "LOLOL" E = "usd" cornelltest.assert_equals(False, a1.iscurrency(A)) cornelltest.assert_equals(True, a1.iscurrency(B)) cornelltest.assert_equals(True, a1.iscurrency(C)) cornelltest.assert_equals(False, a1.iscurrency(D)) cornelltest.assert_equals(False, a1.iscurrency(E)) cornelltest.assert_floats_equal(36.88680000000000, a1.exchange("USD", "RUB", 1.0)) cornelltest.assert_floats_equal(1.00000000000000, a1.exchange("USD", "USD", 1.0)) cornelltest.assert_floats_equal(0.08735622000000, a1.exchange("USD", "XBT", 42.0))
def testD(): """Returns:'Module name is working correctly' if functions iscurrency and exchange test cases work.""" #First is_currency test case result = a1.iscurrency('USD') cornelltest.assert_equals(True, result) #Second is_currency test case suggested by Consultant Nancy Shen (nws37) result = a1.iscurrency('hi') cornelltest.assert_equals(False, result) #End Nancy's suggestion #Third is_currency test case result = a1.iscurrency('usd') cornelltest.assert_equals(False, result) #First exchange test case result = a1.exchange('USD', 'EUR', 2.5) cornelltest.assert_equals(2.24075, result) #Second test case result = a1.exchange('BBD', 'USD', 3000) cornelltest.assert_equals(1500, result)
def exchange(currency_from, currency_to, amount_from): """ Returns: amount of currency received in the given exchange. In this exchange, the user is changing amount_from money in currency currency_from to the currency currency_to. The value returned represents the amount in currency currency_to. The value returned has type float. Parameter currency_from: the currency on hand (the LHS) Precondition: currency_from is a string for a valid currency code Parameter currency_to: the currency to convert to (the RHS) Precondition: currency_to is a string for a valid currency code Parameter amount_from: amount of currency to convert Precondition: amount_from is a float """ if (a1.iscurrency(currency_from) and a1.iscurrency(currency_to)): response = a1.passcurrency_response(currency_from, currency_to, amount_from) if (has_error(response)): print("Has an error: not valid url.") return else: src = (a1.get_src(response)) dst = (a1.get_dst(response)) src_num = a1.before_space(src) src_currency = a1.after_space(src) dst_num = a1.before_space(dst) dst_currency = a1.after_space(dst) return float(dst_num) else: print("Has an error: not valid currency.") return