Beispiel #1
0
def testA():
    #   TEST ONE
    print 'Testing function before_space 1'
    result = a1.before_space("Python rocks")
    cornelltest.assert_equals('Python', result)
    print 'Testing function after_space 1'
    result = a1.after_space("Python rocks")
    cornelltest.assert_equals('rocks', result)
    #  TEST TWO
    print 'Testing function before_space 2'
    result = a1.before_space("3324.92 Euros")
    cornelltest.assert_equals('3324.92', result)
    print 'Testing function after_space 2'
    result = a1.after_space("3324.92 Euros")
    cornelltest.assert_equals('Euros', result)
    # TEST THREE
    print 'Testing function before_space 3'
    result = a1.before_space("Cornell  University")
    cornelltest.assert_equals('Cornell', result)
    print 'Testing function after_space 3'
    result = a1.after_space("Cornell  University")
    cornelltest.assert_equals(' University', result)
    # TEST FOUR
    print 'Testing function before_space 4'
    result = a1.before_space("Mynameis ")
    cornelltest.assert_equals('Mynameis', result)
    print 'Testing function after_space 3'
    result = a1.after_space("Mynameis ")
    cornelltest.assert_equals('', result)
def testA():
    """Returns:'Module name is working correctly' if functions before_space
    and after_space test cases work."""
    #First before_space test case
    result = a1.before_space('500 Yuan')
    cornelltest.assert_equals('500', result)

    #First after_space test case
    result = a1.after_space('500 Yuan')
    cornelltest.assert_equals('Yuan', result)

    #Second before_space test case
    result = a1.before_space(' 19.2 pesos')
    cornelltest.assert_equals('19.2', result)

    #Second after_space test case
    result = a1.after_space(' 19.2 pesos')
    cornelltest.assert_equals('pesos', result)

    #Third before_space test case
    result = a1.before_space('0.73 Pounds ')
    cornelltest.assert_equals('0.73', result)

    #Third after_space test case
    result = a1.after_space('0.73 Pounds ')
    cornelltest.assert_equals('Pounds', result)

    #Fourth before_space test case
    result = a1.before_space(' 0.08 YEN ')
    cornelltest.assert_equals('0.08', result)

    #Fourth after_space test case
    result = a1.after_space('0.08 YEN')
    cornelltest.assert_equals('YEN', result)
    print 'Module name is working correctly'
Beispiel #3
0
def testA():
    """Test procedure for back_space and after_space"""
    #Test case 1a
    result = a1.before_space('0.8963 Euro')
    cornelltest.assert_equals('0.8963', result)
    #Test case 2a
    result = a1.before_space('0.8963   Euro')
    cornelltest.assert_equals('0.8963', result)
    #Test case 3a
    result = a1.before_space('  0.8963 Euro')
    cornelltest.assert_equals('', result)

    #Test case 1b
    result = a1.after_space('0.8963 Euro')
    cornelltest.assert_equals('Euro', result)
    #Test case 2b
    result = a1.after_space('0.8963   Euro')
    cornelltest.assert_equals('  Euro', result)
    #Test case 3b
    result = a1.after_space('   0.8963 Euro')
    cornelltest.assert_equals('  0.8963 Euro', result)
    #Test case 1b
    result = a1.after_space('0.8963 Euro  ')
    cornelltest.assert_equals('Euro  ', result)
    #Test case 1b
    result = a1.after_space('0.8963Euro  ')
    cornelltest.assert_equals(' ', result)
Beispiel #4
0
def testA():
    """
    Test procedure for Part A
    """
    #test procedure for a1.before_space: the function a1.before_space returns the substring of the string s; up to, but not including the first space. For example, s is "0.863569 Euros". The function a1.before_space returns '0.863569', the first substring of s up to but not including the first space.
    introcs.assert_equals('0.863569', a1.before_space("0.863569 Euros"))

    #multiple spaces before space
    introcs.assert_equals('a', a1.before_space("a    b"))

    #multiple spaces after space
    introcs.assert_equals('   b', a1.after_space("a    b"))

    #multiple spaces seperations before space
    introcs.assert_equals('a', a1.before_space("a    b  c"))

    #multiple spaces seperations after space
    introcs.assert_equals('   b  c', a1.after_space("a    b  c"))

    #space before before space
    introcs.assert_equals('', a1.before_space(" a    b"))

    #space before after space
    introcs.assert_equals('a    b', a1.after_space(" a    b"))

    #test procedure for a1.after_space: the function a1.after_space returns the substring of s after the first space. For example, s is "0.863569 Euros". The function a1.after_space returns 'Euros', the substring of s after the first space.
    introcs.assert_equals('Euros', a1.after_space("0.8663569 Euros"))

    #test procedure for a1.before_space: the function a1.before_space returns the substring of the string s; up to, but not including the first space. For example, s is "1.012324 HKD". The function a1.before_space returns '1.012324', the first substring of s up to but not including the first space.
    introcs.assert_equals('1.012324', a1.before_space("1.012324 HKD"))

    #test procedure for a1.after_space: the function a1.after_space returns the substring of s after the first space. For example, s is "1.012324 HKD". The function a1.after_space returns 'HKD', the substring of s after the first space.
    introcs.assert_equals('HKD', a1.after_space("1.012324 HKD"))
