From eaf78a53a5968f436a4636bc5370d29396bd2d0b Mon Sep 17 00:00:00 2001 From: Ekaterina Levchenko Date: Fri, 20 Feb 2026 09:41:09 +0100 Subject: [PATCH] Solution --- __pycache__/testing.cpython-311.pyc | Bin 0 -> 24265 bytes lab-python-error-handling.ipynb | 136 +++++++++++++++++- testing.py | 208 ++++++++++++++++++++++++++++ 3 files changed, 340 insertions(+), 4 deletions(-) create mode 100644 __pycache__/testing.cpython-311.pyc create mode 100644 testing.py diff --git a/__pycache__/testing.cpython-311.pyc b/__pycache__/testing.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b10e0cc0b197f06f8af644308f1a2cfa2d065305 GIT binary patch literal 24265 zcmeG^TTmNUmaUcq0t?|Mc07JG7;GyxV2quNCmF{!_=Ro!0E~lU0wIyxk^u#0 zsjcjUq&$<%)THcr?aC>fz$V^ucI}$f)JzpSo2m8IB(>^PyW&z+KBnepsQvLQGgGs! zt<9cuTixmwNPq(wQ@f%$efz%8eVlXdIrrXoi;4;v_$j}8EAXd{4D(z3(0**nG5Iz) zt}+56Sb|KO`nI%L;F}GyJ=Qj>1^ui+TaUfXPTjU(UQd2oevhNgLBH+6f}X;*!k#5< zOM0AbPVmcng=s4i@&UR82f$*X0N_%g5a2Rl3Bcuo6W|J=2;fS=1#nd-BNV@FX)6(y z!q;kH8NfBda)3_=mL|r%Vgf7N=(Z&Dh$uw8BDe~Cyf+di0Y2zvlXfX0h?kPKp0FUg zt;u3u@&*E)V7N~tUS1M4k7#di$|Fw*bOs`l*OF=pd|`W8;eYaV@O_ne)qa&>nZwMm zeVFmFg5?#5z(z1$>er>GeFsv#hbigrb$dh)VVEwht(kWq^u1IZhPiBs?w?BChuyMAv_2ye)v^AmhW+_ zgS;epJQ5BXj^l=g9(Gl?NFtG{#h`e}>lZ`a;p+OZH`*hHB2u-$NBGKK684Ic6bN-z z_laV64fqb!R0sJEkLIZC9fM9MlB@lbE2Ed<(n9rTd-gIAUmYrpav+OhHwojegWM`$~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*G;7ga^gW#Ai!x)&wU?!=*AHiju8D=t@`Or?vNM>z}tvCegcF-kD z95z8;mIVQ#YQCDz zHnQXgo*&c8>41PeTgN6&wsElVDs(G^5(D0WqXveJs*~STK3G;G_>;{x;E`AEw9+T)!qK&`3o;yp1{T= z*zZ8ZTG5Szflyy$m}DFP;QUK?N!SS&Rh+!wOr0~I9w%CVv|U2|f6_FyHmc9B!uMKz z_xvIFdQqKNhb#wh1_7opvjD=B0|)}gVYUGSj&*Gs~MbhbjqTtJv9Sr%rhWOoQ=~}VDL5p zkzsDW|Rn}tE3&*8}9rJ z^{zpw`!wQ=o6(IYK9l)y)vmYO(@RD%cnksZh$*K&)xCDuEacY^PH6%IL_ynYhqcbP z&kpLl5)k8bqRd?hu<9soM|1%W9mX|?*4#i6PO&W*be4S{8|M_;hOL7ywRyk~VuKez zeGRf3b-cSXRJ`%lc_0RR_-sMqN3CI1eeNX(^u03TQ_7R!C6c!>VpXNrdC z-+g9X!u;H4)+Wr)eWoli-E*ILCXxMlkXK}JKVWpQL3dHVj885jbSb9QLAg0JGqO1} fBj*h+C*0nrfg#5O&WU;JU|mLP7luv+bmsjp+a^{* literal 0 HcmV?d00001 diff --git a/lab-python-error-handling.ipynb b/lab-python-error-handling.ipynb index 3e50ef8..ec555be 100644 --- a/lab-python-error-handling.ipynb +++ b/lab-python-error-handling.ipynb @@ -41,18 +41,146 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, + "id": "2f4d7695", + "metadata": {}, + "outputs": [], + "source": [ + "from testing import *\n", + "import unittest" + ] + }, + { + "cell_type": "code", + "execution_count": 70, "id": "cc2c441d-9dcf-4817-b097-cf6cbe440846", "metadata": {}, "outputs": [], "source": [ - "# your code goes here" + "def greater(a,b):\n", + " try:\n", + " return a if a > b else b\n", + " except TypeError:\n", + " print(f\"Warning: Comparing {a} and {b} as str\")\n", + " a = str(a)\n", + " b = str(b)\n", + " return a if a > b else b\n" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "id": "a1a27ebd", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.033s\n", + "\n", + "OK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Warning: Comparing sdf and 213 as str\n" + ] + }, + { + "data": { + "text/plain": [ + "'sdf'" + ] + }, + "execution_count": 72, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "test_greater(greater)\n", + "\n", + "greater(\"sdf\", 213)" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "id": "3484cf5d", + "metadata": {}, + "outputs": [], + "source": [ + "class EmptyListParameter(Exception):\n", + " def __init__(self, message):\n", + " self.message = message\n", + " super().__init__(message)\n", + "\n", + "def greatest(numbers):\n", + " if not numbers: # if numbers is empty list\n", + " raise EmptyListParameter(\"You passed empty list\")\n", + " \n", + " biggest = numbers[0]\n", + " for number in numbers:\n", + " if number > biggest:\n", + " biggest = number \n", + " return biggest\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "id": "6154f9e0", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.025s\n", + "\n", + "OK\n" + ] + }, + { + "ename": "EmptyListParameter", + "evalue": "You passed empty list", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mEmptyListParameter\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[79]\u001b[39m\u001b[32m, line 3\u001b[39m\n\u001b[32m 1\u001b[39m test_greatest(greatest)\n\u001b[32m----> \u001b[39m\u001b[32m3\u001b[39m \u001b[43mgreatest\u001b[49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[78]\u001b[39m\u001b[32m, line 8\u001b[39m, in \u001b[36mgreatest\u001b[39m\u001b[34m(numbers)\u001b[39m\n\u001b[32m 6\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mgreatest\u001b[39m(numbers):\n\u001b[32m 7\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m numbers: \u001b[38;5;66;03m# if numbers is empty list\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m8\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m EmptyListParameter(\u001b[33m\"\u001b[39m\u001b[33mYou passed empty list\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m 10\u001b[39m biggest = numbers[\u001b[32m0\u001b[39m]\n\u001b[32m 11\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m number \u001b[38;5;129;01min\u001b[39;00m numbers:\n", + "\u001b[31mEmptyListParameter\u001b[39m: You passed empty list" + ] + } + ], + "source": [ + "test_greatest(greatest)\n", + "\n", + "greatest([])" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1c262250", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "ironhack_prework", "language": "python", "name": "python3" }, @@ -66,7 +194,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.11.14" } }, "nbformat": 4, diff --git a/testing.py b/testing.py new file mode 100644 index 0000000..6a247a7 --- /dev/null +++ b/testing.py @@ -0,0 +1,208 @@ +import unittest +import random +from functools import reduce +from math import factorial +from statistics import stdev, mode +from string import ascii_lowercase, ascii_uppercase, digits + + +def test_greater(fn): + class TestKnown(unittest.TestCase): + def __init__(self, input, output): + super(TestKnown, self).__init__() + self.input = input + self.output = output + + def runTest(self): + self.assertEqual(fn(*self.input), self.output, f"Should be {self.output}") + suite = unittest.TestSuite() + for _ in range(100): + a,b = random.randint(-1000,1000),random.randint(-1000,1000) + suite.addTest(TestKnown([a,b],max([a,b]))) + unittest.TextTestRunner().run(suite) + +def test_greatest(fn): + class TestKnown(unittest.TestCase): + def __init__(self, input, output): + super(TestKnown, self).__init__() + self.input = input + self.output = output + + def runTest(self): + self.assertEqual(fn(self.input), self.output, f"Should be {self.output}") + suite = unittest.TestSuite() + for _ in range(100): + arr = [random.randint(-1000,1000) for _ in range(random.randint(10,100))] + suite.addTest(TestKnown(arr,max(arr))) + unittest.TextTestRunner().run(suite) + +def test_sum(fn): + class TestKnown(unittest.TestCase): + def __init__(self, input, output): + super(TestKnown, self).__init__() + self.input = input + self.output = output + + def runTest(self): + self.assertEqual(fn(self.input), self.output, f"Should be {self.output}") + suite = unittest.TestSuite() + for _ in range(100): + arr = [random.randint(-1000,1000) for _ in range(random.randint(10,100))] + suite.addTest(TestKnown(arr,sum(arr))) + unittest.TextTestRunner().run(suite) + + +def test_mult(fn): + class TestKnown(unittest.TestCase): + def __init__(self, input, output): + super(TestKnown, self).__init__() + self.input = input + self.output = output + + def runTest(self): + self.assertEqual(fn(self.input), self.output, f"Should be {self.output}") + suite = unittest.TestSuite() + for _ in range(100): + arr = [random.randint(-10,10) for _ in range(random.randint(10,100))] + suite.addTest(TestKnown(arr,reduce(lambda a,b:a*b,arr,1))) + unittest.TextTestRunner().run(suite) + +def test_operations(fn): + class TestKnown(unittest.TestCase): + def __init__(self, input, output): + super(TestKnown, self).__init__() + self.input = input + self.output = output + + def runTest(self): + self.assertEqual(fn(*self.input), self.output, f"Should be {self.output}") + suite = unittest.TestSuite() + for _ in range(100): + arr = ([random.randint(-10,10) for _ in range(random.randint(10,100))], random.choice(["+","*"])) + def ans(arr,op): + if op =="+": return sum(arr) + else: return reduce(lambda a,b:a*b,arr,1) + suite.addTest(TestKnown(arr,ans(*arr))) + unittest.TextTestRunner().run(suite) + +def test_factorial(fn): + class TestKnown(unittest.TestCase): + def __init__(self, input, output): + super(TestKnown, self).__init__() + self.input = input + self.output = output + + def runTest(self): + self.assertEqual(fn(self.input), self.output, f"Should be {self.output}") + suite = unittest.TestSuite() + for _ in range(100): + n = random.randint(1,100) + suite.addTest(TestKnown(n,factorial(n))) + unittest.TextTestRunner().run(suite) + + +def test_unique(fn): + class TestKnown(unittest.TestCase): + def __init__(self, input, output): + super(TestKnown, self).__init__() + self.input = input + self.output = output + + def runTest(self): + self.assertEqual(set(fn(self.input)), self.output, f"Should be {self.output}") + suite = unittest.TestSuite() + for _ in range(100): + arr = [random.randint(-100,100) for _ in range(random.randint(10,1000))] + suite.addTest(TestKnown(arr,set(arr))) + unittest.TextTestRunner().run(suite) + +def test_mode(fn): + class TestKnown(unittest.TestCase): + def __init__(self, input, output): + super(TestKnown, self).__init__() + self.input = input + self.output = output + + def runTest(self): + self.assertEqual(fn(self.input), self.output, f"Should be {self.output}") + suite = unittest.TestSuite() + for _ in range(100): + arr = [random.randint(1,25) for _ in range(random.randint(100,125))] + 50 * [random.randint(1,25)] + suite.addTest(TestKnown(arr,mode(arr))) + unittest.TextTestRunner().run(suite) + +def test_stdev(fn): + class TestKnown(unittest.TestCase): + def __init__(self, input, output): + super(TestKnown, self).__init__() + self.input = input + self.output = output + + def runTest(self): + self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f"Should be {self.output}") + suite = unittest.TestSuite() + for _ in range(100): + arr = [random.randint(-1000,1000) for _ in range(random.randint(10,100))] + suite.addTest(TestKnown(arr,stdev(arr))) + unittest.TextTestRunner().run(suite) + +pangrams = ["Waltz, nymph, for quick jigs vex Bud.", +"Sphinx of black quartz, judge my vow.", +"Pack my box with five dozen liquor jugs.", +"Glib jocks quiz nymph to vex dwarf.", +"Jackdaws love my big sphinx of quartz.", +"The five boxing wizards jump quickly.", +"How vexingly quick daft zebras jump!", +"Quick zephyrs blow, vexing daft Jim.", +"Two driven jocks help fax my big quiz.", +"The jay, pig, fox, zebra and my wolves quack!", +"Sympathizing would fix Quaker objectives.", +"A wizard's job is to vex chumps quickly in fog.", +"Watch 'Jeopardy!', Alex Trebek's fun TV quiz game.", +"By Jove, my quick study of lexicography won a prize!", +"Waxy and quivering, jocks fumble the pizza."] + +def test_pangram(fn): + class TestKnown(unittest.TestCase): + def __init__(self, input, output): + super(TestKnown, self).__init__() + self.input = input + self.output = output + def runTest(self): + self.assertEqual(fn(self.input), self.output, f"Should be {self.output}") + suite = unittest.TestSuite() + tests = pangrams + ["".join([random.choice(ascii_lowercase) for _ in range(random.randint(25,100))]) for _ in range(15)] + for test in tests: + suite.addTest(TestKnown(test,set(ascii_lowercase).issubset(set(test.lower())))) + unittest.TextTestRunner().run(suite) + +def test_alpha(fn): + class TestKnown(unittest.TestCase): + def __init__(self, input, output): + super(TestKnown, self).__init__() + self.input = input + self.output = output + + def runTest(self): + self.assertEqual(fn(self.input), self.output, f"Should be {self.output}") + suite = unittest.TestSuite() + tests = [",".join(["".join([random.choice(ascii_lowercase) for _ in range(random.randint(4,10))]) for _ in range(random.randint(4,25))]) for _ in range(100)] + for test in tests: + suite.addTest(TestKnown(test,",".join(sorted(test.split(","))))) + unittest.TextTestRunner().run(suite) + +def test_pass(fn): + class TestKnown(unittest.TestCase): + def __init__(self, input_, output): + super(TestKnown, self).__init__() + self.input_ = input_ + self.output = output + + def runTest(self): + self.assertEqual(fn(self.input_), self.output, f"For this password, {self.input_}, the output should be {self.output}") + suite = unittest.TestSuite() + check_p = lambda string: sum([len(set(string)&set(c))>0 for c in [ascii_lowercase, ascii_uppercase, digits, "#@!$%&()^*[]{}"]] + [len(string) >= 8]) >= 5 + tests = ["".join([random.choice(ascii_lowercase*3+ascii_uppercase+digits+"#@!$%&()^*[]{}") for _ in range(random.randint(2,16))]) for _ in range(100)] + for test in tests: + suite.addTest(TestKnown(test,check_p(test))) + unittest.TextTestRunner().run(suite) \ No newline at end of file