update
This commit is contained in:
parent
d64226f44e
commit
077ff40fd6
@ -390,21 +390,34 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import unittest\n",
|
||||
"class TestStringMethods(unittest.TestCase):\n",
|
||||
" def test_upper(self):\n",
|
||||
" self.assertEqual('foo'.upper(), 'FOO')\n",
|
||||
" def test_isupper(self):\n",
|
||||
" self.assertTrue('FOO'.isupper())\n",
|
||||
" self.assertFalse('Foo'.isupper())\n",
|
||||
" def test_split(self):\n",
|
||||
" s = 'hello world'\n",
|
||||
" self.assertEqual(s.split(), ['hello', 'world'])\n",
|
||||
" # check that s.split fails when the separator is not a string\n",
|
||||
" with self.assertRaises(TypeError): \n",
|
||||
" s.split(2)\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" unittest.main()"
|
||||
"import unittest \n",
|
||||
"class TestStringMethods(unittest.TestCase): \n",
|
||||
" def test_upper(self): \n",
|
||||
" # This function tests whether 'foo' in lowercase converts to uppercase correctly.\n",
|
||||
" # If not, it will fail.\n",
|
||||
" self.assertEqual('foo'.upper(), 'FOO') \n",
|
||||
" def test_isupper(self): \n",
|
||||
" # This function tests two things:\n",
|
||||
" # 1) The string 'FOO' is already in uppercase and therefore should return True when\n",
|
||||
" # the method .isupper() is called on it. If not, it will fail.\n",
|
||||
" # 2) The string 'Foo' is not entirely in uppercase (it contains a lowercase letter)\n",
|
||||
" # and therefore should return False when the method .isupper() is called on it.\n",
|
||||
" # If not, it will also fail.\n",
|
||||
" self.assertTrue('FOO'.isupper()) \n",
|
||||
" self.assertFalse('Foo'.isupper()) \n",
|
||||
" def test_split(self): \n",
|
||||
" # This function tests the split method of strings:\n",
|
||||
" # It first creates a string 'hello world', and checks whether it is correctly split\n",
|
||||
" # into two separate words when the method .split() is called on it. If not, it will fail.\n",
|
||||
" s = 'hello world' \n",
|
||||
" self.assertEqual(s.split(), ['hello', 'world']) \n",
|
||||
" # This tests that if you call s.split(2) (where 2 isn't a string separator),\n",
|
||||
" # Python raises a TypeError. If it doesn’t or if it wrongly returns something else,\n",
|
||||
" # the test will fail.\n",
|
||||
" with self.assertRaises(TypeError): \n",
|
||||
" s.split(2) \n",
|
||||
"if __name__ == '__main__': \n",
|
||||
" unittest.main() \n"
|
||||
]
|
||||
},
|
||||
{
|
||||
@ -501,6 +514,13 @@
|
||||
"\ttest_results = result_file.read()\n",
|
||||
"print(test_results)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
Loading…
Reference in New Issue
Block a user