Beispiel #1
0
def testC():
    """
    Test functions currency_response()
    """

    #testing converting to the same currency
    introcs.assert_equals(
        '{ "ok":true, "lhs":"2.5 Australian Dollars",' +
        ' "rhs":"2.5 Australian Dollars", "err":""' + ' }',
        a1.currency_response("AUD", "AUD", 2.5))

    #testing converting between 2 different currencies
    introcs.assert_equals(
        '{ "ok":true, "lhs":"2.5 Australian Dollars",' +
        ' "rhs":"1.7551668602031 United States Dollars", "err":"" }' + '',
        a1.currency_response("AUD", "USD", 2.5))

    #testing invalid source currency
    introcs.assert_equals(
        '{ "ok":false, "lhs":"", "rhs":"", "err":"Source ' +
        'currency code is invalid." }',
        a1.currency_response("abc", "USD", 2.5))

    #testing 2 invalid currencies
    introcs.assert_equals(
        '{ "ok":false, "lhs":"", "rhs":"", "err":"Source' +
        ' currency code is invalid." }',
        a1.currency_response("abc", "def", 2.5))

    #testing invalid exchange currency
    introcs.assert_equals(
        '{ "ok":false, "lhs":"", "rhs":"", "err":"' +
        'Exchange currency code is invalid.' + '" }',
        a1.currency_response("USD", "def", 2.5))
Beispiel #2
0
def testC():
    "test procedure for part C"

    #Test for Currency Response
    cornell.assert_equals(
        '{ "success" : true, "lhs" : "30000 United States Dollars", "rhs" : "112518 Saudi Riyals", "error" : "" }',
        a1.currency_response('USD', 'SAR', 30000))
    cornell.assert_equals(
        '{ "success" : true, "lhs" : "2 United States Dollars", "rhs" : "1.67619 Euros", "error" : "" }',
        a1.currency_response('USD', 'EUR', 2))
    cornell.assert_equals(
        '{ "success" : true, "lhs" : "0 Dominican Pesos", "rhs" : "0 Saudi Riyals", "error" : "" }',
        a1.currency_response('DOP', 'SAR', 0.0))
Beispiel #3
0
def testC():
    #   TEST ONE
    print 'Testing function currency_response 1'
    result = a1.currency_response('USD', 'EUR', 2.5)
    cornelltest.assert_equals(
        '{ "from" : "2.5 United States Dollars", "to" : "2.24075 Euros", "success" : true, "error" : "" }',
        result)
    #   TEST TWO
    print 'Testing function currency_response 2'
    result = a1.currency_response('TND', 'BDT', 3453.67)
    cornelltest.assert_equals(
        '{ "from" : "3453.67 Tunisian Dinar", "to" : "122560.93186266 Bangladeshi Taka", "success" : true, "error" : "" }',
        result)
def testC():
    """Returns:'Module name is working correctly' if function currency_response
    test cases work."""
    #First test case
    result = a1.currency_response('USD', 'EUR', 2.5)
    cornelltest.assert_equals(
        '{ "from" : "2.5 United States Dollars", "to" ' +
        ': "2.24075 Euros", "success" : true, "error" ' + ': "" }', result)

    #Second test case
    result = a1.currency_response('BBD', 'USD', 3000)
    cornelltest.assert_equals(
        '{ "from" : "3000 Barbadian Dollars", "to" : ' +
        '"1500 United States Dollars", "success" : ' + 'true, "error" : "" }',
        result)
Beispiel #5
0
def testC():
    #Test case 1
    result = a1.currency_response('USD', 'EUR', 2.5)
    cornelltest.assert_equals(
        '{ "from" : "2.5 United States Dollars", "to"' +
        ' : "2.24075 Euros", "success" : true, "error" : "" }', result)
    result = a1.currency_response('USD', 'ETB', 1.0)
    cornelltest.assert_equals(
        '{ "from" : "1 United States Dollar", "to"' +
        ' : "22.09099 Ethiopian Birr", "success" : true, "error" : "" }',
        result)
    result = a1.currency_response('ETB', 'USD', 22.09099)
    cornelltest.assert_equals(
        '{ "from" : "22.09099 Ethiopian Birr", "to"' +
        ' : "1 United States Dollar", "success" : true, "error" : "" }',
        result)