Beispiel #5
0
def testA():
    """
    Test procedure for Part A
    """
    print("Testing function before_space(s)")
    s = "Hello World"
    answer = a1.before_space(s)
    introcs.assert_equals('Hello', answer)
    r = 'Hello my name is'
    result = a1.before_space(r)
    introcs.assert_equals('Hello', result)
    t = '     hi'
    final = a1.before_space(t)
    introcs.assert_equals('', final)
    q = 'bye    '
    last = a1.before_space(q)
    introcs.assert_equals('bye', last)
    print("The module is working correctly")

    print("Testing function after_space(s)")
    s = "Hello World"
    result = a1.after_space(s)
    introcs.assert_equals('World', result)
    w = 'Hello my name is'
    result = a1.after_space(w)
    introcs.assert_equals('my name is', result)
    t = '     hi'
    final = a1.after_space(t)
    introcs.assert_equals('    hi', final)
    q = 'bye    '
    last = a1.after_space(q)
    introcs.assert_equals('   ', last)
    print("The module is working correctly")
Beispiel #6
0
def testA():
    """
    Test procedure for Part A
    """
    #testing before_space for string with one space
    result = a1.before_space("4.502 Euros")
    introcs.assert_equals("4.502", result)
    #testing before_space for string with two spaces
    result = a1.before_space("Brandon and Taerim")
    introcs.assert_equals("Brandon", result)
    #testing before_space for string with space at front
    result = a1.before_space(" car")
    introcs.assert_equals("", result)
    #testing before_space for string with multiple spaces together
    result = a1.before_space("Taerim   and")
    introcs.assert_equals("Taerim", result)
    #testing after_space for one space
    result = a1.after_space("4.502 Euros")
    introcs.assert_equals("Euros", result)
    #testing after_space for two spaces
    result = a1.after_space("Brandon and Taerim")
    introcs.assert_equals("and Taerim", result)
    #testing after_space for space at front
    result = a1.after_space(" car")
    introcs.assert_equals("car", result)
    #testing after_space for multiple spaces together
    result = a1.after_space("Taerim  and")
    introcs.assert_equals(" and", result)
    #testing after_space for space at end
    result = a1.after_space("Taerim ")
    introcs.assert_equals("", result)
def testA(s):
    """Test procedure for Part A

     sa1='4.502 Euros'
     sa2='icniwunci'
     sa3='' """
    a1.before_space(s)
    a1.after_space(s)
Beispiel #8
0
def testA():
    """ Test procedure for the functions before_space and after_space """
    
    #Test case for string with only one space
    result1 = a1.before_space("0.838095 Euros")
    cornell.assert_equals = ("0.838095", result1)
    
    #Test case for string with more than one space i.e. four spaces
    result2 = a1.before_space("0.838095    Euros")
    cornell.assert_equals = ("0.838095", result2)
    
    #Test case for string starting with a space i.e. two spaces
    result3 = a1.before_space("  0.838095 Euros")
    cornell.assert_equals = ("0.838095", result3)
    
    #Test case for string ending with a space
    result4 = a1.before_space("0.838095 Euros ")
    cornell.assert_equals = ("0.838095", result4)
    
    #Test case for string with no space but ending with a space
    result28 = a1.before_space("0.838095Euros ")
    cornell.assert_equals = ("0.838095Euros", result28)
    
    #Test case for string with no space but starting with a space
    result29 = a1.before_space(" 0.838095Euros")
    cornell.assert_equals = ("", result29)
    
    #Test case for string that is only a space
    result30 = a1.before_space(" ")
    cornell.assert_equals = ("", result30)
    
    #Test case for string with only one space
    result5 = a1.after_space("0.838095 Euros")
    cornell.assert_equals = ("Euros", result5)
    
    #Test case for string with more than one space i.e. four spaces
    result6 = a1.after_space("0.838095    Euros")
    cornell.assert_equals = ("Euros", result6)
    
    #Test case for string starting with a space i.e. two spaces
    result7 = a1.after_space("  0.838095 Euros")
    cornell.assert_equals = ("Euros", result7)
    
    #Test case for string ending with a space
    result8 = a1.after_space("0.838095 Euros ")
    cornell.assert_equals = ("Euros", result8)
    
    #Test case for string with no space but ending with a space
    result31 = a1.after_space("0.838095Euros ")
    cornell.assert_equals = ("", result31)
    
    #Test case for string with no space but starting with a space
    result32 = a1.after_space(" 0.838095Euros")
    cornell.assert_equals = ("0.838095Euros", result32)
    
    #Test case for string that is only a space
    result33 = a1.after_space(" ")
    cornell.assert_equals = ("", result33)
