From 077ff40fd632ffb84ace0051e5ce96928ba27929 Mon Sep 17 00:00:00 2001 From: Woose Date: Mon, 27 Jan 2025 15:06:36 +0300 Subject: [PATCH] update --- module5.ipynb | 50 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/module5.ipynb b/module5.ipynb index a8b19f9..6d0b048 100644 --- a/module5.ipynb +++ b/module5.ipynb @@ -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": {