From 8412acdc30f6e1b5c245a880d027e4b34dddd12c Mon Sep 17 00:00:00 2001 From: manezhah Date: Sun, 12 Jan 2025 13:21:13 -0500 Subject: [PATCH 1/8] solution 1 :Implement multiply_two_numbers function with tests --- solutions/multiply_two_numbers.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 solutions/multiply_two_numbers.py diff --git a/solutions/multiply_two_numbers.py b/solutions/multiply_two_numbers.py new file mode 100644 index 000000000..fe30683f8 --- /dev/null +++ b/solutions/multiply_two_numbers.py @@ -0,0 +1,27 @@ +""" +A module for multiplying two integers. + +Modul contents: + -multiply_two_numbers: A fnuction to multiply two integers. +created 2025-01-04 +@author: Manezhah Mohmand +""" + + +def multiply_two_numbers(a: int, b: int) -> int: + """Multiplies two integers and returns the product. + + parameters: + a (int): The first integer + b (int):The second integer + + Returns: + int: The product of the two integers + + Raises: + TypeError:If the input contains non-integer elements. + Examples: + >>> multiply_two_numbers(2, 3) + 6 + """ + return a * b From d6b44c02efb73a02079a12ef88ef642c8bacfbcf Mon Sep 17 00:00:00 2001 From: manezhah Date: Sun, 12 Jan 2025 13:27:40 -0500 Subject: [PATCH 2/8] Multiply Two Numbers function --- solutions/tests/__init__.py | 1 - solutions/tests/test_find_max.py | 0 solutions/tests/test_multiply_two_numbers.py | 30 ++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) delete mode 100644 solutions/tests/__init__.py create mode 100644 solutions/tests/test_find_max.py create mode 100644 solutions/tests/test_multiply_two_numbers.py diff --git a/solutions/tests/__init__.py b/solutions/tests/__init__.py deleted file mode 100644 index 8b1378917..000000000 --- a/solutions/tests/__init__.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/solutions/tests/test_find_max.py b/solutions/tests/test_find_max.py new file mode 100644 index 000000000..e69de29bb diff --git a/solutions/tests/test_multiply_two_numbers.py b/solutions/tests/test_multiply_two_numbers.py new file mode 100644 index 000000000..7ddc2ddfd --- /dev/null +++ b/solutions/tests/test_multiply_two_numbers.py @@ -0,0 +1,30 @@ +""" +Test module for multiply two numbers function. + +Created 2025-01-04 + +@author: Manezhah Mohmand +""" + +import unittest +from solutions.multiply_two_numbers import multiply_two_numbers + + +class TestMultiplyTwoNumbers(unittest.TestCase): + """Tests for multiply_two_numbers function.""" + + def test_positive_numbers(self): + """It should return the product of two positive numbers.""" + self.assertEqual(multiply_two_numbers(2, 3), 6) + + def test_negative_numbers(self): + """It should return the product of two negative numbers.""" + self.assertEqual(multiply_two_numbers(-2, -3), 6) + + def test_mixed_sign_numbers(self): + """It should return the product of one positive and one negative number.""" + self.assertEqual(multiply_two_numbers(-2, 3), -6) + + +if __name__ == "__main__": + unittest.main() From c4754fe084b192c5a72d3598046c7ed3f37b6e35 Mon Sep 17 00:00:00 2001 From: olumide-AI Date: Sun, 12 Jan 2025 12:11:36 -0800 Subject: [PATCH 3/8] Changes to my fixes for multiplytwonumber function --- solutions/multiply_two_numbers.py | 52 ++++++++++++------ solutions/tests/test_multiply_two_numbers.py | 55 ++++++++++++++++---- 2 files changed, 79 insertions(+), 28 deletions(-) diff --git a/solutions/multiply_two_numbers.py b/solutions/multiply_two_numbers.py index fe30683f8..b41a60d44 100644 --- a/solutions/multiply_two_numbers.py +++ b/solutions/multiply_two_numbers.py @@ -1,27 +1,45 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + """ -A module for multiplying two integers. +A module for multiplying two integers. + +This module provides the multiply_two_numbers function, which multiplies +two integers and returns their product. + +Module Contents: + - multiply_two_numbers: A function to multiply two integers. -Modul contents: - -multiply_two_numbers: A fnuction to multiply two integers. -created 2025-01-04 -@author: Manezhah Mohmand +Created: 2025-01-04 +Author: Manezhah Mohmand """ -def multiply_two_numbers(a: int, b: int) -> int: - """Multiplies two integers and returns the product. +def multiply_two_numbers(num_one: int, num_two: int) -> int: + """ + Multiplies two integers and returns the product. + + Parameters: + num_one (int): The first integer. + num_two (int): The second integer. - parameters: - a (int): The first integer - b (int):The second integer + Returns: + int: The product of the two integers. - Returns: - int: The product of the two integers + Raises: + TypeError: If either num_one or num_two is not an integer. - Raises: - TypeError:If the input contains non-integer elements. Examples: - >>> multiply_two_numbers(2, 3) - 6 + >>> multiply_two_numbers(2, 3) + 6 + >>> multiply_two_numbers(-4, 5) + -20 + >>> multiply_two_numbers(-2, -3) + 6 + >>> multiply_two_numbers(0, 10) + 0 """ - return a * b + # input validation for defensive test + if not isinstance(num_one, int) or not isinstance(num_two, int): + raise TypeError("Both arguments must be integers.") + return num_one * num_two diff --git a/solutions/tests/test_multiply_two_numbers.py b/solutions/tests/test_multiply_two_numbers.py index 7ddc2ddfd..9c914ba28 100644 --- a/solutions/tests/test_multiply_two_numbers.py +++ b/solutions/tests/test_multiply_two_numbers.py @@ -1,9 +1,14 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + """ -Test module for multiply two numbers function. +Test module for the multiply_two_numbers function. -Created 2025-01-04 +This module contains unit tests for the multiply_two_numbers function, +including standard cases, boundary cases, and defensive tests. -@author: Manezhah Mohmand +Created: 2025-01-04 +Author: Manezhah Mohmand """ import unittest @@ -11,20 +16,48 @@ class TestMultiplyTwoNumbers(unittest.TestCase): - """Tests for multiply_two_numbers function.""" - - def test_positive_numbers(self): - """It should return the product of two positive numbers.""" + """ + Unit tests for the `multiply_two_numbers` function. + + This test suite covers: + - Standard cases (e.g., positive and negative integers). + - Boundary cases (e.g., zero). + - Defensive tests for invalid inputs. + """ + + # Standard cases + def test_two_positive_numbers(self): + """It should return the product of two positive integers.""" self.assertEqual(multiply_two_numbers(2, 3), 6) - def test_negative_numbers(self): - """It should return the product of two negative numbers.""" + def test_two_negative_numbers(self): + """It should return the product of two negative integers.""" self.assertEqual(multiply_two_numbers(-2, -3), 6) - def test_mixed_sign_numbers(self): - """It should return the product of one positive and one negative number.""" + def test_positive_and_negative_number(self): + """It should return the product of a positive and a negative integer.""" self.assertEqual(multiply_two_numbers(-2, 3), -6) + # Boundary cases + def test_zero_with_positive_number(self): + """It should return 0 when one number is 0 and the other is positive.""" + self.assertEqual(multiply_two_numbers(0, 5), 0) + + def test_zero_with_negative_number(self): + """It should return 0 when one number is 0 and the other is negative.""" + self.assertEqual(multiply_two_numbers(0, -7), 0) + + # Defensive tests + def test_non_integer_input(self): + """It should raise a TypeError when the inputs are not integers.""" + with self.assertRaises(TypeError): + multiply_two_numbers(2.5, 3) + + def test_string_input(self): + """It should raise a TypeError when one or both inputs are strings.""" + with self.assertRaises(TypeError): + multiply_two_numbers("2", "3") + if __name__ == "__main__": unittest.main() From 8054b4b6791911da416db74b28dbb1aa26fa8a56 Mon Sep 17 00:00:00 2001 From: olumide-AI Date: Sun, 12 Jan 2025 12:20:36 -0800 Subject: [PATCH 4/8] change the import to relative instead of absolute to attempt to pass pytest --- solutions/tests/test_multiply_two_numbers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/tests/test_multiply_two_numbers.py b/solutions/tests/test_multiply_two_numbers.py index 9c914ba28..2279f9292 100644 --- a/solutions/tests/test_multiply_two_numbers.py +++ b/solutions/tests/test_multiply_two_numbers.py @@ -12,7 +12,7 @@ """ import unittest -from solutions.multiply_two_numbers import multiply_two_numbers +from ..multiply_two_numbers import multiply_two_numbers class TestMultiplyTwoNumbers(unittest.TestCase): From bc8f6d284c4a1cfcda075cd5beb9a82a47cd6771 Mon Sep 17 00:00:00 2001 From: Yuri Spizhovyi Date: Sun, 12 Jan 2025 14:36:51 -0800 Subject: [PATCH 5/8] Delete solutions/tests/test_find_max.py Signed-off-by: Yuri Spizhovyi --- solutions/tests/test_find_max.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 solutions/tests/test_find_max.py diff --git a/solutions/tests/test_find_max.py b/solutions/tests/test_find_max.py deleted file mode 100644 index e69de29bb..000000000 From bedf00cbc40f2ed8ae821fd809219b90e11dcd8a Mon Sep 17 00:00:00 2001 From: Yuri Spizhovyi Date: Sun, 12 Jan 2025 14:37:57 -0800 Subject: [PATCH 6/8] Update test_multiply_two_numbers.py Signed-off-by: Yuri Spizhovyi --- solutions/tests/test_multiply_two_numbers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/tests/test_multiply_two_numbers.py b/solutions/tests/test_multiply_two_numbers.py index 2279f9292..9c914ba28 100644 --- a/solutions/tests/test_multiply_two_numbers.py +++ b/solutions/tests/test_multiply_two_numbers.py @@ -12,7 +12,7 @@ """ import unittest -from ..multiply_two_numbers import multiply_two_numbers +from solutions.multiply_two_numbers import multiply_two_numbers class TestMultiplyTwoNumbers(unittest.TestCase): From c17038bc565a0aeaa533d5a65801c8f7d10f924d Mon Sep 17 00:00:00 2001 From: Yuri Spizhovyi Date: Sun, 12 Jan 2025 14:44:27 -0800 Subject: [PATCH 7/8] Fix import statement in the test file. --- solutions/tests/test_multiply_two_numbers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/solutions/tests/test_multiply_two_numbers.py b/solutions/tests/test_multiply_two_numbers.py index 9c914ba28..af3775896 100644 --- a/solutions/tests/test_multiply_two_numbers.py +++ b/solutions/tests/test_multiply_two_numbers.py @@ -12,6 +12,7 @@ """ import unittest + from solutions.multiply_two_numbers import multiply_two_numbers From 8134182736caf668b7b1f110384e8b864629b9a0 Mon Sep 17 00:00:00 2001 From: Yuri Spizhovyi Date: Sun, 12 Jan 2025 14:49:38 -0800 Subject: [PATCH 8/8] restore init file --- solutions/tests/__init__.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 solutions/tests/__init__.py diff --git a/solutions/tests/__init__.py b/solutions/tests/__init__.py new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/solutions/tests/__init__.py @@ -0,0 +1 @@ +