Beispiel #9
0
def testA():
    """
    Test functions before_space(), after_space()
    """

    #testing one space
    atest1 = a1.before_space('Hameedah Khadar')
    introcs.assert_equals('Hameedah', atest1)

    #testing multiple spaces
    atest2 = a1.before_space('Ham   Khadar')
    introcs.assert_equals('Ham', atest2)

    #testing spaces in the beginning of the string
    atest3 = a1.before_space(" HelloWorld")
    introcs.assert_equals("", atest3)

    #testing multiple seperated spaces
    atest8 = a1.before_space('Hello World !')
    introcs.assert_equals("Hello", atest8)

    #testing one space
    atest5 = a1.after_space('Hameedah Khadar')
    introcs.assert_equals('Khadar', atest5)

    #testing multiple spaces
    atest6 = a1.after_space('Ham   Khadar')
    introcs.assert_equals('  Khadar', atest6)

    #testing spaces in the beginning of the string
    atest7 = a1.after_space(" HelloWorld!")
    introcs.assert_equals("HelloWorld!", atest7)

    #testing multiple seperated spaces
    atest9 = a1.after_space('Hello World !')
    introcs.assert_equals("World !", atest9)

    #testing space in the end of the string
    atest10 = a1.after_space("HelloWorld ")
    introcs.assert_equals("", atest10)
Beispiel #10
0
def testA():
    "test procedure for part A"
    #Test for '0.838095 Euros'
    cornell.assert_equals('0.838095', a1.before_space('0.838095 Euros'))
    cornell.assert_equals('Euros', a1.after_space('0.838095 Euros'))

    #Test for '5 Saudi Riyals'
    cornell.assert_equals('5', a1.before_space('5 Saudi Riyals'))
    cornell.assert_equals('Saudi Riyals', a1.after_space('5 Saudi Riyals'))

    #Test for ' 5'
    cornell.assert_equals('', a1.before_space(' 5'))
    cornell.assert_equals('5', a1.after_space(' 5'))

    #Test for '5 '
    cornell.assert_equals('5', a1.before_space('5 '))
    cornell.assert_equals('', a1.after_space('5 '))

    #Test for 'Peter Oh likes Tennis'
    cornell.assert_equals('Peter', a1.before_space('Peter Oh likes Tennis'))
    cornell.assert_equals('Oh likes Tennis',
                          a1.after_space('Peter Oh likes Tennis'))
Beispiel #11
0
def testA():
    """Test procedure for Part A"""
    result = a1.before_space('0.12345 Bitcoins')
    cornell.assert_equals('0.12345', result)
    result = a1.before_space('1799.3186929883  Lebanese Pounds')
    cornell.assert_equals('1799.3186929883', result)
    result = a1.before_space('7.725799   Solomon Islands Dollars')
    cornell.assert_equals('7.725799', result)
    result = a1.before_space('1 United States Dollar')
    cornell.assert_equals('1', result)
    result = a1.before_space(' 1 United States Dollar')
    cornell.assert_equals('', result)

    result = a1.after_space('0.12345 Bitcoins')
    cornell.assert_equals('Bitcoins', result)
    result = a1.after_space('1799.3186929883 Lebanese Pounds')
    cornell.assert_equals('Lebanese Pounds', result)
    result = a1.after_space('7.725799 Solomon Islands Dollars')
    cornell.assert_equals('Solomon Islands Dollars', result)
    result = a1.after_space('73.8118685829172 Papua New Guinean Kina')
    cornell.assert_equals('Papua New Guinean Kina', result)
    result = a1.after_space('8.0307256337289 Trinidad and Tobago Dollars')
    cornell.assert_equals('Trinidad and Tobago Dollars', result)
    result = a1.after_space('124 Euros ')
    cornell.assert_equals('Euros ', result)
    result = a1.after_space(' 34.5827 Namibian Dollars')
    cornell.assert_equals('34.5827 Namibian Dollars', result)
    result = a1.after_space('17.8686  Mexican Pesos')
    cornell.assert_equals(' Mexican Pesos', result)

    #Test for first_inside_quotes
    result = a1.first_inside_quotes('ab"cd"ef')
    cornell.assert_equals('cd', result)
    result = a1.first_inside_quotes('""')
    cornell.assert_equals('', result)
    result = a1.first_inside_quotes('"This is assignment 1"')
    cornell.assert_equals('This is assignment 1', result)
    result = a1.first_inside_quotes('ab"cd"ef"gh"')
    cornell.assert_equals('cd', result)
Beispiel #12
0
Datei: a1.py Projekt: tx58/origin
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
def testA():
    """
    Test procedure for Part A
    """
    introcs.assert_equals('0.863569', a1.before_space("0.863569 Euros"))
    introcs.assert_equals('Euros', a1.after_space("0.8663569 Euros"))