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)
示例#2
0
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)
示例#3
0
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)
示例#4
0
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)
示例#5
0
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)
示例#6
0
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))
示例#7
0
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))
示例#8
0
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))
示例#9
0
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))
示例#10
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)
示例#11
0
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')
示例#12
0
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)
示例#13
0
"""
User interface for module currency

When run as a script, this module prompts the user for two currencies and
amount.
It prints out the result of converting the first currency to the second.

Author: Aion Ashby and Maxine Nzegwu and Nnenna Dara
Date:   7 September 2019
"""

import a1

original = input('3-letter code for original currency: ')
new = input('3-letter code for the new currency: ')
amount = input('Amount of the original currency: ')
print('You can exchange ' + amount + ' ' + original + ' for ' +\
 str(a1.exchange(original, new, float(amount))) + ' ' + new + '.')
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: ')
            amt = input('Enter original amount: ')
        else:
            break

print('Source currency has Error: ' + str(a1.is_currency(src)))
print('Destination Currency has Error: ' + str(a1.is_currency(dst)))
a, b = a1.exchange(src, dst, amt)
print('You can exchange ' + a + ' for ' + b)
示例#15
0
文件: a1app.py 项目: tx58/origin
"""
User interface for module currency

When run as a script, this module prompts the user for two currencies and amount.
It prints out the result of converting the first currency to the second.

Author: Tianli Xia
Date:   Sep 11th, 2018
"""

import introcs
import a1

currency_from = input("3-letter code for original currency:")
currency_to = input("3-letter code for the new currency:")
amount_from = input("Amount of the original currency:")
amount_to = a1.exchange(currency_from, currency_to, amount_from)
print("You can exchange " + str(amount_from) + " " + currency_from.upper() +
      " for " + str(amount_to) + " " + currency_to.upper() + '.')
"""
User interface for module currency

When run as a script, this module prompts the user for two currencies and
an amount. It prints out the result of converting the first currency to
the second.

Author: Oscar So (ons4), Jee-In Lee (jl3697)
Date:   September 11, 2019
"""

import a1
currency_from = input("Enter source currency: ")
currency_to = input("Enter target currency: ")
amount_from = float(input("Enter original amount: "))
print("You can exchange " + str(amount_from) + " " + currency_from 
        + " for " + str(a1.exchange(currency_from, currency_to, amount_from))
        + " " + currency_to + ".")
示例#17
0
"""
User interface for module currency

When run as a script, this module prompts the user for two currencies
and amount.
It prints out the result of converting the first currency to the second.

Author: Robel Ayalew rsa83 
Date:   9/19/18
"""
import a1

first = str(input("3-letter code for original currency: "))
second = str(input("3-letter code for the new currency: "))
last = float(input("Amount of the original currency: "))

a = a1.exchange(first, second, last)

print ("You can exchange " + str(last) + " " + first + " for " + str(a) + " " +
      second + ".")