def test_has_error(self): self.assertTrue( has_error( "453", weather_response("Delhi", "2ab136be1543b5789451a5994364c0d3"))) self.assertTrue( has_error( "London", weather_response("Kolkata", "2ab136be1543b5789451a5994364c0d3"))) self.assertTrue( has_error( "Sydney", weather_response("Chandigarh", "2ab136be1543b5789451a5994364c0d3"))) self.assertTrue( has_error( "Rohtak", weather_response("Mumbai", "2ab136be1543b5789451a5994364c0d3"))) self.assertTrue( has_error( "Ludhiana", weather_response("Bathinda", "2ab136be1543b5789451a5994364c0d3")))
def testB(): """Prints: "Module al passed all tests" if all tests successful. Precondition: a1 is a module that contains functions get_keyword_index(), has_error(), and get_value()""" print "Testing functions get_keyword_index(), has_error(), and get_value()" A = 'A "word" B' B = 'A word B "word" C' C = 'A x B "word" C' cornelltest.assert_equals(2, a1.get_keyword_index(A, "word")) cornelltest.assert_equals(9, a1.get_keyword_index(B, "word")) cornelltest.assert_equals(-1, a1.get_keyword_index(C, "x")) D = '{"to": "EUR", "rate": 0.75, "warning": "invalid quantity, ignored.",\ "from": "USD"}' E = '{"err": "failed to parse response from xe.com."}' F = '{"to": "EUR", "rate": 0.77203, "from": "USD", "v": 1.93007500000000}' cornelltest.assert_equals(True, a1.has_error(D)) cornelltest.assert_equals(True, a1.has_error(E)) cornelltest.assert_equals(False, a1.has_error(F)) G = '{"to": "EUR", "rate": 0.75443, "from": "USD", "v": 1.88}' H = '{"to": "EUR", "rate": 0.75443, "from": "USD", "v": 1.88}' cornelltest.assert_equals('"EUR"', a1.get_value(G, "to")) cornelltest.assert_equals("1.88", a1.get_value(H, "v"))
def testB(): # TEST ONE print 'Testing function get_from 1' result = a1.get_from( '{"from":"2 United States Dollars","to":"1.825936 Euros","success":true,"error":""}' ) cornelltest.assert_equals('2 United States Dollars', result) # TEST TWO print 'Testing function get_from 2' result = a1.get_from( '{"from":"","to":"Qatari Rial","success":true,"error":""}') cornelltest.assert_equals('', result) # TEST ONE print 'Testing function get_to 1' result = a1.get_to( '{"from":"2 United States Dollars","to":"1.825936 Euros","success":true,"error":""}' ) cornelltest.assert_equals('1.825936 Euros', result) # TEST TWO print 'Testing function get_to 2' result = a1.get_to('{"from":"","to":"","success":true,"error":""}') cornelltest.assert_equals('', result) # TEST ONE print 'Testing function has_error 1' result = a1.has_error( '{"from":"2 United States Dollars","to":"1.825936 Euros","success":true,"error":""}' ) cornelltest.assert_equals(False, result) # TEST TWO print 'Testing function has_error 2' result = a1.has_error( '{"from":"","to":"1.825936 Euros","success":false,"error":""}') cornelltest.assert_equals(True, result)
def test_has_error(self): self.assertEqual( has_error( "Delhi", weather_response("Delhi", "2ab136be1543b5789451a5994364c0d3")), "False") self.assertEqual( has_error( "Mumbai", weather_response("Delhi", "2ab136be1543b5789451a5994364c0d3")), "True") self.assertEqual( has_error( "Delhi", weather_response("Chennai", "2ab136be1543b5789451a5994364c0d3")), "True") self.assertEqual( has_error( "Chennai", weather_response("Chennai", "2ab136be1543b5789451a5994364c0d3")), "False") self.assertEqual( has_error( "Delhi", weather_response("Mumbai", "2ab136be1543b5789451a5994364c0d3")), "True")
def testB(): """Test procedure for Part B""" result = a1.get_lhs( '{"success":true, "lhs":"2 United States Dollars", "rhs":"1.825936 Euros", "error":""}' ) cornell.assert_equals('2 United States Dollars', result) result = a1.get_lhs( '{"success":false, "lhs":"", "rhs":"", "error":"Source currency code is invalid."}' ) cornell.assert_equals('', result) result = a1.get_rhs( '{"success":true, "lhs":"2 United States Dollars", "rhs":"1.825936 Euros", "error":""}' ) cornell.assert_equals('1.825936 Euros', result) result = a1.get_rhs( '{"success":false, "lhs":"", "rhs":"", "error":"Source currency code is invalid."}' ) cornell.assert_equals('', result) result = a1.has_error( '{"success":false, "lhs":"", "rhs":"", "error":"Source currency code is invalid."}' ) cornell.assert_equals(True, result) result = a1.has_error( '{"success":true, "lhs":"2 United States Dollars", "rhs":"1.825936 Euros", "error":""}' ) cornell.assert_equals(False, result)
def testB(s): """Test procedure for Part B sb1='{ "ok":true, "lhs":"2.5 United States Dollars", "rhs":"64.375 Cuban Pesos", "err":"" }' sb2='{ "ok":true, "lhs":"2.5UnitedStatesDollars", "rhs":"64.375CubanPesos", "err":"" }' sb3='{ "ok":false, "lhs":"", "rhs":"", "err":"Source currency code is invalid." }' sb4='{ "ok":false, "lhs":"", "rhs":"", "err":"Currency amount is invalid." }' """ a1.get_lhs(s) a1.get_rhs(s) a1.has_error(s)
def testB(): """ Test functions get_src(), get_dst() """ #testing one occurrence of double quotes btest1 = a1.first_inside_quotes('A "BD" D') introcs.assert_equals("BD", btest1) #testing multiple occurrence of double quotes btest2 = a1.first_inside_quotes('A b "cde" fg "hi" jk ') introcs.assert_equals("cde", btest2) #testing nothing in the double quote btest3 = a1.first_inside_quotes('""') introcs.assert_equals("", btest3) #testing a string with only double quotes btest4 = a1.first_inside_quotes('"ab"') introcs.assert_equals("ab", btest4) #testing a valid input btest5 = a1.get_lhs('{ "ok":true, "lhs":"1 Bitcoin", "rhs":"9916.0137 ' + 'Euros","err":"" }') introcs.assert_equals('1 Bitcoin', btest5) #testing an invalid input btest7 = a1.get_lhs('{ "ok":false, "lhs":"", "rhs":"", "err":"Source ' + 'currency code is invalid." }') introcs.assert_equals('', btest7) #testing an invalid input btest8 = a1.get_rhs('{ "ok":false, "lhs":"", "rhs":"", "err":"Source ' + 'currency code is invalid." }') introcs.assert_equals('', btest8) #testing a valid input btest9 = a1.get_rhs('{ "ok":true, "lhs":"1 Bitcoin", "rhs":"9916.0137 ' + 'Euros","err":"" }') introcs.assert_equals('9916.0137 Euros', btest9) #testing an invalid query btest10 = a1.has_error('{ "ok":false, "lhs":"", "rhs":"", "err":"" }') introcs.assert_equals(True, btest10) #testing a valid query btest11 = a1.has_error( '{ "ok":true, "lhs":"1 Bitcoin", "rhs":"9916.0137 ' + 'Euros", "err":"" }') introcs.assert_equals(False, btest11) #testing an invalid currency btest11 = a1.has_error('{ "ok":false, "lhs":"", "rhs":"", ' + '"err":"Exchange currency code is invalid." }') introcs.assert_equals(True, btest11)
def testB(): "test procedure for part B" #Test for first_inside_quotes cornell.assert_equals('C', a1.first_inside_quotes('A B "C" D')) cornell.assert_equals('D E F', a1.first_inside_quotes('A B C "D E F"')) cornell.assert_equals(' ', a1.first_inside_quotes('ABC " " DEF')) #Test for get_lhs cornell.assert_equals( '2 United States Dollars', a1.get_lhs( '{"success":true, "lhs":"2 United States Dollars", "rhs":"1.825936 Euros", "error":""}' )) cornell.assert_equals( '2.5 United States Dollars', a1.get_lhs( '{ "success" : true, "lhs" : "2.5 United States Dollars", "rhs" : "2.0952375 Euros", "error" : "" }' )) cornell.assert_equals( '30000 United States Dollars', a1.get_lhs( '{ "success" : true, "lhs" : "30000 United States Dollars", "rhs" : "6.5237409 Bitcoins", "error" : "" }' )) #Test for get_rhs cornell.assert_equals( '112518 Saudi Riyals', a1.get_rhs( '{ "success" : true, "lhs" : "30000 United States Dollars", "rhs" : "112518 Saudi Riyals", "error" : "" }' )) cornell.assert_equals( '2384.8473112096 Saudi Riyals', a1.get_rhs( '{ "success" : true, "lhs" : "30000 Dominican Pesos", "rhs" : "2384.8473112096 Saudi Riyals", "error" : "" }' )) cornell.assert_equals( '4975.8459973372 Hong Kong Dollars', a1.get_rhs( '{ "success" : true, "lhs" : "30000 Dominican Pesos", "rhs" : "4975.8459973372 Hong Kong Dollars", "error" : "" }' )) #Test for has_error cornell.assert_equals( True, a1.has_error( '{"success":false, "lhs":"", "rhs":"", "error":"Source currency code is invalid."}' )) cornell.assert_equals( False, a1.has_error( '{"success":true, "lhs":"2 United States Dollars", "rhs":"1.825936 Euros", "error":""}' ))
def testB(): """Test procedure for first_inside_quotes(s). Will extract substrings.""" #Test case 1 result = a1.first_inside_quotes('Johnny"apple"seed') cornelltest.assert_equals('apple', result) #Test case 2 result = a1.first_inside_quotes('Harvard" sucks "poo') cornelltest.assert_equals(' sucks ', result) #Test case 2 result = a1.first_inside_quotes('Harvard" "poo') cornelltest.assert_equals(' ', result) #Test case 2 result = a1.first_inside_quotes('Harvard""poo') cornelltest.assert_equals('', result) result = a1.first_inside_quotes('Jeffrey, "Don\'t panic!" about assign. 1') cornelltest.assert_equals('Don\'t panic!', result) result = a1.first_inside_quotes( 'Jeffrey, "Don\'t panic!" you will "be" ok') cornelltest.assert_equals('Don\'t panic!', result) """Test procedure for get_from(json).""" #Test case 1a result = a1.get_from( '"from" : "2.5 United States Dollars",' + '"to" : "2.24075 Euros", "success" : true, "error" : ""') cornelltest.assert_equals('2.5 United States Dollars', result) result = a1.get_from('{"from":"2 United States Dollars",' + '"to":"1.825936 Euros","success":true,"error":""}') cornelltest.assert_equals('2 United States Dollars', result) result = a1.get_from( '{ "from" : "", "to" : "", "success" : false, "error"' + ' : "Exchange currency code is invalid." }') cornelltest.assert_equals('', result) #Test case 2b result = a1.get_to('"from" : "2 United States Dollars","to"' + ' : "1.825936 Euros","success":true,"error":""') cornelltest.assert_equals('1.825936 Euros', result) result = a1.get_to('{ "from" : "", "to" : "", "success" : false, "error"' + ' : "Exchange currency code is invalid." }') cornelltest.assert_equals('', result) #Test case 1c result = a1.has_error('"from" : "2 United States Dollars","to"' + ' : "1.825936 Euros","success":true,"error":""') cornelltest.assert_equals(False, result) #Test case 2c result = a1.has_error( '"from" : "", "to" : "", "success"' + ' : false, "error" : "Source currency code is invalid."') cornelltest.assert_equals(True, result)
def testB(): """Returns:'Module name is working correctly' if functions get_from, get_to, and has_error test cases work.""" #First get_from test case result = a1.get_from('{ "from":"3 United States Dollars", "to": ' + '"20.041308 Chinese Yuan", "success" : true, ' + '"error" : "" }') cornelltest.assert_equals('3 United States Dollars', result) #First get_to test case result = a1.get_to('{ "from":"3 United States Dollars", "to":"20.041308 ' + 'Chinese Yuan", "success" : true, "error" : "" }') cornelltest.assert_equals('20.041308 Chinese Yuan', result) #Second get_from test case result = a1.get_from('{ "from":"30 Liberian Dollars", "to":' + '"0.32876712328767 United States Dollars", ' + '"success" : true, "error" : "" }') cornelltest.assert_equals('30 Liberian Dollars', result) #Second get_to test case result = a1.get_to('{ "from":"30 Liberian Dollars", "to":' + '"0.32876712328767 United States Dollars", "success" ' + ': true, "error" : "" }') cornelltest.assert_equals('0.32876712328767 United States Dollars', result) #First has_error test case result = a1.has_error('{ "from":"", "to":"", "success" : false, "error" ' + ': "Exchange currency code is invalid." }') cornelltest.assert_equals(True, result) #Second has_error test case result = a1.has_error('{ "from":"", "to":"", "success" : false, "error" ' + ': "Currency amount is invalid." }') cornelltest.assert_equals(True, result) #Third has_error test case result = a1.has_error('{ "from":"", "to":"", "success" : false, "error" ' + ': "Source currency code is invalid." }') cornelltest.assert_equals(True, result) print 'Module name is working correctly'
def testB(): """Test procedure for functions first_inside_quotes, get_lhs(json), get_rhs(json), and has_error(json)""" #Test case for general string with only one set of double quotes result9 = a1.first_inside_quotes('A "B C" D') cornell.assert_equals = ('B C', result9) #Test case for nothing inside the double quotes result10 = a1.first_inside_quotes('A "" C') cornell.assert_equals = ('', result10) #Test case for two sets of double quotes in the string result11 = a1.first_inside_quotes('A "B" "C" D') cornell.assert_equals = ('B', result11) #Test case for whole string inside double quotes result34 = a1.first_inside_quotes('"B"') cornell.assert_equals = ('B', result34) #Test case for given a general lhs currency query result12 = a1.get_lhs('{"success" : true, "lhs" : "2 United States Dollars", "rhs" : "1.825936 Euros", "error":""}') cornell.assert_equals = ('2 United States Dollars', result12) #Test Case for an invalid lhs currency query result13 = a1.get_lhs('{"success" : false, "lhs" : "2 AAA", "rhs" : "3 BBB", "error" : "Currency amount is invalid." }') cornell.assert_equals = ('', result13) #Test case for given a general rhs currency query result14 = a1.get_rhs('{"success" : true, "lhs" : "2 United States Dollars", "rhs" : "1.825936 Euros", "error":""}') cornell.assert_equals = ('1.825936 Euros', result14) #Test Case for an invalid rhs currency query result15 = a1.get_rhs('{"success" : false, "lhs" : "2 AAA", "rhs" : "3 BBB", "error" : "Currency amount is invalid." }') cornell.assert_equals = ('', result15) #Test case for a valid currency query result16 = a1.has_error('{"success" : true, "lhs" : "2 United States Dollars", "rhs" : "1.825936 Euros", "error":""}') cornell.assert_equals = (False, result16) #Test case for an invalid currency query result17 = a1.has_error('{"success" : false, "lhs" : "", "rhs" : "", "error":"Source currency code is invalid."}') cornell.assert_equals = (True, result17)
def test_has_error(self): self.assertTrue( has_error( 'Mumbai', weather_response('Delhi', 'e6205c85b5958567349335aeb1cee7df')), True) self.assertTrue( has_error( 'Lucknow', weather_response('Lucknow', 'e6205c85b5958567349335aeb1cee7df')), False) self.assertTrue( has_error( 'Jaipur', weather_response('Jaipur', 'e6205c85b5958567349335aeb1cee7df')), False) self.assertTrue( has_error( 'Allahabad', weather_response('Allahabad', 'e6205c85b5958567349335aeb1cee7df')), False)
def test_has_error(self): self.assertFalse( has_error( "Delhi", weather_response("DeLHi", "c21be3f5656ccff4a5fb262f334b1867"))) self.assertFalse( has_error( "New York", weather_response("New%20York", "c21be3f5656ccff4a5fb262f334b1867"))) self.assertFalse( has_error( "New York", weather_response("New York", "c21be3f5656ccff4a5fb262f334b1867"))) self.assertTrue( has_error( "Kolkata", weather_response("Mumbai", "c21be3f5656ccff4a5fb262f334b1867"))) self.assertTrue( has_error( "KOLKATA", weather_response("KOLKATA", "c21be3f5656ccff4a5fb262f334b1867"))) self.assertTrue( has_error( "KOLKATA", weather_response("Kolkata", "c21be3f5656ccff4a5fb262f334b1867")))
def test_has_error(self): # self.assertTrue() self.assertTrue( has_error( 'California', weather_response("Noida", "55caddfec6f90b2b717bb37ceab8abb0"))) self.assertTrue( has_error( 'D', weather_response("Noida", "55caddfec6f90b2b717bb37ceab8abb0"))) self.assertTrue( has_error( 'Delhi', weather_response("Noida", "55caddfec6f90b2b717bb37ceab8abb0"))) self.assertTrue( has_error( 'Ghaziabad', weather_response("Noida", "55caddfec6f90b2b717bb37ceab8abb0"))) self.assertTrue( has_error( 'Faridabad', weather_response("Noida", "55caddfec6f90b2b717bb37ceab8abb0")))
def test_has_error(self): self.assertTrue( has_error( '123', weather_response('123', '2ab136be1543b5789451a5994364c0d3'))) self.assertTrue( has_error( 'man', weather_response('man', '2ab136be1543b5789451a5994364c0d3'))) self.assertFalse( has_error( 'Faridabad', weather_response('Harayana', '2ab136be1543b5789451a5994364c0d3'))) self.assertTrue( has_error( 'Amasd', weather_response('Amasd', '2ab136be1543b5789451a5994364c0d3'))) self.assertFalse( has_error( 'Mumbai', weather_response('Mumbai', '2ab136be1543b5789451a5994364c0d3')))
def test_has_error(self): self.assertTrue( has_error( "Delhi", weather_response("London", "5753b64e9e1290004733b7726fb5aa15"))) self.assertTrue( has_error( "Mumbai", weather_response("Munich", "5753b64e9e1290004733b7726fb5aa15"))) self.assertTrue( has_error( "Bangalore", weather_response("Dubai", "5753b64e9e1290004733b7726fb5aa15"))) self.assertTrue( has_error( "Chennai", weather_response("Doha", "5753b64e9e1290004733b7726fb5aa15"))) self.assertTrue( has_error( "Hyderabad", weather_response("Beijing", "5753b64e9e1290004733b7726fb5aa15")))
def test_has_error(self): self.assertTrue(has_error("110009", str(weather_response("110009")))) self.assertTrue(has_error("600025", str(weather_response("600025")))) self.assertTrue(has_error("247667", str(weather_response("247667")))) self.assertTrue(has_error("2139", str(weather_response("2139")))) self.assertTrue(has_error("2142", str(weather_response("2142"))))
def test_has_error(self): self.assertTrue(has_error("Delhi", weather_response())) self.assertTrue(has_error("Dilli", weather_response())) self.assertTrue(has_error("London", weather_response("London"))) self.assertTrue(has_error("Monza", weather_response())) self.assertTrue(has_error("DELHI", weather_response()))
def testB(): """ Test procedure for Part B """ print("Testing function first_inside_quotes(s)") s = 'A "B C" D' answer = a1.first_inside_quotes(s) introcs.assert_equals('B C', answer) e = 'hello" " hi' result = a1.first_inside_quotes(e) introcs.assert_equals(" ", result) c = '"1"' result = a1.first_inside_quotes(c) introcs.assert_equals("1", result) t = '"hello" my "name is"' final = a1.first_inside_quotes(t) introcs.assert_equals("hello", final) e = '"" hi' result = a1.first_inside_quotes(e) introcs.assert_equals("", result) print('The module is working correctly') print("Testing function get_src(json)") s = '{ "src" : " 2 United States Dollars ",\ "dst" : "1.727138 Euros", "valid" : true, "error" : "" }' final = a1.get_src(s) introcs.assert_equals(' 2 United States Dollars ', final) s = '{ "src" : "2 United States Dollars ",\ "dst" : "1.727138 Euros", "valid" : true, "error" : "" }' final = a1.get_src(s) introcs.assert_equals('2 United States Dollars ', final) s = '{ "src" : " 2 United States Dollars",\ "dst" : "1.727138 Euros", "valid" : true, "error" : "" }' final = a1.get_src(s) introcs.assert_equals(' 2 United States Dollars', final) s = '{ "src" : "2 United States Dollars",\ "dst" : "1.727138 Euros", "valid" : true, "error" : "" }' final = a1.get_src(s) introcs.assert_equals('2 United States Dollars', final) s = '{ "src" : "",\ "dst" : "1.727138 Euros", "valid" : true, "error" : "" }' final = a1.get_src(s) introcs.assert_equals("", final) q = '{ "src" : "", "dst" : "", "valid" : false, "error" :\ "Exchange currency code is invalid." }' end = a1.get_src(q) introcs.assert_equals("", end) print('The module is working correctly') print("Testing function dst_src(json)") s = '{ "src" : "2 United States Dollars", "dst" :\ " 1.727138 Euros ", "valid" : true, "error" : "" }' end = a1.get_dst(s) introcs.assert_equals(' 1.727138 Euros ', end) s = '{ "src" : "2 United States Dollars", "dst" :\ "1.727138 Euros ", "valid" : true, "error" : "" }' end = a1.get_dst(s) introcs.assert_equals('1.727138 Euros ', end) s = '{ "src" : "2 United States Dollars", "dst" :\ " 1.727138 Euros", "valid" : true, "error" : "" }' end = a1.get_dst(s) introcs.assert_equals(' 1.727138 Euros', end) s = '{ "src" : "2 United States Dollars", "dst" :\ "1.727138 Euros", "valid" : true, "error" : "" }' end = a1.get_dst(s) introcs.assert_equals('1.727138 Euros', end) s = '{ "src" : "2 United States Dollars",\ "dst" : "", "valid" : true, "error" : "" }' final = a1.get_dst(s) introcs.assert_equals("", final) s = '{ "src" : "", "dst" : "", "valid" : false, "error"\ : "Source currency code is invalid." }' stop = a1.get_dst(s) introcs.assert_equals("", stop) print('The module is working correctly') print('Testing has_error(json)') t = '{ "src" : "<old-amt>", "dst" : "<new-amt>", "valid" : true,\ "error" : "" }' final = a1.has_error(t) introcs.assert_equals(False, final) q = '{ "src" : "", "dst" : "", "valid" : false, "error" :\ "Exchange currency code is invalid." }' end = a1.has_error(q) introcs.assert_equals(True, end) l = '{ "src" : "", "dst" : "", "valid" : false, "error" :\ "Currency amount is invalid." }' done = a1.has_error(l) introcs.assert_equals(True, done) s = '{ "src" : "", "dst" : "", "valid" : false, "error"\ : "Source currency code is invalid." }' stop = a1.has_error(s) introcs.assert_equals(True, stop) print('The module is working correctly')
def testB(): """ Test procedure for Part B """ #testing first_inside_quotes for json result = a1.first_inside_quotes( '{ "ok":true, "lhs":"2.5 United States Dollars", ' '"rhs":"64.375 Cuban Pesos", "err":"" }') introcs.assert_equals('ok', result) #testing first_inside_quotes for no quotes result = a1.first_inside_quotes('Quotes "" quotes') introcs.assert_equals('', result) #testing first_inside_quotes for two quotes result = a1.first_inside_quotes('two "of" these "quotes"') introcs.assert_equals('of', result) #testing first_inside_quotes for one quote in a string result = a1.first_inside_quotes('""') introcs.assert_equals('', result) #testing first_inside_quotes for two quotes result = a1.first_inside_quotes(' "" "" ') introcs.assert_equals('', result) #testing first_inside_quotes for a single quote in a double quote result = a1.first_inside_quotes(' " ' ' "') introcs.assert_equals(' ', result) #testing first_inside_quotes whole quote in quotes result = a1.first_inside_quotes('"this entire string"') introcs.assert_equals('this entire string', result) #testing get get_lhs result = a1.get_lhs('{ "ok":true, "lhs":"2.5 United States Dollars", ' '"rhs":"64.375 Cuban Pesos", "err":"" }') introcs.assert_equals('2.5 United States Dollars', result) #testing get_lhs on json with error result = a1.get_lhs('{ "ok":false, "lhs":"", "rhs":"", ' '"err":"Currency amount is invalid." }') introcs.assert_equals('', result) #testing get_lhs with longer json result = a1.get_lhs( '{ "ok":true, "lhs":"2.5 Trinidad and Tobago Dollars", ' '"rhs":"77.304437834842 Guyanaese Dollars", "err":"" }') introcs.assert_equals('2.5 Trinidad and Tobago Dollars', result) #testing get_lhs result = a1.get_lhs('{ "ok":true, "lhs":"1 Bitcoin", ' '"rhs":"9916.0137 Euros", "err":"" }') introcs.assert_equals('1 Bitcoin', result) #testing get_rhs with regular json result = a1.get_rhs('{ "ok":true, "lhs":"1 Bitcoin", ' '"rhs":"9916.0137 Euros", "err":"" }') introcs.assert_equals('9916.0137 Euros', result) #testing get_rhs with json with an error result = a1.get_rhs('{ "ok":false, "lhs":"", "rhs":"", ' '"err":"Currency amount is invalid." }') introcs.assert_equals('', result) #testing get_rhs with longer json result = a1.get_rhs( '{ "ok":true, "lhs":"2.5 Trinidad and Tobago Dollars", ' '"rhs":"77.304437834842 Guyanaese Dollars", "err":"" }') introcs.assert_equals('77.304437834842 Guyanaese Dollars', result) #testing has_error with an error result = a1.has_error('{ "ok":false, "lhs":"", "rhs":"", ' '"err":"Currency amount is invalid." }') introcs.assert_equals(True, result) #testing has_error without an error result = a1.has_error('{ "ok":true, "lhs":"1 Bitcoin", ' '"rhs":"9916.0137 Euros", "err":"" }') introcs.assert_equals(False, result)
def test_has_error(self): self.assertFalse(has_error("Delhi",(weather_response("Delhi","1b51de2b8b1a00efe9e9d1c5cdd5c759")))) self.assertFalse(has_error("Mumbai",(weather_response("Mumbai","1b51de2b8b1a00efe9e9d1c5cdd5c759")))) self.assertFalse(has_error("Ludhiana",(weather_response("Ludhiana","1b51de2b8b1a00efe9e9d1c5cdd5c759")))) self.assertFalse(has_error("Australia",(weather_response("Australia","1b51de2b8b1a00efe9e9d1c5cdd5c759")))) self.assertFalse(has_error("India",(weather_response("India","1b51de2b8b1a00efe9e9d1c5cdd5c759"))))
def test_has_error(self): self.assertTrue(has_error("Delhyo",jsonURL)) self.assertTrue(has_error("Tokyo",jsonURL)) self.assertTrue(has_error("London",jsonURL)) self.assertTrue(has_error("Beijing",jsonURL)) self.assertTrue(has_error("Delhi",jsonURL))
def test_has_error(self): self.assertTrue(has_error("1234",weather_response("1234",'65ff78135854500cd7853fe3860b5569'))) self.assertFalse(has_error("Delhi",x))
def testB(): """ Test procedure for Part B """ #test procedures for a1.first_inside_quotes: the function a1.first_inside_quotes #returns the first substring of s between two double quote characters. #For example, if s is 'A "B C" D', the function first_inside_quotes returns 'B C'. #If s is '"A" "B" C "D"', the function first_inside_quotes returns 'A'. #If s is " ", the function first_inside_quotes returns ' '. introcs.assert_equals('B C', a1.first_inside_quotes('A "B C" D')) #Test multiple "" introcs.assert_equals('A', a1.first_inside_quotes('"A" "B" C "D"')) #Test empty space introcs.assert_equals(' ', a1.first_inside_quotes('" "')) #test procedure for a1.get_lhs: a1.get_src returns the string inside double quotes immediately following the keyword "lhs". If JSON is '{ "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }', the function a1.get_lhs returns '2 United States Dollars' (not '"2 United States Dollars"'). introcs.assert_equals( '2 United States Dollars', a1.get_lhs( '{ "ok": true, "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }' )) #test procedure for a1.get_rhs: a1.get_rhs returns the string inside double quotes immediately following the keyword "rhs". If JSON is '{ "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }', the function returns '2 United States Dollars' (not '"2 United States Dollars"'). introcs.assert_equals( '1.727138 Euros', a1.get_rhs( '{ "ok": true, "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }' )) #test procedure for a1.has_error: a1.get_src returns True if the query has an error. Since the query is not valid, the function returns True (it does NOT return "Source currency code is invalid"). introcs.assert_equals( True, a1.has_error( '{ "ok": true, "lhs" : "", "rhs" : "", "err" : "Source currency code is invalid." }' )) #test procedure for a1.get_lhs: a1.get_src returns the string inside double quotes immediately following the keyword "lhs". If JSON is '{ "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }', the function returns "2 United States Dollars". introcs.assert_equals( "2 United States Dollars", a1.get_lhs( '{ "ok": true, "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }' )) #test procedure for a1.get_lhs: a1.get_src returns the string inside double quotes immediately following the keyword "lhs". If JSON is '{ "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }', the function a1.get_lhs returns "2 United States Dollars". introcs.assert_equals( "1.727138 Euros", a1.get_rhs( '{ "ok": true, "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }' )) #test procedure for a1.has_error: a1.has_error returns False since the query does not have an error and is thus "valid". introcs.assert_equals( False, a1.has_error( '{"ok": true, "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }' )) #test procedure for a1.has_error: a1.has_error returns True since the query has an error. The function does NOT return "Source currency code is invalid". introcs.assert_equals( True, a1.has_error( '{"ok": true, "lhs" : "", "rhs" : "", "err" : "Source currency code is invalid." }' )) #test procedure for a1.get_lhs: a1.get_lhs returns the string inside double quotes immediately following the keyword "lhs". If JSON is '{ "ok":true, "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }', the function a1.get_lhs returns '2 United States Dollars'. introcs.assert_equals( '2 United States Dollars', a1.get_lhs( '{ "ok":true, "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }' )) #test procedure for a1.get_rhs: a1.get_rhs returns the string inside double quotes immediately following the keyword "rhs". If JSON is '{ "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }', the function a1.get_rhs returns '1.727138 Euros'. introcs.assert_equals( '1.727138 Euros', a1.get_rhs( '{"ok": true, "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }' )) #test procedure for a1.has_error: a1.has_error returns True if the query has an error. If JSON is '{ "lhs" : "", "rhs" : "", , "err" : "Source currency code is invalid." }' the function a1.has_error returns True, since the query has an error (it does NOT return "Source currency code is invalid"). introcs.assert_equals( True, a1.has_error( '{"ok": true, "lhs" : "", "rhs" : "", "err" : "Source currency code is invalid." }' )) #test procedure for a1.get_lhs: a1.get_lhs returns the string inside double quotes immediately following "lhs". If JSON is '{ "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }' the function a1.get_lhs returns "2 United States Dollars". introcs.assert_equals( "2 United States Dollars", a1.get_lhs( '{"ok": true, "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }' )) #test procedure for a1.get_rhs: a1.get_rhs returns the string inside double quotes immediately following "rhs". If JSON is '{ "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }', the function a1.get_rhs returns "1.727138 Euros". introcs.assert_equals( "1.727138 Euros", a1.get_rhs( '{"ok": true, "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }' )) #test procedure for a1.has_error: a1.has_error returns False if the query is "valid". It does NOT return "valid". introcs.assert_equals( False, a1.has_error( '{"ok": true, "lhs" : "2 United States Dollars", "rhs" : "1.727138 Euros", "err" : "" }' )) #test procedure for a1.has_error: a1.has_error returns True if the query has an error. It does NOT return "Source currency code is invalid". introcs.assert_equals( True, a1.has_error( '{ "ok":false, "lhs":"", "rhs":"", "err":"Exchange currency code is invalid." }' ))
def test_has_error(self): self.assertFalse(has_error("California", json1)) self.assertFalse(has_error("123", json2)) self.assertFalse(has_error("Del", json3)) self.assertTrue(has_error(" ", json2)) self.assertTrue(has_error("#%!", json3))
def test_has_error(self): self.assertTrue(has_error("Delhi",string1)) self.assertTrue(has_error("Paris",string2)) self.assertTrue(has_error("Jaipur",string3)) self.assertTrue(has_error("Hyderabad",string4)) self.assertTrue(has_error("Singapore",string5))