def testC(sc1, sc2, sc3):
    """Test procedure for Part C

     sc1= src=USD, dst=CUP, amt=2.5
     sc2= src=USA, dst=BBB, amt=steve
     sc3= src='', dst='', amt='' """
    a = a1.currency_response(sc1, sc2, sc3)
    print(a)
Beispiel #7
0
def testC():
    """Test procedure for Part C"""
    result = a1.currency_response('USD', 'EUR', 2.5)
    cornell.assert_equals(
        '{ "success" : true, "lhs" : "2.5 United States Dollars", "rhs" : "2.0952375 Euros", "error" : "" }',
        result)
    result = a1.currency_response('p', 'EUR', 2.5)
    cornell.assert_equals(
        '{ "success" : false, "lhs" : "", "rhs" : "", "error" : "Source currency code is invalid." }',
        result)
    result = a1.currency_response('USD', 'y', 2.5)
    cornell.assert_equals(
        '{ "success" : false, "lhs" : "", "rhs" : "", "error" : "Exchange currency code is invalid." }',
        result)
    result = a1.currency_response('qwerty', 'asdfgh', 2)
    cornell.assert_equals(
        '{ "success" : false, "lhs" : "", "rhs" : "", "error" : "Source currency code is invalid." }',
        result)
Beispiel #8
0
def testC():
    """
    Test procedure for Part C
    """

    print('Testing function currency_response(currency_from,\
     currency_to, amount_from)')
    last = a1.currency_response('USD', 'EUR', 2.5)
    introcs.assert_equals('{ "src" : "2.5 United States Dollars", "dst"'+\
    ' : "2.1589225 Euros", "valid" : true, "error" : "" }', last)
    last = a1.currency_response('United', 'EUR', 2.5)
    introcs.assert_equals('{ "src" : "", "dst" : "", "valid" : '+\
    'false, "error" : "Source currency code is invalid." }', last)
    last = a1.currency_response('USD', 'Europe', 2.5)
    introcs.assert_equals('{ "src" : "", "dst" : "", "valid" : '+\
    'false, "error" : "Exchange currency code is invalid." }', last)
    last = a1.currency_response('USD', 'EUR', 2.8989890)
    introcs.assert_equals('{ "src" : "2.898989 United States Dollars", "dst"'+\
    ' : "2.503477031741 Euros", "valid" : true, "error" : "" }', last)
    print('The module is working correctly')
Beispiel #9
0
def testC():
    """Test procedure for the function currency_response"""
    #Test case for valid currency_from
    result18 = a1.currency_response('USD', 'HKD', 1.0)
    cornell.assert_equals = ('{ "success" : true, "lhs" : "1 United States Dollar", "rhs" : "7.82541 Hong Kong Dollars", "error" : "" }', result18)
    
    #Test case for invalid currency_from
    result19 = a1.currency_response('AAA', 'HKD', 1.0)
    cornell.assert_equals = ('{ "success" : false, "lhs" : "", "rhs" : "", "error" : "Source currency code is invalid." }', result19)
    
    #Test case for invalid currency_from
    result20 = a1.currency_response('usd', 'HKD', 1.0)
    cornell.assert_equals = ('{ "success" : false, "lhs" : "", "rhs" : "", "error" : "Source currency code is invalid." }', result20)
    
    #Test case for invalid currency_to
    result21 = a1.currency_response('USD', 'hkd', 1.0)
    cornell.assert_equals = ('{ "success" : false, "lhs" : "", "rhs" : "", "error" : "Exchange currency code is invalid." }', result21)
    
    #Test case for invalid currency_to
    result22 = a1.currency_response('USD', 'BBB', 1.0)
    cornell.assert_equals = ('{ "success" : false, "lhs" : "", "rhs" : "", "error" : "Exchange currency code is invalid." }', result22)
    
    #Test case for invalid amount_from
    result23 = a1.currency_response('USD', 'HKD', 10.0e100000)
    cornell.assert_equals = ('{ "success" : true, "lhs" : "INF United States Dollars", "rhs" : "INF Hong Kong Dollars", "error" : "" }', result23)
