From d82c8ba3e3bbe4237e008bf22b0f1b3ee52e1439 Mon Sep 17 00:00:00 2001 From: Moealfadil <142026026+Moealfadil@users.noreply.github.com> Date: Sun, 29 Dec 2024 18:43:56 +0200 Subject: [PATCH 01/45] CI checks --- solutions/IsPrime.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/solutions/IsPrime.py b/solutions/IsPrime.py index a943faff5..656de9cfd 100644 --- a/solutions/IsPrime.py +++ b/solutions/IsPrime.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ -A module for finding if an integer is prime. +Module for finding if an integer is prime. Module contents: - IsPrime: finds if an integer is prime. @@ -30,6 +30,8 @@ def IsPrime(a: int) -> str: prime >>> IsPrime(2.5) invalid input + >>> IsPrime(-1) + not prime """ if not isinstance(a, int): return "invalid input" From 553b1c326733ed0e1efc60514d3e9ec5b7f221af Mon Sep 17 00:00:00 2001 From: raghad598 Date: Sat, 4 Jan 2025 15:51:18 +0200 Subject: [PATCH 02/45] my 2nd solution --- solutions/area_of_circle.py | 40 ++++++++++++++++++++++++++ solutions/tests/test_area_of_circle.py | 27 +++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 solutions/area_of_circle.py create mode 100644 solutions/tests/test_area_of_circle.py diff --git a/solutions/area_of_circle.py b/solutions/area_of_circle.py new file mode 100644 index 000000000..6a1c54760 --- /dev/null +++ b/solutions/area_of_circle.py @@ -0,0 +1,40 @@ +""" +A module for calculating the area of a circle. + +Module contents: + - calculate_circle_area: calculates the area of a circle given its radius. + +Created on 01 04 2025 +@author: Raghad +""" +import math + +def calculate_circle_area(radius: float) -> float: + """Calculate the area of a circle given its radius. + + Parameters: + radius: float, the radius of the circle + + Returns -> float: area of the circle + + Raises: + ValueError: if the radius is negative + + >>> calculate_circle_area(5) + 78.53981633974483 + >>> calculate_circle_area(0) + 0.0 + >>> calculate_circle_area(-1) + Traceback (most recent call last): + ... + ValueError: Radius cannot be negative + """ + if radius < 0: + raise ValueError("Radius cannot be negative") + + return math.pi * radius**2 + +if _name_ == "_main_": + radius = 5 + area = calculate_circle_area(radius) + print("Area of the circle:", area) diff --git a/solutions/tests/test_area_of_circle.py b/solutions/tests/test_area_of_circle.py new file mode 100644 index 000000000..5204bb9ea --- /dev/null +++ b/solutions/tests/test_area_of_circle.py @@ -0,0 +1,27 @@ +import unittest +import math +from solutions.area_of_circle import calculate_circle_area +# Assuming the function is already defined as: +# def calculate_circle_area(radius): +# if radius < 0: +# return "Radius cannot be negative" +# area = math.pi * radius**2 +# return area + +class TestCircleArea(unittest.TestCase): + + def test_positive_radius(self): + self.assertAlmostEqual(calculate_circle_area(5), math.pi * 5**2) + self.assertAlmostEqual(calculate_circle_area(10), math.pi * 10**2) + + def test_zero_radius(self): + self.assertEqual(calculate_circle_area(0), 0) + + def test_negative_radius(self): + self.assertEqual(calculate_circle_area(-5), "Radius cannot be negative") + + def test_large_radius(self): + self.assertAlmostEqual(calculate_circle_area(1000), math.pi * 1000**2) + +if __name__ == '__main__': + unittest.main() From c7cc0de2a9ceeab88cefa16b1021fc065c7b8bf6 Mon Sep 17 00:00:00 2001 From: Raghad Abdul Rahim Date: Wed, 8 Jan 2025 11:57:10 +0300 Subject: [PATCH 03/45] Update test_area_of_circle.py --- solutions/tests/test_area_of_circle.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/solutions/tests/test_area_of_circle.py b/solutions/tests/test_area_of_circle.py index 5204bb9ea..64ec98969 100644 --- a/solutions/tests/test_area_of_circle.py +++ b/solutions/tests/test_area_of_circle.py @@ -1,12 +1,16 @@ +""" +Unit test module for area_of_circle.py + +Module contents: + - Unit Test cases for calculating the area of circle + +Created on 01 01 2025 +@author: Raghad +""" + import unittest import math from solutions.area_of_circle import calculate_circle_area -# Assuming the function is already defined as: -# def calculate_circle_area(radius): -# if radius < 0: -# return "Radius cannot be negative" -# area = math.pi * radius**2 -# return area class TestCircleArea(unittest.TestCase): From 8537a1b40c951ff2bd5f1b8ff55d4ee905596caf Mon Sep 17 00:00:00 2001 From: Raghad Abdul Rahim Date: Wed, 8 Jan 2025 11:58:13 +0300 Subject: [PATCH 04/45] Update area_of_circle.py --- solutions/area_of_circle.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/solutions/area_of_circle.py b/solutions/area_of_circle.py index 6a1c54760..e9b685c2c 100644 --- a/solutions/area_of_circle.py +++ b/solutions/area_of_circle.py @@ -33,8 +33,3 @@ def calculate_circle_area(radius: float) -> float: raise ValueError("Radius cannot be negative") return math.pi * radius**2 - -if _name_ == "_main_": - radius = 5 - area = calculate_circle_area(radius) - print("Area of the circle:", area) From 71f917cab1f5171e0f23f22584e5ae9d0ea3cb3f Mon Sep 17 00:00:00 2001 From: Raghad Abdul Rahim Date: Wed, 8 Jan 2025 12:04:44 +0300 Subject: [PATCH 05/45] Update test_area_of_circle.py --- solutions/tests/test_area_of_circle.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/solutions/tests/test_area_of_circle.py b/solutions/tests/test_area_of_circle.py index 64ec98969..7af9fd0bc 100644 --- a/solutions/tests/test_area_of_circle.py +++ b/solutions/tests/test_area_of_circle.py @@ -21,9 +21,6 @@ def test_positive_radius(self): def test_zero_radius(self): self.assertEqual(calculate_circle_area(0), 0) - def test_negative_radius(self): - self.assertEqual(calculate_circle_area(-5), "Radius cannot be negative") - def test_large_radius(self): self.assertAlmostEqual(calculate_circle_area(1000), math.pi * 1000**2) From 6969b5e0e56858d66760a95a0fc1410c23aace4e Mon Sep 17 00:00:00 2001 From: Raghad Abdul Rahim Date: Wed, 8 Jan 2025 12:06:48 +0300 Subject: [PATCH 06/45] Update test_area_of_circle.py --- solutions/tests/test_area_of_circle.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/solutions/tests/test_area_of_circle.py b/solutions/tests/test_area_of_circle.py index 7af9fd0bc..23581e20e 100644 --- a/solutions/tests/test_area_of_circle.py +++ b/solutions/tests/test_area_of_circle.py @@ -12,17 +12,18 @@ import math from solutions.area_of_circle import calculate_circle_area -class TestCircleArea(unittest.TestCase): +class TestCircleArea(unittest.TestCase): def test_positive_radius(self): self.assertAlmostEqual(calculate_circle_area(5), math.pi * 5**2) self.assertAlmostEqual(calculate_circle_area(10), math.pi * 10**2) - + def test_zero_radius(self): self.assertEqual(calculate_circle_area(0), 0) - + def test_large_radius(self): self.assertAlmostEqual(calculate_circle_area(1000), math.pi * 1000**2) -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main() From 6cb3ff7264c1658d6d8caf1d57849c17d712aa84 Mon Sep 17 00:00:00 2001 From: Raghad Abdul Rahim Date: Wed, 8 Jan 2025 12:07:10 +0300 Subject: [PATCH 07/45] Update area_of_circle.py --- solutions/area_of_circle.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/solutions/area_of_circle.py b/solutions/area_of_circle.py index e9b685c2c..59edce800 100644 --- a/solutions/area_of_circle.py +++ b/solutions/area_of_circle.py @@ -7,8 +7,10 @@ Created on 01 04 2025 @author: Raghad """ + import math + def calculate_circle_area(radius: float) -> float: """Calculate the area of a circle given its radius. @@ -31,5 +33,5 @@ def calculate_circle_area(radius: float) -> float: """ if radius < 0: raise ValueError("Radius cannot be negative") - + return math.pi * radius**2 From ecd0b07b3ff34cac74110c2ac5b904810561a1f8 Mon Sep 17 00:00:00 2001 From: raghad598 Date: Thu, 9 Jan 2025 10:50:03 +0200 Subject: [PATCH 08/45] resolved -comments --- solutions/area_of_circle.py | 21 ++++++++-------- solutions/tests/test_area_of_circle.py | 33 ++++++++++---------------- 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/solutions/area_of_circle.py b/solutions/area_of_circle.py index 59edce800..d88bb49fa 100644 --- a/solutions/area_of_circle.py +++ b/solutions/area_of_circle.py @@ -2,16 +2,14 @@ A module for calculating the area of a circle. Module contents: - - calculate_circle_area: calculates the area of a circle given its radius. + - area_of_circle: calculates the area of a circle given its radius. Created on 01 04 2025 @author: Raghad """ - import math - -def calculate_circle_area(radius: float) -> float: +def area_of_circle(radius: float) -> float: """Calculate the area of a circle given its radius. Parameters: @@ -22,16 +20,17 @@ def calculate_circle_area(radius: float) -> float: Raises: ValueError: if the radius is negative - >>> calculate_circle_area(5) + >>> area_of_circle(5) 78.53981633974483 - >>> calculate_circle_area(0) + >>> area_of_circle(0) 0.0 - >>> calculate_circle_area(-1) - Traceback (most recent call last): - ... - ValueError: Radius cannot be negative """ if radius < 0: raise ValueError("Radius cannot be negative") - + return math.pi * radius**2 + +if __name__ == "__main__": + radius = 5 + area = area_of_circle(radius) + print("Area of the circle:", area) diff --git a/solutions/tests/test_area_of_circle.py b/solutions/tests/test_area_of_circle.py index 23581e20e..04f431240 100644 --- a/solutions/tests/test_area_of_circle.py +++ b/solutions/tests/test_area_of_circle.py @@ -1,29 +1,22 @@ -""" -Unit test module for area_of_circle.py - -Module contents: - - Unit Test cases for calculating the area of circle - -Created on 01 01 2025 -@author: Raghad -""" - import unittest import math -from solutions.area_of_circle import calculate_circle_area - +from solutions.area_of_circle import area_of_circle class TestCircleArea(unittest.TestCase): + """Unit tests for the area_of_circle function.""" + def test_positive_radius(self): - self.assertAlmostEqual(calculate_circle_area(5), math.pi * 5**2) - self.assertAlmostEqual(calculate_circle_area(10), math.pi * 10**2) - + """Test the function with positive radius values.""" + self.assertAlmostEqual(area_of_circle(5), math.pi * 5**2) + self.assertAlmostEqual(area_of_circle(10), math.pi * 10**2) + def test_zero_radius(self): - self.assertEqual(calculate_circle_area(0), 0) - + """Test the function with a zero radius.""" + self.assertEqual(area_of_circle(0), 0) + def test_large_radius(self): - self.assertAlmostEqual(calculate_circle_area(1000), math.pi * 1000**2) - + """Test the function with a very large radius.""" + self.assertAlmostEqual(area_of_circle(1000), math.pi * 1000**2) -if __name__ == "__main__": +if __name__ == '__main__': unittest.main() From 71be2d3bb7791fc9d9d98d38efec9114a8a05c5f Mon Sep 17 00:00:00 2001 From: raghad598 Date: Thu, 9 Jan 2025 13:30:09 +0200 Subject: [PATCH 09/45] resolved-comments --- solutions/tests/test_area_of_circle.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/solutions/tests/test_area_of_circle.py b/solutions/tests/test_area_of_circle.py index 04f431240..77c1ead7f 100644 --- a/solutions/tests/test_area_of_circle.py +++ b/solutions/tests/test_area_of_circle.py @@ -1,5 +1,4 @@ import unittest -import math from solutions.area_of_circle import area_of_circle class TestCircleArea(unittest.TestCase): @@ -7,16 +6,16 @@ class TestCircleArea(unittest.TestCase): def test_positive_radius(self): """Test the function with positive radius values.""" - self.assertAlmostEqual(area_of_circle(5), math.pi * 5**2) - self.assertAlmostEqual(area_of_circle(10), math.pi * 10**2) + self.assertAlmostEqual(area_of_circle(5), 78.53981633974483) + self.assertAlmostEqual(area_of_circle(10), 314.1592653589793) def test_zero_radius(self): """Test the function with a zero radius.""" - self.assertEqual(area_of_circle(0), 0) + self.assertEqual(area_of_circle(0), 0.0) def test_large_radius(self): """Test the function with a very large radius.""" - self.assertAlmostEqual(area_of_circle(1000), math.pi * 1000**2) + self.assertAlmostEqual(area_of_circle(1000), 3141592.653589793) if __name__ == '__main__': unittest.main() From 2467889fd2684b43e95a36af589dc000bdcb45c9 Mon Sep 17 00:00:00 2001 From: raghad598 Date: Thu, 9 Jan 2025 17:13:15 +0200 Subject: [PATCH 10/45] ruff format --- solutions/area_of_circle.py | 5 ++++- solutions/cumulative_sum.py | 6 +++--- solutions/tests/test_area_of_circle.py | 10 ++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/solutions/area_of_circle.py b/solutions/area_of_circle.py index d88bb49fa..0ff68d67f 100644 --- a/solutions/area_of_circle.py +++ b/solutions/area_of_circle.py @@ -7,8 +7,10 @@ Created on 01 04 2025 @author: Raghad """ + import math + def area_of_circle(radius: float) -> float: """Calculate the area of a circle given its radius. @@ -27,9 +29,10 @@ def area_of_circle(radius: float) -> float: """ if radius < 0: raise ValueError("Radius cannot be negative") - + return math.pi * radius**2 + if __name__ == "__main__": radius = 5 area = area_of_circle(radius) diff --git a/solutions/cumulative_sum.py b/solutions/cumulative_sum.py index 2e77fb9d0..6cd87f1c1 100644 --- a/solutions/cumulative_sum.py +++ b/solutions/cumulative_sum.py @@ -44,9 +44,9 @@ def cumulative_sum(numbers: list) -> list: # Validate input assert numbers is not None, "Input cannot be None." assert isinstance(numbers, list), "Input must be a list of numeric values." - assert all( - isinstance(num, (int, float)) for num in numbers - ), "All elements in the list must be numeric." + assert all(isinstance(num, (int, float)) for num in numbers), ( + "All elements in the list must be numeric." + ) # Compute cumulative sums cumulative_list = [] current_sum = 0 diff --git a/solutions/tests/test_area_of_circle.py b/solutions/tests/test_area_of_circle.py index 77c1ead7f..ab40effe0 100644 --- a/solutions/tests/test_area_of_circle.py +++ b/solutions/tests/test_area_of_circle.py @@ -1,21 +1,23 @@ import unittest from solutions.area_of_circle import area_of_circle + class TestCircleArea(unittest.TestCase): """Unit tests for the area_of_circle function.""" - + def test_positive_radius(self): """Test the function with positive radius values.""" self.assertAlmostEqual(area_of_circle(5), 78.53981633974483) self.assertAlmostEqual(area_of_circle(10), 314.1592653589793) - + def test_zero_radius(self): """Test the function with a zero radius.""" self.assertEqual(area_of_circle(0), 0.0) - + def test_large_radius(self): """Test the function with a very large radius.""" self.assertAlmostEqual(area_of_circle(1000), 3141592.653589793) -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main() From a7106a5622de92087f270643d8e3caf1a7388b42 Mon Sep 17 00:00:00 2001 From: Muna Sattouf Date: Thu, 9 Jan 2025 21:13:51 +0200 Subject: [PATCH 11/45] added factorials function --- solutions/factorials.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 solutions/factorials.py diff --git a/solutions/factorials.py b/solutions/factorials.py new file mode 100644 index 000000000..00e1a1b74 --- /dev/null +++ b/solutions/factorials.py @@ -0,0 +1,38 @@ +""" +This module calculates the factorial of a positive number. +We define the factorial of a positive number as the product of all positive integer, +that are less than or equal to the number. +For example, factorials(5)=5*4*3*2*1=120 +""" +def factorials(n: int)->int: + """ + Calculates the facotrial of non-negative integer. + The argument, n, is a non-negative integer. + We choose (0<=n<=100). + Returns: + int, which is the factorials if the number. + Raises: + ValueError, if input is non-negative integer, or exceed max. value. + + Examples: + >>> factorials(4) + 24 + >>> factorials(0) + 1 + """ + + if not isinstance(n, int): + raise ValueError('input must be an integer') + + if n<0: + raise ValueError('input must be a non-negative integer') + + if n>100: + raise ValueError('Input must not exceed 100') + + # We shall use recursion. the base case is factorial of 0 or 1. + + if n == 1 or n == 0: + return 1 + else: + return n*factorials(n-1) \ No newline at end of file From 55badc20b7141247e70a43033efdd6b06312d434 Mon Sep 17 00:00:00 2001 From: Muna Sattouf Date: Thu, 9 Jan 2025 22:00:54 +0200 Subject: [PATCH 12/45] added function file --- solutions/factorials.py | 38 -------------------------------------- solutions/pyproject.toml | Bin 0 -> 28 bytes 2 files changed, 38 deletions(-) delete mode 100644 solutions/factorials.py create mode 100644 solutions/pyproject.toml diff --git a/solutions/factorials.py b/solutions/factorials.py deleted file mode 100644 index 00e1a1b74..000000000 --- a/solutions/factorials.py +++ /dev/null @@ -1,38 +0,0 @@ -""" -This module calculates the factorial of a positive number. -We define the factorial of a positive number as the product of all positive integer, -that are less than or equal to the number. -For example, factorials(5)=5*4*3*2*1=120 -""" -def factorials(n: int)->int: - """ - Calculates the facotrial of non-negative integer. - The argument, n, is a non-negative integer. - We choose (0<=n<=100). - Returns: - int, which is the factorials if the number. - Raises: - ValueError, if input is non-negative integer, or exceed max. value. - - Examples: - >>> factorials(4) - 24 - >>> factorials(0) - 1 - """ - - if not isinstance(n, int): - raise ValueError('input must be an integer') - - if n<0: - raise ValueError('input must be a non-negative integer') - - if n>100: - raise ValueError('Input must not exceed 100') - - # We shall use recursion. the base case is factorial of 0 or 1. - - if n == 1 or n == 0: - return 1 - else: - return n*factorials(n-1) \ No newline at end of file diff --git a/solutions/pyproject.toml b/solutions/pyproject.toml new file mode 100644 index 0000000000000000000000000000000000000000..ab7378221973ed0f2b62944821b8b55d12ac71f9 GIT binary patch literal 28 gcmezWFPfo*As+~H81xv57)lw^fH0PUmw}4`0DSNUYybcN literal 0 HcmV?d00001 From 2a54ed4bc3a81a2f2b5a0385bead71e967d98293 Mon Sep 17 00:00:00 2001 From: Muna Sattouf Date: Thu, 9 Jan 2025 22:08:50 +0200 Subject: [PATCH 13/45] edits --- solutions/leap_year.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 solutions/leap_year.py diff --git a/solutions/leap_year.py b/solutions/leap_year.py new file mode 100644 index 000000000..3f1cd90c9 --- /dev/null +++ b/solutions/leap_year.py @@ -0,0 +1,31 @@ +""" +The module checks whether a given year is a leap year. + +A year is a leap year if it is divisible by 4, +and if it is divisible by 100, it must also be divisible by 400. +""" + +def leap_year(year: int) -> bool: + """ + Checks whether the given year is a leap year. + + Argument: + year, a positive integer + + Returns: + boolean: True if the year is a leap year, false otherwise. + + Examples: + >>> leap_year(2024) + True + >>> leap_year(1900) + False + >>> leap_year(2021) + False + """ + if not isinstance(year, int): + raise ValueError("Year must be an integer") + if year < 0: + raise ValueError("Year must be positive integer") + + return(year % 4 == 0 and year % 100 != 0) or (year % 400 == 0) From 08729717047b1d385b13a932495a28e2428ad925 Mon Sep 17 00:00:00 2001 From: raghad598 Date: Fri, 10 Jan 2025 11:14:55 +0200 Subject: [PATCH 14/45] resolved-comments --- solutions/area_of_circle.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/solutions/area_of_circle.py b/solutions/area_of_circle.py index 0ff68d67f..3ce55cf88 100644 --- a/solutions/area_of_circle.py +++ b/solutions/area_of_circle.py @@ -26,6 +26,8 @@ def area_of_circle(radius: float) -> float: 78.53981633974483 >>> area_of_circle(0) 0.0 + >>> area_of_circle(3.5) + 38.48451000647496 """ if radius < 0: raise ValueError("Radius cannot be negative") From 1c71d93f82072cd26c104ba98531aaa74941a8f0 Mon Sep 17 00:00:00 2001 From: Muna Sattouf Date: Fri, 10 Jan 2025 13:29:11 +0200 Subject: [PATCH 15/45] added test file --- solutions/tests/test_leap_year.py | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 solutions/tests/test_leap_year.py diff --git a/solutions/tests/test_leap_year.py b/solutions/tests/test_leap_year.py new file mode 100644 index 000000000..71d00faf1 --- /dev/null +++ b/solutions/tests/test_leap_year.py @@ -0,0 +1,48 @@ +import unittest +for leap_year import leap_year + +class TestLeapYear(unittest.TestCase): + """ + Test cases for the leap_year function + """ + + def test_divisibility_by_4(self): + """ + Tests a year is divisible by 4 but not 100 + """ + self. assertTrue(leap_year(2024)) + + def test_not_leap_divisible_by_100(self): + """ + Tests a year divisible by 100 but not 400 + """ + self.assertFalse(leap_year(1900)) + + def test_leap_divisible_by_400(self): + """ + Tests a year divisible by 400 + """ + self.assertTrue(leap_year(2000)) + + def test_not_leap_not_divisble_by_4(self): + """ + Tests a year not divisble by 4 + """ + self.assertFalse(2023) + + def test_invalid_type(self): + """ + A ValueError should be raised if type is not integer + """ + with self.assertRaises(ValueError): + leap_year("hi") + + def test_invalid_negative(self): + """ + A value error must be rasied if the year is a negative integer + """ + with self.assertRaises(ValueError): + leap_year(-175) + +if __name__=="__main__": + unittest.main() \ No newline at end of file From 5a3292b2a918c325eea34f8adc0bf69aef2b4348 Mon Sep 17 00:00:00 2001 From: Muna Sattouf Date: Fri, 10 Jan 2025 13:38:50 +0200 Subject: [PATCH 16/45] edited last line for clarity --- solutions/leap_year.py | 4 +++- solutions/tests/test_leap_year.py | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/solutions/leap_year.py b/solutions/leap_year.py index 3f1cd90c9..6a5541f9b 100644 --- a/solutions/leap_year.py +++ b/solutions/leap_year.py @@ -1,5 +1,7 @@ """ The module checks whether a given year is a leap year. +create by Muna Sattouf on January 9, 2025 +Completed on January 10, 2024 A year is a leap year if it is divisible by 4, and if it is divisible by 100, it must also be divisible by 400. @@ -28,4 +30,4 @@ def leap_year(year: int) -> bool: if year < 0: raise ValueError("Year must be positive integer") - return(year % 4 == 0 and year % 100 != 0) or (year % 400 == 0) + return year % 4 == 0 or (year % 4 == 0 and year % 100 != 0) diff --git a/solutions/tests/test_leap_year.py b/solutions/tests/test_leap_year.py index 71d00faf1..4e24e67c6 100644 --- a/solutions/tests/test_leap_year.py +++ b/solutions/tests/test_leap_year.py @@ -1,5 +1,10 @@ +""" +Test for the leap_year function +Created and completed by Muna Sattouf on January 10, 2024 +""" + import unittest -for leap_year import leap_year +from leap_year import leap_year class TestLeapYear(unittest.TestCase): """ @@ -28,7 +33,7 @@ def test_not_leap_not_divisble_by_4(self): """ Tests a year not divisble by 4 """ - self.assertFalse(2023) + self.assertFalse(leap_year(2023)) def test_invalid_type(self): """ From 66d38f8aa430158123fa6fbdfcf2b67f3968bdfd Mon Sep 17 00:00:00 2001 From: Muna Sattouf Date: Fri, 10 Jan 2025 13:44:56 +0200 Subject: [PATCH 17/45] fixed mistake in line 7 --- solutions/tests/test_leap_year.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/tests/test_leap_year.py b/solutions/tests/test_leap_year.py index 4e24e67c6..c4d70f2e0 100644 --- a/solutions/tests/test_leap_year.py +++ b/solutions/tests/test_leap_year.py @@ -4,7 +4,7 @@ """ import unittest -from leap_year import leap_year +from solutions.leap_year import leap_year class TestLeapYear(unittest.TestCase): """ From 60a518d67ed2c3c5ccedc165f697ec9cc8300f46 Mon Sep 17 00:00:00 2001 From: Muna Sattouf Date: Fri, 10 Jan 2025 13:48:32 +0200 Subject: [PATCH 18/45] changed to UTF-8 --- solutions/tests/test_leap_year.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/tests/test_leap_year.py b/solutions/tests/test_leap_year.py index c4d70f2e0..4b0f54694 100644 --- a/solutions/tests/test_leap_year.py +++ b/solutions/tests/test_leap_year.py @@ -1,5 +1,5 @@ """ -Test for the leap_year function +Test for leap_year function Created and completed by Muna Sattouf on January 10, 2024 """ From 37c7197112bf4934d56b79eaeb816213156a7374 Mon Sep 17 00:00:00 2001 From: Muna Sattouf Date: Fri, 10 Jan 2025 13:50:14 +0200 Subject: [PATCH 19/45] fixed issue with code --- solutions/leap_year.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/leap_year.py b/solutions/leap_year.py index 6a5541f9b..45f5c3091 100644 --- a/solutions/leap_year.py +++ b/solutions/leap_year.py @@ -30,4 +30,4 @@ def leap_year(year: int) -> bool: if year < 0: raise ValueError("Year must be positive integer") - return year % 4 == 0 or (year % 4 == 0 and year % 100 != 0) + return year % 400 == 0 or (year % 4 == 0 and year % 100 != 0) From 9f25c27b2d9955577a976e701e320f12b3fa5ea7 Mon Sep 17 00:00:00 2001 From: Muna Sattouf Date: Fri, 10 Jan 2025 13:54:01 +0200 Subject: [PATCH 20/45] fix last line --- solutions/leap_year.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/leap_year.py b/solutions/leap_year.py index 45f5c3091..8da3ee658 100644 --- a/solutions/leap_year.py +++ b/solutions/leap_year.py @@ -30,4 +30,4 @@ def leap_year(year: int) -> bool: if year < 0: raise ValueError("Year must be positive integer") - return year % 400 == 0 or (year % 4 == 0 and year % 100 != 0) + return (year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)) \ No newline at end of file From af57192e932a8f0e6eb0da880bb787aa76b4d592 Mon Sep 17 00:00:00 2001 From: Muna Sattouf Date: Fri, 10 Jan 2025 13:55:59 +0200 Subject: [PATCH 21/45] stylistic --- solutions/tests/test_leap_year.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solutions/tests/test_leap_year.py b/solutions/tests/test_leap_year.py index 4b0f54694..0c82d74ee 100644 --- a/solutions/tests/test_leap_year.py +++ b/solutions/tests/test_leap_year.py @@ -1,6 +1,6 @@ """ -Test for leap_year function -Created and completed by Muna Sattouf on January 10, 2024 +Test for leap_year function. +Created and completed by Muna Sattouf on January 10, 2024. """ import unittest From 2bf39e3dafa16fc2d1d9d270e778c54abdcb26b2 Mon Sep 17 00:00:00 2001 From: Muna Sattouf Date: Fri, 10 Jan 2025 16:10:59 +0200 Subject: [PATCH 22/45] added code in lines 1,2 --- solutions/leap_year.py | 2 ++ solutions/tests/test_leap_year.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/solutions/leap_year.py b/solutions/leap_year.py index 8da3ee658..8f4e75a24 100644 --- a/solutions/leap_year.py +++ b/solutions/leap_year.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- """ The module checks whether a given year is a leap year. create by Muna Sattouf on January 9, 2025 diff --git a/solutions/tests/test_leap_year.py b/solutions/tests/test_leap_year.py index 0c82d74ee..813fba7d9 100644 --- a/solutions/tests/test_leap_year.py +++ b/solutions/tests/test_leap_year.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- """ Test for leap_year function. Created and completed by Muna Sattouf on January 10, 2024. From 922b056c722212b0a16963d6e94f911cd35ef14f Mon Sep 17 00:00:00 2001 From: raghad598 Date: Fri, 10 Jan 2025 21:55:15 +0200 Subject: [PATCH 23/45] resolved comments --- solutions/area_of_circle.py | 19 ++++++++++++------- solutions/tests/test_area_of_circle.py | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/solutions/area_of_circle.py b/solutions/area_of_circle.py index 3ce55cf88..714da9a49 100644 --- a/solutions/area_of_circle.py +++ b/solutions/area_of_circle.py @@ -10,7 +10,7 @@ import math - +# Define a function to calculate the area of a circle. def area_of_circle(radius: float) -> float: """Calculate the area of a circle given its radius. @@ -22,20 +22,25 @@ def area_of_circle(radius: float) -> float: Raises: ValueError: if the radius is negative - >>> area_of_circle(5) - 78.53981633974483 - >>> area_of_circle(0) - 0.0 - >>> area_of_circle(3.5) - 38.48451000647496 + Examples: + >>> area_of_circle(5) + 78.53981633974483 + >>> area_of_circle(0) + 0.0 + >>> area_of_circle(3.5) + 38.48451000647496 """ + # Raise an error if the radius is negative. if radius < 0: raise ValueError("Radius cannot be negative") + # Calculate and return the area using the formula: area = Ο€ * r^2 return math.pi * radius**2 +# Entry point for script execution if __name__ == "__main__": + # Example usage: Calculate the area of a circle with a radius of 5. radius = 5 area = area_of_circle(radius) print("Area of the circle:", area) diff --git a/solutions/tests/test_area_of_circle.py b/solutions/tests/test_area_of_circle.py index ab40effe0..82d575aae 100644 --- a/solutions/tests/test_area_of_circle.py +++ b/solutions/tests/test_area_of_circle.py @@ -18,6 +18,21 @@ def test_large_radius(self): """Test the function with a very large radius.""" self.assertAlmostEqual(area_of_circle(1000), 3141592.653589793) + def test_negative_radius(self): + """Test the function with a negative radius.""" + with self.assertRaises(ValueError) as context: + area_of_circle(-5) + self.assertEqual(str(context.exception), "Radius cannot be negative") + + def test_invalid_type(self): + """Test the function with an invalid type for radius.""" + with self.assertRaises(TypeError): + area_of_circle("string") + with self.assertRaises(TypeError): + area_of_circle([1, 2, 3]) + with self.assertRaises(TypeError): + area_of_circle(None) + if __name__ == "__main__": unittest.main() From fa3eb3c2cbd9be5e2f0f1a1c7f1dc8fd990a6925 Mon Sep 17 00:00:00 2001 From: raghad598 Date: Fri, 10 Jan 2025 22:04:46 +0200 Subject: [PATCH 24/45] ruff errors --- solutions/area_of_circle.py | 1 + 1 file changed, 1 insertion(+) diff --git a/solutions/area_of_circle.py b/solutions/area_of_circle.py index 714da9a49..c3562cfca 100644 --- a/solutions/area_of_circle.py +++ b/solutions/area_of_circle.py @@ -10,6 +10,7 @@ import math + # Define a function to calculate the area of a circle. def area_of_circle(radius: float) -> float: """Calculate the area of a circle given its radius. From 187ddc448b0d74358adc20f2be684f16900b1c24 Mon Sep 17 00:00:00 2001 From: Marc Al Darazi Date: Sat, 11 Jan 2025 10:33:33 +0300 Subject: [PATCH 25/45] binary_to_hex challenge I did the challenge called binary_to_hex and it's ready for reviewing --- solutions/binary_to_hex.py | 46 +++++++++++++++ solutions/tests/test_binary_to_hex.py | 80 +++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 solutions/binary_to_hex.py create mode 100644 solutions/tests/test_binary_to_hex.py diff --git a/solutions/binary_to_hex.py b/solutions/binary_to_hex.py new file mode 100644 index 000000000..9c97f7993 --- /dev/null +++ b/solutions/binary_to_hex.py @@ -0,0 +1,46 @@ +""" +Module: Binary to Hexadecimal Converter + +This module provides a utility function to convert binary strings to their +corresponding hexadecimal representations. It validates the input to ensure +that it contains only binary digits (0s and 1s) and performs the conversion +accurately. + +Functions: + - binary_to_hex(binary_str): Converts a binary string to its hexadecimal representation. + +Usage Example: + >>> from binary_to_hex import binary_to_hex + >>> binary_to_hex("1101") + 'D' + +""" + +def binary_to_hex(binary_str): + """ + Convert a binary string to its hexadecimal representation. + + Parameters: + binary_str (str): A string of 0s and 1s representing a binary number. + + Returns: + str: The hexadecimal representation of the binary number. + + Raises: + ValueError: If the input is not a valid binary string. + + Example: + >>> binary_to_hex("1101") + 'D' + >>> binary_to_hex("11110000") + 'F0' + """ + # Validate input + if not all(char in '01' for char in binary_str): + raise ValueError("Input must be a binary string containing only 0s and 1s.") + + # Convert binary string to integer + decimal_value = int(binary_str, 2) + + # Convert integer to hexadecimal string and return + return hex(decimal_value)[2:].upper() diff --git a/solutions/tests/test_binary_to_hex.py b/solutions/tests/test_binary_to_hex.py new file mode 100644 index 000000000..5900a7808 --- /dev/null +++ b/solutions/tests/test_binary_to_hex.py @@ -0,0 +1,80 @@ +""" +Module: Binary to Hexadecimal Converter + +This module provides a utility function to convert binary strings to their +corresponding hexadecimal representations. It validates the input to ensure +that it contains only binary digits (0s and 1s) and performs the conversion +accurately. + +Functions: + - binary_to_hex(binary_str): Converts a binary string to its hexadecimal representation. + +Usage Example: + >>> from binary_to_hex import binary_to_hex + >>> binary_to_hex("1101") + 'D' + +""" + +def binary_to_hex(binary_str): + """ + Convert a binary string to its hexadecimal representation. + + Parameters: + binary_str (str): A string of 0s and 1s representing a binary number. + + Returns: + str: The hexadecimal representation of the binary number. + + Raises: + ValueError: If the input is not a valid binary string. + + Example: + >>> binary_to_hex("1101") + 'D' + >>> binary_to_hex("11110000") + 'F0' + """ + # Validate input + if not all(char in '01' for char in binary_str): + raise ValueError("Input must be a binary string containing only 0s and 1s.") + + # Convert binary string to integer + decimal_value = int(binary_str, 2) + + # Convert integer to hexadecimal string and return + return hex(decimal_value)[2:].upper() + +# Unit Tests +def test_binary_to_hex_valid(): + """ + Test binary_to_hex with valid binary input. + Asserts the correct hexadecimal output is produced. + """ + assert binary_to_hex("1101") == "D" + +def test_binary_to_hex_large(): + """ + Test binary_to_hex with a larger binary input. + Asserts the correct hexadecimal output is produced. + """ + assert binary_to_hex("11110000") == "F0" + +def test_binary_to_hex_minimum(): + """ + Test binary_to_hex with the smallest valid binary input. + Asserts the correct hexadecimal output is produced. + """ + assert binary_to_hex("0") == "0" + +def test_binary_to_hex_invalid(): + """ + Test binary_to_hex with invalid input containing non-binary characters. + Asserts that a ValueError is raised. + """ + try: + binary_to_hex("11012") + except ValueError as e: + assert str(e) == "Input must be a binary string containing only 0s and 1s." + else: + assert False, "ValueError was not raised for invalid input." From 734e1df0b6b79cbb624dc680c01f9026c4fb650b Mon Sep 17 00:00:00 2001 From: Marc Al Darazi Date: Sat, 11 Jan 2025 10:57:18 +0300 Subject: [PATCH 26/45] hex_to_binary challenge i have done with the second challenge hex_to_binary and it's ready to be reviewed --- solutions/hex_to_binary.py | 41 +++++++++++++++++++++ solutions/tests/test_hex_to_binary.py | 52 +++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 solutions/hex_to_binary.py create mode 100644 solutions/tests/test_hex_to_binary.py diff --git a/solutions/hex_to_binary.py b/solutions/hex_to_binary.py new file mode 100644 index 000000000..32b2a323a --- /dev/null +++ b/solutions/hex_to_binary.py @@ -0,0 +1,41 @@ +""" +hex_to_binary.py + +This module provides a utility function to convert a hexadecimal string +to its binary representation. + +Functions: +- hex_to_binary: Converts a hexadecimal string to its binary equivalent. +""" + +def hex_to_binary(hex_string): + """ + Convert a hexadecimal string to its binary representation. + + Parameters: + hex_string (str): A string representing a hexadecimal number. + It can include a leading '0x' prefix or not. + + Returns: + str: A binary string representation of the given hexadecimal number, + with leading zeros preserved. + + Raises: + ValueError: If the input string is not a valid hexadecimal number. + + Example: + >>> hex_to_binary("1A") + '11010' + >>> hex_to_binary("0xFF") + '11111111' + """ + # Remove '0x' prefix if present + if hex_string.startswith("0x"): + hex_string = hex_string[2:] + + try: + # Convert to integer, then to binary + binary_string = bin(int(hex_string, 16))[2:] # Remove '0b' prefix + return binary_string + except ValueError: + raise ValueError("Invalid hexadecimal string") diff --git a/solutions/tests/test_hex_to_binary.py b/solutions/tests/test_hex_to_binary.py new file mode 100644 index 000000000..e3ea6d603 --- /dev/null +++ b/solutions/tests/test_hex_to_binary.py @@ -0,0 +1,52 @@ +import unittest +from hex_to_binary import hex_to_binary + +class TestHexToBinary(unittest.TestCase): + """ + Unit tests for the hex_to_binary function. + + These tests validate that the hex_to_binary function correctly converts + hexadecimal strings to binary strings, handling both cases with and + without the '0x' prefix and invalid inputs. + """ + + def test_valid_hex_without_prefix(self): + """ + Test converting a valid hexadecimal string without the '0x' prefix. + """ + self.assertEqual(hex_to_binary("1A"), "11010") + + def test_valid_hex_with_prefix(self): + """ + Test converting a valid hexadecimal string with the '0x' prefix. + """ + self.assertEqual(hex_to_binary("0xFF"), "11111111") + + def test_single_digit_hex(self): + """ + Test converting a single digit hexadecimal string. + """ + self.assertEqual(hex_to_binary("9"), "1001") + + def test_hex_with_lowercase_letters(self): + """ + Test converting a hexadecimal string with lowercase letters. + """ + self.assertEqual(hex_to_binary("a"), "1010") + + def test_invalid_hex_with_non_hex_characters(self): + """ + Test an invalid hexadecimal string with non-hex characters. + """ + with self.assertRaises(ValueError): + hex_to_binary("G1") + + def test_empty_string(self): + """ + Test an empty string as input, which should raise a ValueError. + """ + with self.assertRaises(ValueError): + hex_to_binary("") + +if __name__ == "_main_": + unittest.main() From d2529c2872015802a620bc75eba4c621d71aea6c Mon Sep 17 00:00:00 2001 From: Muna Sattouf Date: Sat, 11 Jan 2025 11:26:01 +0200 Subject: [PATCH 27/45] reformatted --- solutions/leap_year.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/solutions/leap_year.py b/solutions/leap_year.py index 8f4e75a24..87000846f 100644 --- a/solutions/leap_year.py +++ b/solutions/leap_year.py @@ -9,17 +9,18 @@ and if it is divisible by 100, it must also be divisible by 400. """ + def leap_year(year: int) -> bool: """ Checks whether the given year is a leap year. - + Argument: year, a positive integer - + Returns: boolean: True if the year is a leap year, false otherwise. - - Examples: + + Examples: >>> leap_year(2024) True >>> leap_year(1900) @@ -31,5 +32,5 @@ def leap_year(year: int) -> bool: raise ValueError("Year must be an integer") if year < 0: raise ValueError("Year must be positive integer") - - return (year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)) \ No newline at end of file + + return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) From 12d36d3e571dfa361b91a220b8c0824458d3fbb8 Mon Sep 17 00:00:00 2001 From: Marc Al Darazi Date: Sat, 11 Jan 2025 14:30:41 +0300 Subject: [PATCH 28/45] updated binary_to_hex updated binary_to_hex --- solutions/binary_to_hex.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/solutions/binary_to_hex.py b/solutions/binary_to_hex.py index 9c97f7993..6679e7050 100644 --- a/solutions/binary_to_hex.py +++ b/solutions/binary_to_hex.py @@ -6,14 +6,6 @@ that it contains only binary digits (0s and 1s) and performs the conversion accurately. -Functions: - - binary_to_hex(binary_str): Converts a binary string to its hexadecimal representation. - -Usage Example: - >>> from binary_to_hex import binary_to_hex - >>> binary_to_hex("1101") - 'D' - """ def binary_to_hex(binary_str): From e4b83cae56a712775c22b5377c77a400adc42502 Mon Sep 17 00:00:00 2001 From: Marc Al Darazi Date: Sat, 11 Jan 2025 15:00:14 +0300 Subject: [PATCH 29/45] updated hex_to_binary updated hex_to_binary --- solutions/hex_to_binary.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/solutions/hex_to_binary.py b/solutions/hex_to_binary.py index 32b2a323a..f6f475309 100644 --- a/solutions/hex_to_binary.py +++ b/solutions/hex_to_binary.py @@ -13,12 +13,12 @@ def hex_to_binary(hex_string): Convert a hexadecimal string to its binary representation. Parameters: - hex_string (str): A string representing a hexadecimal number. - It can include a leading '0x' prefix or not. + hex_string (str): A string representing a hexadecimal number. + It can include a leading '0x' prefix or not. Returns: str: A binary string representation of the given hexadecimal number, - with leading zeros preserved. + with leading zeros preserved. Raises: ValueError: If the input string is not a valid hexadecimal number. From 717268bcb871a4a47b8f0cf806f909d16915a484 Mon Sep 17 00:00:00 2001 From: TagwaHashim Date: Sat, 11 Jan 2025 14:03:00 +0200 Subject: [PATCH 30/45] new function file to detect errors --- solutions/sum_of.py | 39 +++++++++++++++++++++++++++ solutions/tests/test_sum_of.py | 48 ++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 solutions/sum_of.py create mode 100644 solutions/tests/test_sum_of.py diff --git a/solutions/sum_of.py b/solutions/sum_of.py new file mode 100644 index 000000000..42694ab68 --- /dev/null +++ b/solutions/sum_of.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on XX XX XX + +A module gives a summation of two numbers. + +@author: Tagwa Hashim +""" + + +def sum_of(num1, num2): + """ + Adds two numbers and returns their sum. + + Args: + num1: The first number. Can be an integer or a float. + num2: The second number. Can be an integer or a float. + + Returns: + The sum of num1 and num2. + + Raises: + AssertionError: If either num1 or num2 is not a number (int or float). + + Examples: + >>> sum_of(3, 5) + 8 + >>> sum_of(2.5, 3.7) + 6.2 + >>> sum_of("hello", 2.718) + Traceback (most recent call last): + ... + AssertionError: Both arguments must be numbers (int or float). + """ + assert isinstance(num1, (int, float)) and isinstance(num2, (int, float)), ( + "Both arguments must be numbers (int or float)." + ) + return num1 + num2 diff --git a/solutions/tests/test_sum_of.py b/solutions/tests/test_sum_of.py new file mode 100644 index 000000000..c8563b6e3 --- /dev/null +++ b/solutions/tests/test_sum_of.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Unit tests for the sum_of function. + +@author: Tagwa Hashim +""" + +import unittest + +from solutions.sum_of import sum_of + + +class TestSumOf(unittest.TestCase): + """Test the sum_of function""" + + def test_add_integers(self): + """Test sum_of of two integers.""" + self.assertEqual(sum_of(7, 12), 19) + + def test_add_floats(self): + """Test sum_of of two floats.""" + self.assertEqual(sum_of(1.6, 3.3), 4.9) + + def test_add_mixtype(self): + """Test sum_of of integer and float.""" + self.assertEqual(sum_of(3, 2.05), 5.05) + + def test_add_zero(self): + """Test sum_of with zero.""" + self.assertEqual(sum_of(0, 5), 5) + self.assertEqual(sum_of(5, 0), 5) + + def test_add_negative_numbers(self): + """Test sum_of with negative numbers.""" + self.assertEqual(sum_of(-3, -5), -8) + self.assertEqual(sum_of(-3, 5), 2) + + def test_invalid_input_type_num(self): + """Test with invalid input type for num1 or num2, should raise assertion error""" + + with self.assertRaises(AssertionError): + sum_of("hello", 2) + sum_of(18, "hello") + + +if __name__ == "__main__": + unittest.main() From b1568d321969589f29c2f1c1da5c44d994119805 Mon Sep 17 00:00:00 2001 From: Falaq Abdulmajeed Date: Sat, 11 Jan 2025 17:48:12 +0300 Subject: [PATCH 31/45] added readme in test file --- solutions/tests/README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/solutions/tests/README.md b/solutions/tests/README.md index 007eb9551..3735407a9 100644 --- a/solutions/tests/README.md +++ b/solutions/tests/README.md @@ -1 +1,19 @@ -# Tests +# Test Folder πŸ—‚οΈ + +This folder contains test files designed to validate the functionality of the +functions in the [solutions](https://github.com/MIT-Emerging-Talent/ET6-foundations-group-18/tree/main/solutions) +folder. βœ… + +## Structure πŸ—οΈ + +- Each test file corresponds to a function in the [solutions](https://github.com/MIT-Emerging-Talent/ET6-foundations-group-18/tree/main/solutions) +folder. πŸ”— +- Tests are written using Python's `unittest` framework. 🐍 +- Folder structure: `test_file_1.py`, `test_file_2.py`, etc. πŸ“‚ + +## Running Tests ▢️ + +To run all tests in the folder, use the following command: + +```bash +python -m unittest path/to/test/folder From 8dc2d5300f57ba72a66b78bfaeeb33548049aaf1 Mon Sep 17 00:00:00 2001 From: Marc Al Darazi Date: Sat, 11 Jan 2025 21:11:17 +0300 Subject: [PATCH 32/45] fixing py-format fixing py-format --- solutions/binary_to_hex.py | 14 ++-- solutions/tests/test_binary_to_hex.py | 115 ++++++++++---------------- 2 files changed, 51 insertions(+), 78 deletions(-) diff --git a/solutions/binary_to_hex.py b/solutions/binary_to_hex.py index 6679e7050..41adeb156 100644 --- a/solutions/binary_to_hex.py +++ b/solutions/binary_to_hex.py @@ -1,13 +1,15 @@ """ Module: Binary to Hexadecimal Converter -This module provides a utility function to convert binary strings to their -corresponding hexadecimal representations. It validates the input to ensure -that it contains only binary digits (0s and 1s) and performs the conversion +This module provides a utility function to convert binary strings to their +corresponding hexadecimal representations. It validates the input to ensure +that it contains only binary digits (0s and 1s) and performs the conversion accurately. +@author: Marc Darazi """ + def binary_to_hex(binary_str): """ Convert a binary string to its hexadecimal representation. @@ -20,15 +22,17 @@ def binary_to_hex(binary_str): Raises: ValueError: If the input is not a valid binary string. - + Example: >>> binary_to_hex("1101") 'D' >>> binary_to_hex("11110000") 'F0' + >>> binary_to_hex("101010101010") + 'AAA' """ # Validate input - if not all(char in '01' for char in binary_str): + if not all(char in "01" for char in binary_str): raise ValueError("Input must be a binary string containing only 0s and 1s.") # Convert binary string to integer diff --git a/solutions/tests/test_binary_to_hex.py b/solutions/tests/test_binary_to_hex.py index 5900a7808..79f0f011d 100644 --- a/solutions/tests/test_binary_to_hex.py +++ b/solutions/tests/test_binary_to_hex.py @@ -1,80 +1,49 @@ """ Module: Binary to Hexadecimal Converter -This module provides a utility function to convert binary strings to their -corresponding hexadecimal representations. It validates the input to ensure -that it contains only binary digits (0s and 1s) and performs the conversion +This module provides a utility function to convert binary strings to their +corresponding hexadecimal representations. It validates the input to ensure +that it contains only binary digits (0s and 1s) and performs the conversion accurately. -Functions: - - binary_to_hex(binary_str): Converts a binary string to its hexadecimal representation. - -Usage Example: - >>> from binary_to_hex import binary_to_hex - >>> binary_to_hex("1101") - 'D' - +Author: Marc Darazi """ -def binary_to_hex(binary_str): - """ - Convert a binary string to its hexadecimal representation. - - Parameters: - binary_str (str): A string of 0s and 1s representing a binary number. - - Returns: - str: The hexadecimal representation of the binary number. - - Raises: - ValueError: If the input is not a valid binary string. - - Example: - >>> binary_to_hex("1101") - 'D' - >>> binary_to_hex("11110000") - 'F0' - """ - # Validate input - if not all(char in '01' for char in binary_str): - raise ValueError("Input must be a binary string containing only 0s and 1s.") - - # Convert binary string to integer - decimal_value = int(binary_str, 2) - - # Convert integer to hexadecimal string and return - return hex(decimal_value)[2:].upper() - -# Unit Tests -def test_binary_to_hex_valid(): - """ - Test binary_to_hex with valid binary input. - Asserts the correct hexadecimal output is produced. - """ - assert binary_to_hex("1101") == "D" - -def test_binary_to_hex_large(): - """ - Test binary_to_hex with a larger binary input. - Asserts the correct hexadecimal output is produced. - """ - assert binary_to_hex("11110000") == "F0" - -def test_binary_to_hex_minimum(): - """ - Test binary_to_hex with the smallest valid binary input. - Asserts the correct hexadecimal output is produced. - """ - assert binary_to_hex("0") == "0" - -def test_binary_to_hex_invalid(): - """ - Test binary_to_hex with invalid input containing non-binary characters. - Asserts that a ValueError is raised. - """ - try: - binary_to_hex("11012") - except ValueError as e: - assert str(e) == "Input must be a binary string containing only 0s and 1s." - else: - assert False, "ValueError was not raised for invalid input." +import unittest +from solutions.binary_to_hex import binary_to_hex + + +class TestBinaryToHex(unittest.TestCase): + # Unit Tests + def test_binary_to_hex_valid(self): + """ + Test binary_to_hex with valid binary input. + Asserts the correct hexadecimal output is produced. + """ + assert binary_to_hex("1101") == "D" + + def test_binary_to_hex_large(self): + """ + Test binary_to_hex with a larger binary input. + Asserts the correct hexadecimal output is produced. + """ + assert binary_to_hex("11110000") == "F0" + + def test_binary_to_hex_minimum(self): + """ + Test binary_to_hex with the smallest valid binary input. + Asserts the correct hexadecimal output is produced. + """ + assert binary_to_hex("0") == "0" + + def test_binary_to_hex_invalid(self): + """ + Test binary_to_hex with invalid input containing non-binary characters. + Asserts that a ValueError is raised. + """ + try: + binary_to_hex("11012") + except ValueError as e: + assert str(e) == "Input must be a binary string containing only 0s and 1s." + else: + assert False, "ValueError was not raised for invalid input." From 1ba0e9a829967ca0edc8a6b0a76933acbac41ce8 Mon Sep 17 00:00:00 2001 From: Muna Sattouf Date: Sat, 11 Jan 2025 20:13:31 +0200 Subject: [PATCH 33/45] Save changes --- solutions/cumulative_sum.py | 6 +++--- solutions/pyproject.toml | Bin 28 -> 0 bytes solutions/tests/test_leap_year.py | 24 +++++++++++++----------- 3 files changed, 16 insertions(+), 14 deletions(-) delete mode 100644 solutions/pyproject.toml diff --git a/solutions/cumulative_sum.py b/solutions/cumulative_sum.py index 2e77fb9d0..6cd87f1c1 100644 --- a/solutions/cumulative_sum.py +++ b/solutions/cumulative_sum.py @@ -44,9 +44,9 @@ def cumulative_sum(numbers: list) -> list: # Validate input assert numbers is not None, "Input cannot be None." assert isinstance(numbers, list), "Input must be a list of numeric values." - assert all( - isinstance(num, (int, float)) for num in numbers - ), "All elements in the list must be numeric." + assert all(isinstance(num, (int, float)) for num in numbers), ( + "All elements in the list must be numeric." + ) # Compute cumulative sums cumulative_list = [] current_sum = 0 diff --git a/solutions/pyproject.toml b/solutions/pyproject.toml deleted file mode 100644 index ab7378221973ed0f2b62944821b8b55d12ac71f9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 28 gcmezWFPfo*As+~H81xv57)lw^fH0PUmw}4`0DSNUYybcN diff --git a/solutions/tests/test_leap_year.py b/solutions/tests/test_leap_year.py index 813fba7d9..a5943e3ca 100644 --- a/solutions/tests/test_leap_year.py +++ b/solutions/tests/test_leap_year.py @@ -8,48 +8,50 @@ import unittest from solutions.leap_year import leap_year + class TestLeapYear(unittest.TestCase): """ Test cases for the leap_year function """ - + def test_divisibility_by_4(self): """ Tests a year is divisible by 4 but not 100 """ - self. assertTrue(leap_year(2024)) - + self.assertTrue(leap_year(2024)) + def test_not_leap_divisible_by_100(self): """ Tests a year divisible by 100 but not 400 """ self.assertFalse(leap_year(1900)) - + def test_leap_divisible_by_400(self): """ - Tests a year divisible by 400 + Tests a year divisible by 400 """ self.assertTrue(leap_year(2000)) - + def test_not_leap_not_divisble_by_4(self): """ Tests a year not divisble by 4 """ self.assertFalse(leap_year(2023)) - + def test_invalid_type(self): """ A ValueError should be raised if type is not integer """ with self.assertRaises(ValueError): leap_year("hi") - + def test_invalid_negative(self): """ A value error must be rasied if the year is a negative integer """ with self.assertRaises(ValueError): leap_year(-175) - -if __name__=="__main__": - unittest.main() \ No newline at end of file + + +if __name__ == "__main__": + unittest.main() From ffc5cf51459f1aeea3ff453a8201afbeabecad7f Mon Sep 17 00:00:00 2001 From: Marc Al Darazi Date: Sat, 11 Jan 2025 21:24:06 +0300 Subject: [PATCH 34/45] fixed py formatting fixed py formatting --- solutions/hex_to_binary.py | 9 ++++++--- solutions/tests/test_hex_to_binary.py | 26 +++++++++++++++++--------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/solutions/hex_to_binary.py b/solutions/hex_to_binary.py index f6f475309..fcaaeee4b 100644 --- a/solutions/hex_to_binary.py +++ b/solutions/hex_to_binary.py @@ -1,13 +1,14 @@ """ -hex_to_binary.py - This module provides a utility function to convert a hexadecimal string to its binary representation. Functions: - hex_to_binary: Converts a hexadecimal string to its binary equivalent. + +Author: Marc Darazi """ + def hex_to_binary(hex_string): """ Convert a hexadecimal string to its binary representation. @@ -28,11 +29,13 @@ def hex_to_binary(hex_string): '11010' >>> hex_to_binary("0xFF") '11111111' + >>> hex_to_binary("0x0") + '0' """ # Remove '0x' prefix if present if hex_string.startswith("0x"): hex_string = hex_string[2:] - + try: # Convert to integer, then to binary binary_string = bin(int(hex_string, 16))[2:] # Remove '0b' prefix diff --git a/solutions/tests/test_hex_to_binary.py b/solutions/tests/test_hex_to_binary.py index e3ea6d603..b90f4a0be 100644 --- a/solutions/tests/test_hex_to_binary.py +++ b/solutions/tests/test_hex_to_binary.py @@ -1,6 +1,17 @@ +""" +This module provides a utility function to convert a hexadecimal string +to its binary representation. + +Functions: +- hex_to_binary: Converts a hexadecimal string to its binary equivalent. + +Author: Marc Darazi +""" + import unittest from hex_to_binary import hex_to_binary + class TestHexToBinary(unittest.TestCase): """ Unit tests for the hex_to_binary function. @@ -9,44 +20,41 @@ class TestHexToBinary(unittest.TestCase): hexadecimal strings to binary strings, handling both cases with and without the '0x' prefix and invalid inputs. """ - + def test_valid_hex_without_prefix(self): """ Test converting a valid hexadecimal string without the '0x' prefix. """ self.assertEqual(hex_to_binary("1A"), "11010") - + def test_valid_hex_with_prefix(self): """ Test converting a valid hexadecimal string with the '0x' prefix. """ self.assertEqual(hex_to_binary("0xFF"), "11111111") - + def test_single_digit_hex(self): """ Test converting a single digit hexadecimal string. """ self.assertEqual(hex_to_binary("9"), "1001") - + def test_hex_with_lowercase_letters(self): """ Test converting a hexadecimal string with lowercase letters. """ self.assertEqual(hex_to_binary("a"), "1010") - + def test_invalid_hex_with_non_hex_characters(self): """ Test an invalid hexadecimal string with non-hex characters. """ with self.assertRaises(ValueError): hex_to_binary("G1") - + def test_empty_string(self): """ Test an empty string as input, which should raise a ValueError. """ with self.assertRaises(ValueError): hex_to_binary("") - -if __name__ == "_main_": - unittest.main() From c9178d46cbe7db8c047445a04514af735bc93f06 Mon Sep 17 00:00:00 2001 From: Marc Al Darazi Date: Sat, 11 Jan 2025 21:27:19 +0300 Subject: [PATCH 35/45] fixing py_testing fixing py_testing --- solutions/tests/test_hex_to_binary.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/tests/test_hex_to_binary.py b/solutions/tests/test_hex_to_binary.py index b90f4a0be..d6c2c66ab 100644 --- a/solutions/tests/test_hex_to_binary.py +++ b/solutions/tests/test_hex_to_binary.py @@ -9,7 +9,7 @@ """ import unittest -from hex_to_binary import hex_to_binary +from ..hex_to_binary import hex_to_binary class TestHexToBinary(unittest.TestCase): From daa29776398286f39fb5f217e75711cc3f37a3dd Mon Sep 17 00:00:00 2001 From: Muna Sattouf Date: Sat, 11 Jan 2025 22:37:24 +0200 Subject: [PATCH 36/45] removed unnecessary file --- solutions/pyproject.toml | Bin 0 -> 28 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 solutions/pyproject.toml diff --git a/solutions/pyproject.toml b/solutions/pyproject.toml new file mode 100644 index 0000000000000000000000000000000000000000..ab7378221973ed0f2b62944821b8b55d12ac71f9 GIT binary patch literal 28 gcmezWFPfo*As+~H81xv57)lw^fH0PUmw}4`0DSNUYybcN literal 0 HcmV?d00001 From 661f041e86829c2e1635ae4f70c26b297a8f25b5 Mon Sep 17 00:00:00 2001 From: Muna Sattouf Date: Sat, 11 Jan 2025 22:38:05 +0200 Subject: [PATCH 37/45] Deleted pyproject.toml --- solutions/pyproject.toml | Bin 28 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 solutions/pyproject.toml diff --git a/solutions/pyproject.toml b/solutions/pyproject.toml deleted file mode 100644 index ab7378221973ed0f2b62944821b8b55d12ac71f9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 28 gcmezWFPfo*As+~H81xv57)lw^fH0PUmw}4`0DSNUYybcN From fc943a9e9ac61a18e021d2f9363b8a5d38553841 Mon Sep 17 00:00:00 2001 From: Marc Al Darazi Date: Sun, 12 Jan 2025 00:56:37 +0300 Subject: [PATCH 38/45] resolved comments resolved comments --- solutions/tests/test_binary_to_hex.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/solutions/tests/test_binary_to_hex.py b/solutions/tests/test_binary_to_hex.py index 79f0f011d..19934fe15 100644 --- a/solutions/tests/test_binary_to_hex.py +++ b/solutions/tests/test_binary_to_hex.py @@ -1,9 +1,7 @@ """ Module: Binary to Hexadecimal Converter -This module provides a utility function to convert binary strings to their -corresponding hexadecimal representations. It validates the input to ensure -that it contains only binary digits (0s and 1s) and performs the conversion +It validates the input to ensure that it contains only binary digits (0s and 1s) and performs the conversion accurately. Author: Marc Darazi @@ -14,11 +12,15 @@ class TestBinaryToHex(unittest.TestCase): + """ + Testing the binary-to-hex function. + """ # Unit Tests def test_binary_to_hex_valid(self): """ Test binary_to_hex with valid binary input. Asserts the correct hexadecimal output is produced. + it should give D """ assert binary_to_hex("1101") == "D" From bf0332fcf24232cf626d1cc197cc31f14a9b0276 Mon Sep 17 00:00:00 2001 From: Marc Al Darazi Date: Sun, 12 Jan 2025 01:01:17 +0300 Subject: [PATCH 39/45] Updated binary to hex solved py formatting --- solutions/tests/test_binary_to_hex.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/solutions/tests/test_binary_to_hex.py b/solutions/tests/test_binary_to_hex.py index 19934fe15..79f0f011d 100644 --- a/solutions/tests/test_binary_to_hex.py +++ b/solutions/tests/test_binary_to_hex.py @@ -1,7 +1,9 @@ """ Module: Binary to Hexadecimal Converter -It validates the input to ensure that it contains only binary digits (0s and 1s) and performs the conversion +This module provides a utility function to convert binary strings to their +corresponding hexadecimal representations. It validates the input to ensure +that it contains only binary digits (0s and 1s) and performs the conversion accurately. Author: Marc Darazi @@ -12,15 +14,11 @@ class TestBinaryToHex(unittest.TestCase): - """ - Testing the binary-to-hex function. - """ # Unit Tests def test_binary_to_hex_valid(self): """ Test binary_to_hex with valid binary input. Asserts the correct hexadecimal output is produced. - it should give D """ assert binary_to_hex("1101") == "D" From 694598dcc9d05f885fdcb11683df7f0f7ac7897d Mon Sep 17 00:00:00 2001 From: "s.ashour82" Date: Sun, 12 Jan 2025 10:03:41 +0200 Subject: [PATCH 40/45] Update README.md crafting is done --- solutions/README.md | 157 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 157 insertions(+) diff --git a/solutions/README.md b/solutions/README.md index 9852346d2..cff2c0c69 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -1 +1,158 @@ # Solutions + +## This file contains a brief on the challenges completed by Group 18 Team + +### factorial + +- **description:** A module for Computing the factorial of + a non-negative integer n. + +- **written by:** Saad (sashour82) + +- **reviewed by:** Luyandochitindi (Luyando-Chitindi) + +### is_palinrome + +- **description:** A module for checking if a given string is + a palindrome (reads the same backward as forward). + +- **written by:** Saad (sashour82) + +- **reviewed by:** Falaq (FalaqMajeed) + +### is_even + +- **description:** A module that contains a function that checks if a number is even. + +- **written by:** Luyandochitindi (Luyando-Chitindi) + +- **reviewed by:** Mohammed (Moealfadil) + +### is_positive + +- **description:** A module that contains a function that checks if a number is positive. + +- **written by:** Luyandochitindi (Luyando-Chitindi) + +- **reviewed by:**Β Muna (Muna-S) + +### mean + +- **description:** Calculates the mean of numbers in a list + +- **written by:** Mohammed (Moealfadil) + +- **reviewed by:** Falaq (FalaqMajeed) + +### is_prime + +- **description:** Checks if a number is prime or not + +- **written by:** Mohammed (Moealfadil) + +- **reviewed by:** Luyandochitindi (Luyando-Chitindi) + +### cumulative_sum + +- **description:** Calculates the cumulative sum of a list by iterating + through its elements and maintaining a running total + +- **written by:** Falaq (FalaqMajeed) + +- **reviewed by:** Mohammed (Moealfadil) + +### list_to_string + +- **description:** Converts a list into a single string + +- **written by:** Falaq (FalaqMajeed) + +- **reviewed by:** Raghad (raghad598) + +### max_in + +- **description:** Find the maximum number in a list + +- **written by:** TagwaHashim (TagwaHashim) + +- **reviewed by:** Raghad (raghad598) + +### sum_of + +- **description:** Calculate the summation of two numbers + +- **written by:** TagwaHashim (TagwaHashim) + +- **reviewed by:** Muna (Muna-S) + +### binary_to_decimal + +- **description:** Give the decimal number for a binary + +- **written by:** Muna (Muna-S) + +- **reviewed by:** TagwaHashim (TagwaHashim) + +### leap_year + +- **description:** Checks whether a year is a leap year + +- **written by:** Muna (Muna-S) + +- **reviewed by:** TagwaHashim (TagwaHashim) + +### remove_duplicates + +- **description:** Take a list and return it without any repeated values + +- **written by:** Heba (HebaShaheen) + +- **reviewed by:** Saad (sashour82) + +### decimal_to_binary + +- **description:** Give the binary number for a decimal + +- **written by:** Heba (HebaShaheen) + +- **reviewed by:** Saad (sashour82) + +### count_words + +- **description:** Counts the number of words in a string + +- **written by:** Raghad (raghad598) + +- **reviewed by:** Saad (sashour82) + +### area_of_circle + +- **description:** Calculates the area of a circle given its radius + +- **written by:** Raghad (raghad598) + +- **reviewed by:** Mohammed (Moealfadil) + +### hex_to_binary + +- **description:** Converts a hexadecimal string to its binary equivalent + +- **written by:** Marc (MarcDarazi99) + +- **reviewed by:** Mohammed (Moealfadil) + +### hex_to_binary + +- **description:** Converts a hexadecimal string to its binary equivalent + +- **written by:** Marc (MarcDarazi99) + +- **reviewed by:** Mohammed (Moealfadil) + +### binary_to_hex + +- **description:** Converts a binary string to its hexadecimal equivalent + +- **written by:** Marc (MarcDarazi99) + +- **reviewed by:** Mohammed (Moealfadil), Heba (HebaShaheen) From 46e8fb261b2ec53ad89627991d7eb6f1cd2870d1 Mon Sep 17 00:00:00 2001 From: "s.ashour82" Date: Sun, 12 Jan 2025 10:13:20 +0200 Subject: [PATCH 41/45] Update README.md file edited by removing duplication in headers --- solutions/README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/solutions/README.md b/solutions/README.md index cff2c0c69..af395340b 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -141,14 +141,6 @@ - **reviewed by:** Mohammed (Moealfadil) -### hex_to_binary - -- **description:** Converts a hexadecimal string to its binary equivalent - -- **written by:** Marc (MarcDarazi99) - -- **reviewed by:** Mohammed (Moealfadil) - ### binary_to_hex - **description:** Converts a binary string to its hexadecimal equivalent From 6e4feb7cf3900ef4b8b492946c3ceefe1a266f9c Mon Sep 17 00:00:00 2001 From: "s.ashour82" Date: Sun, 12 Jan 2025 10:43:56 +0200 Subject: [PATCH 42/45] Update README.md --- solutions/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solutions/README.md b/solutions/README.md index af395340b..fa4618a6b 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -91,7 +91,7 @@ - **written by:** Muna (Muna-S) -- **reviewed by:** TagwaHashim (TagwaHashim) +- **reviewed by:** TagwaHashim (TagwaHashim), Falaq (FalaqMajeed) ### leap_year @@ -147,4 +147,4 @@ - **written by:** Marc (MarcDarazi99) -- **reviewed by:** Mohammed (Moealfadil), Heba (HebaShaheen) +- **reviewed by:** Mohammed (Moealfadil), Heba (HebaShaheen), Falaq (FalaqMajeed) From 602f376a0f0b295453ea72e448a96e4e3ae37f6b Mon Sep 17 00:00:00 2001 From: "s.ashour82" Date: Sun, 12 Jan 2025 11:52:52 +0200 Subject: [PATCH 43/45] Update README.md file updated --- solutions/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solutions/README.md b/solutions/README.md index fa4618a6b..d51d38b9d 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -91,7 +91,7 @@ - **written by:** Muna (Muna-S) -- **reviewed by:** TagwaHashim (TagwaHashim), Falaq (FalaqMajeed) +- **reviewed by:** TagwaHashim (TagwaHashim), Falaq (FalaqMajeed), Saad (sashour82) ### leap_year @@ -131,7 +131,7 @@ - **written by:** Raghad (raghad598) -- **reviewed by:** Mohammed (Moealfadil) +- **reviewed by:** Heba (HebaShaheen), Mohammed (Moealfadil) ### hex_to_binary From 1da973fb4bc054996da444a2364e13b57683e543 Mon Sep 17 00:00:00 2001 From: Moealfadil <142026026+Moealfadil@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:55:41 +0200 Subject: [PATCH 44/45] change file name --- solutions/{IsPrime.py => is_prime.py} | 18 +++++++------- .../{test_IsPrime.py => test_is_prime.py} | 24 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) rename solutions/{IsPrime.py => is_prime.py} (74%) rename solutions/tests/{test_IsPrime.py => test_is_prime.py} (79%) diff --git a/solutions/IsPrime.py b/solutions/is_prime.py similarity index 74% rename from solutions/IsPrime.py rename to solutions/is_prime.py index 656de9cfd..ddb48720f 100644 --- a/solutions/IsPrime.py +++ b/solutions/is_prime.py @@ -4,33 +4,33 @@ Module for finding if an integer is prime. Module contents: - - IsPrime: finds if an integer is prime. + - is_prime: finds if an integer is prime. Created on XX XX XX @author: Mohammed Elfadil """ -def IsPrime(a: int) -> str: +def is_prime(a: int) -> str: """Checks if an integer is prime. Parameter: a: int Return -> str: whether a is prime or not Raises: AssertionError: if the argument is not an integer - >>> IsPrime(0) + >>> is_prime(0) not prime - >>> IsPrime(1) + >>> is_prime(1) not prime - >>> IsPrime(2) + >>> is_prime(2) prime - >>> IsPrime(4) + >>> is_prime(4) not prime - >>> IsPrime(7) + >>> is_prime(7) prime - >>> IsPrime(2.5) + >>> is_prime(2.5) invalid input - >>> IsPrime(-1) + >>> is_prime(-1) not prime """ if not isinstance(a, int): diff --git a/solutions/tests/test_IsPrime.py b/solutions/tests/test_is_prime.py similarity index 79% rename from solutions/tests/test_IsPrime.py rename to solutions/tests/test_is_prime.py index 399160f98..4364f8a89 100644 --- a/solutions/tests/test_IsPrime.py +++ b/solutions/tests/test_is_prime.py @@ -1,67 +1,67 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- import unittest -from solutions.IsPrime import IsPrime +from solutions.is_prime import is_prime class TestIsPrime(unittest.TestCase): - """test the IsPrime function""" + """test the is_prime function""" def test_0(self): """It should evaluate not prime""" - actual = IsPrime(0) + actual = is_prime(0) expected = "not prime" self.assertEqual(actual, expected) def test_1(self): """It should evaluate not prime""" - actual = IsPrime(1) + actual = is_prime(1) expected = "not prime" self.assertEqual(actual, expected) def test_2(self): - actual = IsPrime(2) + actual = is_prime(2) expected = "prime" self.assertEqual(actual, expected) def test_4(self): """its should evaluate not prime""" - actual = IsPrime(4) + actual = is_prime(4) expected = "not prime" self.assertEqual(actual, expected) def test_7(self): """It should evaluate prime""" - actual = IsPrime(7) + actual = is_prime(7) expected = "prime" self.assertEqual(actual, expected) def test_9(self): """It should evaluate not prime""" - actual = IsPrime(9) + actual = is_prime(9) expected = "not prime" self.assertEqual(actual, expected) def test_11(self): """It should evaluate prime""" - actual = IsPrime(11) + actual = is_prime(11) expected = "prime" self.assertEqual(actual, expected) def test_13(self): """It should evaluate prime""" - actual = IsPrime(13) + actual = is_prime(13) expected = "prime" self.assertEqual(actual, expected) def test_negative(self): """It should evaluate not prime""" - actual = IsPrime(-1) + actual = is_prime(-1) expected = "not prime" self.assertEqual(actual, expected) def test_not_integer(self): """It should evaluate not prime""" - actual = IsPrime(1.5) + actual = is_prime(1.5) expected = "invalid input" self.assertEqual(actual, expected) From 960b30fa9253d24b84d6106a4a635a73441548c8 Mon Sep 17 00:00:00 2001 From: Moealfadil <142026026+Moealfadil@users.noreply.github.com> Date: Sun, 12 Jan 2025 14:55:35 +0200 Subject: [PATCH 45/45] Update README.md --- solutions/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solutions/README.md b/solutions/README.md index d51d38b9d..800b37986 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -109,9 +109,9 @@ - **reviewed by:** Saad (sashour82) -### decimal_to_binary +### binary_decimal_conversion -- **description:** Give the binary number for a decimal +- **description:** Gives the binary number for a decimal and vice versa - **written by:** Heba (HebaShaheen)