Beispiel #10
0
def testC():
    """
    Test procedure for Part C
    """
    #testing currency_response for case we were provided
    result = a1.currency_response('USD', 'CUP', 2.5)
    introcs.assert_equals(
        '{ "ok":true, "lhs":"2.5 United States Dollars", '
        '"rhs":"64.375 Cuban Pesos", "err":"" }', result)
    #test currency_response for longer json
    result = a1.currency_response('TTD', 'JMD', 2.5)
    introcs.assert_equals(
        '{ "ok":true, "lhs":"2.5 Trinidad and Tobago Dollars", '
        '"rhs":"48.690190282653 Jamaican Dollars", "err":"" }', result)
    #testing currency_response for invalid currency code
    result = a1.currency_response('ABC', 'DEF', 2.5)
    introcs.assert_equals(
        '{ "ok":false, "lhs":"", "rhs":"", '
        '"err":"Source currency code is invalid." }', result)
    #testing currency_response for invalid amt input
    result = a1.currency_response('TTD', 'JMD', '')
    introcs.assert_equals(
        '{ "ok":false, "lhs":"", "rhs":"", '
        '"err":"Currency amount is invalid." }', result)
Beispiel #11
0
def testC():
    """
    Test procedure for Part C
    """
    #test procedure for a1.currency_response: a1.currency_response returns
    #the response to a currency query. The query converts amount_from money
    #in currency currency_from to the currency currency_to. The query is
    #"valid", with the old amount ("lhs") displaying 2.5 United States
    #Dollars and the new converted amount ("rhs") 64.375 Cuban Pesos.
    introcs.assert_equals(
        '{ "ok":true, "lhs":"2.5 United States Dollars", "rhs":"64.375 Cuban Pesos", "err":"" }',
        a1.currency_response("USD", "CUP", 2.5))

    #test procedure for a1.currency_response: a1.currency_response returns
    #the response to a currency query. The query converts amount_from money
    #in currency currency_from to the currency currency_to. The query is
    #"valid", with the old amount ("lhs") displaying 2.5 United States
    #Dollars and the new converted amount ("rhs") 2.2160175 Euros.
    introcs.assert_equals(
        '{ "ok":true, "lhs":"2.5 United States Dollars", "rhs":"2.2160175 Euros", "err":"" }',
        a1.currency_response("USD", "EUR", 2.5))

    #test procedure for a1.currency_response: a1.currency_response returns
    #the response to a currency query. The query converts amount_from money
    #in currency currency_from to the currency currency_to. The query is
    #"valid", with the old amount ("lhs") displaying 100 United States
    #Dollars and the new converted amount ("rhs") 782.455 Hong Kong Dollars.
    introcs.assert_equals(
        '{ "ok":true, "lhs":"100 United States Dollars", "rhs":"782.455 Hong Kong Dollars", "err":"" }',
        a1.currency_response("USD", "HKD", 100))

    #invalid source
    introcs.assert_equals(
        '{ "ok":false, "lhs":"", "rhs":"", "err":"Source currency code is invalid." }',
        a1.currency_response("asd", "USD", 2.5))

    #invalid amount
    introcs.assert_equals(
        '{ "ok":false, "lhs":"", "rhs":"", "err":"Currency amount is invalid." }',
        a1.currency_response("USD", "HKD", ""))

    #invalid exchange empty
    introcs.assert_equals(
        '{ "ok":false, "lhs":"", "rhs":"", "err":"Exchange currency code is invalid." }',
        a1.currency_response("USD", "", 2.5))
Beispiel #12
0
def testC():
    """Prints: "Module al passed all tests" if all tests successful.
    
    Precondition: a1 is a module that contains function currency_response()"""

    print "Testing function currency_response()"

    A = '{"to": "EUR", "rate": 0.77203, "from": "USD", "v": 1.93007500000000}'
    B = '{"to": "MNT", "rate": 0.17376, "from": "BYR", "v": 17.37634752695054}'
    C = '{"to": "CHF", "rate": 828.86915, "from": "XPD", "v": 0.08288691535559}'
    D = '{"to": "XBT", "rate": 1.00000, "from": "XBT", "v": 42.00000000000000}'
    E = '{"err": "failed to parse response from xe.com."}'
    F = '{"to": "USD", "rate": 1.29529, "from": "EUR", "v": -12.95286452598992}'
    cornelltest.assert_equals(A, a1.currency_response("USD", "EUR", 2.5))
    cornelltest.assert_equals(B, a1.currency_response("BYR", "MNT", 100.0))
    cornelltest.assert_equals(C, a1.currency_response("XPD", "CHF", 0.0001))
    cornelltest.assert_equals(D, a1.currency_response("XBT", "XBT", 42.0))
    cornelltest.assert_equals(E, a1.currency_response("LOL", "USD", 10.0))
    cornelltest.assert_equals(F, a1.currency_response("EUR", "USD", -10.0))