From e07dc5a3ff440d89938bbc2547f0ed2d12646402 Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Sun, 22 Dec 2024 22:30:33 +0200 Subject: [PATCH 001/116] Add is_even and is_positive functions to solutions --- solutions/is_even.py | 58 ++++++++++++++++++++++++++++++++++++++++ solutions/is_positive.py | 58 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 solutions/is_even.py create mode 100644 solutions/is_positive.py diff --git a/solutions/is_even.py b/solutions/is_even.py new file mode 100644 index 000000000..bc2b96d6c --- /dev/null +++ b/solutions/is_even.py @@ -0,0 +1,58 @@ +""" +A module for checking if a number is even. + + +Author: Luyando Ennie Chitindi +Date: 12/22/2024 + + +This module has a function that checks if a number is even. +The function takes an integer as an input and returns a boolean value that +indicates whether the number is divisible by 2. + + +Function: +- is_even(number: int) -> bool + + +Exception: +- Raises TypeError if an input is not an integer. + + +Example: +>>> is_even(4) +True +>>> is_even(3) +False +>>> is_even(0) +True +""" + +def is_even(number: int) -> bool: + """ + This will check if number is even. + + + Argument: + number (int): The number to use to check if it is even. + + + Returns: + bool: Only true if the number is even, false otherwise. + + + Raises: + TypeError: If the argument provided is not an integer. + + + Example: + >>> is_even(6) + True + >>> is_even(7) + False + >>> is_even(0) + True + """ + if not isinstance(number, int): + raise TypeError("Input must be an integer.") + return number % 2 == 0 diff --git a/solutions/is_positive.py b/solutions/is_positive.py new file mode 100644 index 000000000..2a8e7bce2 --- /dev/null +++ b/solutions/is_positive.py @@ -0,0 +1,58 @@ +""" +A module for checking if a number is positive. + + +Author: Luyando Chitindi +Date: 12/22/2024 + + +This module contains a function that deals with checking if a number is positive. +The function will take an integer as an input and returns a boolean value indicating +whether the number is greater than zero. + +Function: +- is positive(number: int) -> bool + + +Exceptions: +-Raises TypeError if the input is not an integer. + + +For Example: +>>> is_positive(5) +True +>>> is_positive(-3) +False +>>> is_positive(0) +False +""" + + +def is_positive(number: int) -> bool: + """ + This will check if the number is positive. + + + Arguments: + number (int): The number to check if it is positive. + + + Returns: + bool: True if the number is positive, false otherwise. + + + Raises: + TypeError: If the argument that is provided is not an integer. + + + Example: + >>> is_positive(10) + True + >>> is_positive(-5) + False + >>> is_positive(0) + False + """ + if not isinstance(number, int): + raise TypeError("Input must be an integer.") + return number > 0 From 84280de25c4dd4fb393d7420f7598f186d534f46 Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Mon, 23 Dec 2024 01:30:33 +0200 Subject: [PATCH 002/116] Removed is_even.py from positive-number-function branch --- solutions/is_even.py | 58 -------------------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 solutions/is_even.py diff --git a/solutions/is_even.py b/solutions/is_even.py deleted file mode 100644 index bc2b96d6c..000000000 --- a/solutions/is_even.py +++ /dev/null @@ -1,58 +0,0 @@ -""" -A module for checking if a number is even. - - -Author: Luyando Ennie Chitindi -Date: 12/22/2024 - - -This module has a function that checks if a number is even. -The function takes an integer as an input and returns a boolean value that -indicates whether the number is divisible by 2. - - -Function: -- is_even(number: int) -> bool - - -Exception: -- Raises TypeError if an input is not an integer. - - -Example: ->>> is_even(4) -True ->>> is_even(3) -False ->>> is_even(0) -True -""" - -def is_even(number: int) -> bool: - """ - This will check if number is even. - - - Argument: - number (int): The number to use to check if it is even. - - - Returns: - bool: Only true if the number is even, false otherwise. - - - Raises: - TypeError: If the argument provided is not an integer. - - - Example: - >>> is_even(6) - True - >>> is_even(7) - False - >>> is_even(0) - True - """ - if not isinstance(number, int): - raise TypeError("Input must be an integer.") - return number % 2 == 0 From da51111f9b4d04c6bf34c60d664eedacff99d3b0 Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Fri, 27 Dec 2024 23:12:24 +0200 Subject: [PATCH 003/116] Add is_even.py to solutions folder --- solutions/is_even.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 solutions/is_even.py diff --git a/solutions/is_even.py b/solutions/is_even.py new file mode 100644 index 000000000..2f751f013 --- /dev/null +++ b/solutions/is_even.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on XX XX XX + +A module for checking if an integer is even. + +@author: Luyando Ennie Chitindi +""" +def is_even(number:int) -> bool: + """ + This checks if an integer is even. + + Parameters: + number: int, the number to check + + Returns -> bool: + True if the number is even, false otherwise. + + Raises: + AssertionError: if the input is not an integer + + Example: + >>> is_even(4) + True + >>> is_even(3) + False + >>> is_even(0) + True + >>> is_even("hello") + Traceback (most recent call last): + ... + AssertionError: Input must be an integer. + """ + assert isinstance(number, int), "Input must be an integer" + if number % 2 == 0: + return True + return False From 37fcf02efbac54da757ac2fa5463a113dc539dcf Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Sat, 28 Dec 2024 01:29:32 +0200 Subject: [PATCH 004/116] Add is_even function and corresponding unit test --- solutions/tests/test_is_even.py | 59 +++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 solutions/tests/test_is_even.py diff --git a/solutions/tests/test_is_even.py b/solutions/tests/test_is_even.py new file mode 100644 index 000000000..d4312c615 --- /dev/null +++ b/solutions/tests/test_is_even.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on XX XX XX + +@Luyando Ennie Chitindi +""" + +import unittest +from solutions.is_even import is_even + +class TestIsEven(unittest.TestCase): + """ Test the is_even function""" + +def test_even_number(self): + """It should evaluate 4 to true""" + actual = is_even(4) + expected = True + self.assertEqual(actual, expected) + +def test_odd_number(self): + """It should evaluate 3 to False""" + actual = is_even(3) + expected = False + self.assertEqual(actual, expected) + +def test_zero(self): + """It should evaluate 0 to True""" + actual = is_even(0) + expected = True + self.assertEqual(actual, expected) + +def test_negative_even_number(self): + """It should evaluate -2 to True""" + actual = is_even(-2) + expected = True + self.assertEqual(actual, expected) + +def test_negative_odd_number(self): + """It should evaluate -3 to False""" + actual = is_even(-3) + expected = False + self.assertEqual(actual, expected) + +def test_non_integer_input(self): + """It should raise an assertion error if the argument is not an integer""" + with self.assertRaises(AssertionError): + is_even(3.5) + + with self.assertRaises(AssertionError): + is_even("string") + +def test_less_than_0(self): + """It should raise an assertion error if the argument is less than 0""" + with self.assertRaises(AssertionError): + is_even(-2.5) + +if __name__ == "__main__": + unittest.main() From fdf1ea856e2734897f67f14a3dd22b53420dd34b Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Sat, 28 Dec 2024 02:02:39 +0200 Subject: [PATCH 005/116] Remove is_even.py for resubmission --- solutions/is_even.py | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 solutions/is_even.py diff --git a/solutions/is_even.py b/solutions/is_even.py deleted file mode 100644 index 2f751f013..000000000 --- a/solutions/is_even.py +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Created on XX XX XX - -A module for checking if an integer is even. - -@author: Luyando Ennie Chitindi -""" -def is_even(number:int) -> bool: - """ - This checks if an integer is even. - - Parameters: - number: int, the number to check - - Returns -> bool: - True if the number is even, false otherwise. - - Raises: - AssertionError: if the input is not an integer - - Example: - >>> is_even(4) - True - >>> is_even(3) - False - >>> is_even(0) - True - >>> is_even("hello") - Traceback (most recent call last): - ... - AssertionError: Input must be an integer. - """ - assert isinstance(number, int), "Input must be an integer" - if number % 2 == 0: - return True - return False From e8d8c22863787fb44bf390cf7b05adb016a94ad5 Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Sat, 28 Dec 2024 02:33:26 +0200 Subject: [PATCH 006/116] Re added is_even.py function --- solutions/is_even.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 solutions/is_even.py diff --git a/solutions/is_even.py b/solutions/is_even.py new file mode 100644 index 000000000..2f751f013 --- /dev/null +++ b/solutions/is_even.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on XX XX XX + +A module for checking if an integer is even. + +@author: Luyando Ennie Chitindi +""" +def is_even(number:int) -> bool: + """ + This checks if an integer is even. + + Parameters: + number: int, the number to check + + Returns -> bool: + True if the number is even, false otherwise. + + Raises: + AssertionError: if the input is not an integer + + Example: + >>> is_even(4) + True + >>> is_even(3) + False + >>> is_even(0) + True + >>> is_even("hello") + Traceback (most recent call last): + ... + AssertionError: Input must be an integer. + """ + assert isinstance(number, int), "Input must be an integer" + if number % 2 == 0: + return True + return False From a086da950db05e02d7dcfc79a09199d12b373f1d Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Sat, 28 Dec 2024 17:00:05 +0200 Subject: [PATCH 007/116] Updated is_even.py and test_is_even.py for CI checks compliance --- solutions/is_even.py | 2 +- solutions/tests/test_is_even.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/solutions/is_even.py b/solutions/is_even.py index 2f751f013..9e66889b2 100644 --- a/solutions/is_even.py +++ b/solutions/is_even.py @@ -3,7 +3,7 @@ """ Created on XX XX XX -A module for checking if an integer is even. +A module for checking to see if an integer is even. @author: Luyando Ennie Chitindi """ diff --git a/solutions/tests/test_is_even.py b/solutions/tests/test_is_even.py index d4312c615..ef12efc26 100644 --- a/solutions/tests/test_is_even.py +++ b/solutions/tests/test_is_even.py @@ -3,7 +3,7 @@ """ Created on XX XX XX -@Luyando Ennie Chitindi +@Luyando .E. Chitindi """ import unittest From df0ab776ca50d537cb75d83298b9118a00233b89 Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Sat, 28 Dec 2024 17:51:29 +0200 Subject: [PATCH 008/116] Reuploaded is_even.py and test_is_even.py for CI checks --- solutions/is_even.py | 2 +- solutions/tests/test_is_even.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/solutions/is_even.py b/solutions/is_even.py index 9e66889b2..0395e4b8f 100644 --- a/solutions/is_even.py +++ b/solutions/is_even.py @@ -5,7 +5,7 @@ A module for checking to see if an integer is even. -@author: Luyando Ennie Chitindi +@author: Luyando .E. Chitindi """ def is_even(number:int) -> bool: """ diff --git a/solutions/tests/test_is_even.py b/solutions/tests/test_is_even.py index ef12efc26..d4312c615 100644 --- a/solutions/tests/test_is_even.py +++ b/solutions/tests/test_is_even.py @@ -3,7 +3,7 @@ """ Created on XX XX XX -@Luyando .E. Chitindi +@Luyando Ennie Chitindi """ import unittest From 8e42c8768ebeadede5391f31dc632e3693f995f2 Mon Sep 17 00:00:00 2001 From: colevandersWands <18554853+colevandersWands@users.noreply.github.com> Date: Sat, 28 Dec 2024 14:02:25 -0500 Subject: [PATCH 009/116] use ruff as formatter --- .vscode/settings.json | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5a90e202f..bbda5188d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -113,5 +113,14 @@ }, // Enable/disable update table of contents on save - "markdown.extension.toc.updateOnSave": false + "markdown.extension.toc.updateOnSave": false, + + "[python]": { + "editor.defaultFormatter": "charliermarsh.ruff", + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.fixAll.ruff": true, + "source.organizeImports.ruff": true + } + } } From 7bf2e2593ea6bd52ec3002dfe7509b0d1a5d1b0d Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Sat, 28 Dec 2024 22:09:04 +0200 Subject: [PATCH 010/116] modified files --- .vscode/settings.json | 5 ++++- solutions/is_even.py | 12 +++++++----- solutions/tests/test_is_even.py | 11 ++++++++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5a90e202f..058679944 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -113,5 +113,8 @@ }, // Enable/disable update table of contents on save - "markdown.extension.toc.updateOnSave": false + "markdown.extension.toc.updateOnSave": false, + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + } } diff --git a/solutions/is_even.py b/solutions/is_even.py index 0395e4b8f..3d12add1b 100644 --- a/solutions/is_even.py +++ b/solutions/is_even.py @@ -7,19 +7,21 @@ @author: Luyando .E. Chitindi """ -def is_even(number:int) -> bool: + + +def is_even(number: int) -> bool: """ This checks if an integer is even. - + Parameters: number: int, the number to check - + Returns -> bool: True if the number is even, false otherwise. - + Raises: AssertionError: if the input is not an integer - + Example: >>> is_even(4) True diff --git a/solutions/tests/test_is_even.py b/solutions/tests/test_is_even.py index d4312c615..270d9fb70 100644 --- a/solutions/tests/test_is_even.py +++ b/solutions/tests/test_is_even.py @@ -9,8 +9,10 @@ import unittest from solutions.is_even import is_even + class TestIsEven(unittest.TestCase): - """ Test the is_even function""" + """Test the is_even function""" + def test_even_number(self): """It should evaluate 4 to true""" @@ -18,30 +20,35 @@ def test_even_number(self): expected = True self.assertEqual(actual, expected) + def test_odd_number(self): """It should evaluate 3 to False""" actual = is_even(3) expected = False self.assertEqual(actual, expected) + def test_zero(self): """It should evaluate 0 to True""" actual = is_even(0) expected = True self.assertEqual(actual, expected) + def test_negative_even_number(self): """It should evaluate -2 to True""" actual = is_even(-2) expected = True self.assertEqual(actual, expected) + def test_negative_odd_number(self): """It should evaluate -3 to False""" actual = is_even(-3) expected = False self.assertEqual(actual, expected) + def test_non_integer_input(self): """It should raise an assertion error if the argument is not an integer""" with self.assertRaises(AssertionError): @@ -50,10 +57,12 @@ def test_non_integer_input(self): with self.assertRaises(AssertionError): is_even("string") + def test_less_than_0(self): """It should raise an assertion error if the argument is less than 0""" with self.assertRaises(AssertionError): is_even(-2.5) + if __name__ == "__main__": unittest.main() From d9b59d5ce7ca81dc5d649c58ae4dbfe751a1faab Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Sat, 28 Dec 2024 23:35:00 +0200 Subject: [PATCH 011/116] Fixed unit test --- solutions/tests/test_is_even.py | 97 ++++++++++++++------------------- 1 file changed, 42 insertions(+), 55 deletions(-) diff --git a/solutions/tests/test_is_even.py b/solutions/tests/test_is_even.py index 270d9fb70..f8691b45f 100644 --- a/solutions/tests/test_is_even.py +++ b/solutions/tests/test_is_even.py @@ -1,11 +1,5 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -""" -Created on XX XX XX - -@Luyando Ennie Chitindi -""" - import unittest from solutions.is_even import is_even @@ -13,55 +7,48 @@ class TestIsEven(unittest.TestCase): """Test the is_even function""" - -def test_even_number(self): - """It should evaluate 4 to true""" - actual = is_even(4) - expected = True - self.assertEqual(actual, expected) - - -def test_odd_number(self): - """It should evaluate 3 to False""" - actual = is_even(3) - expected = False - self.assertEqual(actual, expected) - - -def test_zero(self): - """It should evaluate 0 to True""" - actual = is_even(0) - expected = True - self.assertEqual(actual, expected) - - -def test_negative_even_number(self): - """It should evaluate -2 to True""" - actual = is_even(-2) - expected = True - self.assertEqual(actual, expected) - - -def test_negative_odd_number(self): - """It should evaluate -3 to False""" - actual = is_even(-3) - expected = False - self.assertEqual(actual, expected) - - -def test_non_integer_input(self): - """It should raise an assertion error if the argument is not an integer""" - with self.assertRaises(AssertionError): - is_even(3.5) - - with self.assertRaises(AssertionError): - is_even("string") - - -def test_less_than_0(self): - """It should raise an assertion error if the argument is less than 0""" - with self.assertRaises(AssertionError): - is_even(-2.5) + def test_even_number(self): + """It should evaluate 4 to true""" + actual = is_even(4) + expected = True + self.assertEqual(actual, expected) + + def test_odd_number(self): + """It should evaluate 3 to False""" + actual = is_even(3) + expected = False + self.assertEqual(actual, expected) + + def test_zero(self): + """It should evaluate 0 to True""" + actual = is_even(0) + expected = True + self.assertEqual(actual, expected) + + def test_negative_even_number(self): + """It should evaluate -2 to True""" + actual = is_even(-2) + expected = True + self.assertEqual(actual, expected) + + def test_negative_odd_number(self): + """It should evaluate -3 to False""" + actual = is_even(-3) + expected = False + self.assertEqual(actual, expected) + + def test_non_integer_input(self): + """It should raise an assertion error if the argument is not an integer""" + with self.assertRaises(AssertionError): + is_even(3.5) + + with self.assertRaises(AssertionError): + is_even("string") + + def test_less_than_0(self): + """It should raise an assertion error if the argument is less than 0""" + with self.assertRaises(AssertionError): + is_even(-2.5) if __name__ == "__main__": From a6cab574ec1da5ca0829a5d0f593336253d8c779 Mon Sep 17 00:00:00 2001 From: Moealfadil <142026026+Moealfadil@users.noreply.github.com> Date: Sun, 29 Dec 2024 10:27:07 +0200 Subject: [PATCH 012/116] mean function --- solutions/mean.py | 29 +++++++++++++++++++++ solutions/tests/test_mean.py | 50 ++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 solutions/mean.py create mode 100644 solutions/tests/test_mean.py diff --git a/solutions/mean.py b/solutions/mean.py new file mode 100644 index 000000000..bb5168f3d --- /dev/null +++ b/solutions/mean.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +A module for finding the mean of a list of numbers. + +Module contents: + - mean: finds the mean of a list of numbers. + +Created on XX XX XX +@author: Mohammed Elfadil +""" + + +def mean(a: list) -> float: + """Finds the mean of a list of numbers. + Parameter: + a: list + Return -> float: the mean of the list + Raises: + AssertionError: if the argument is not a list + >>> mean([1, 2, 3, 4, 5]) + 3.0 + >>> mean([10, 20, 30, 40, 50]) + 30.0 + """ + if not isinstance(a, list): + return "invalid input" + + return sum(a) / len(a) diff --git a/solutions/tests/test_mean.py b/solutions/tests/test_mean.py new file mode 100644 index 000000000..90b160c64 --- /dev/null +++ b/solutions/tests/test_mean.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +import unittest +from solutions.mean import mean + + +class TestMean(unittest.TestCase): + """test the mean function""" + + def test_1(self): + """It should evaluate 3.0""" + actual = mean([1, 2, 3, 4, 5]) + expected = 3.0 + self.assertEqual(actual, expected) + + def test_2(self): + """It should evaluate 30.0""" + actual = mean([10, 20, 30, 40, 50]) + expected = 30.0 + self.assertEqual(actual, expected) + + def test_3(self): + """It should evaluate 0.0""" + actual = mean([0, 0, 0, 0, 0]) + expected = 0.0 + self.assertEqual(actual, expected) + + def test_4(self): + """It should evaluate 1.0""" + actual = mean([1]) + expected = 1.0 + self.assertEqual(actual, expected) + + def test_integer(self): + """It should evaluate invalid input""" + actual = mean(1) + expected = "invalid input" + self.assertEqual(actual, expected) + + def test_negatives(self): + """It should evaluate -4.0""" + actual = mean([-2, -4, -6]) + expected = -4.0 + self.assertEqual(actual, expected) + + def test_floats(self): + """It should evaluate 2.5""" + actual = mean([1.5, 2.5, 3.5]) + expected = 2.5 + self.assertEqual(actual, expected) From cec61c8be188206752287d9e4d93778fcda044fa Mon Sep 17 00:00:00 2001 From: Falaq Abdulmajeed Date: Sun, 29 Dec 2024 17:27:37 +0300 Subject: [PATCH 013/116] created cumulative sum in a list --- solutions/cumulative_sum.py | 58 ++++++++++++++++ solutions/tests/__init__.py | 1 - solutions/tests/test_cumulative_sum.py | 96 ++++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 solutions/cumulative_sum.py delete mode 100644 solutions/tests/__init__.py create mode 100644 solutions/tests/test_cumulative_sum.py diff --git a/solutions/cumulative_sum.py b/solutions/cumulative_sum.py new file mode 100644 index 000000000..a1cb44c61 --- /dev/null +++ b/solutions/cumulative_sum.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +Module: cumulative_sum + +Description: + This module provides a function to calculate the cumulative sum of + a list of numbers. It is useful for applications requiring progressive + accumulation of values, such as financial calculations, data analysis, + or custom mathematical operations. + +Module Contents: + - cumulative_sum(numbers: list) -> list: + Computes and returns a list of cumulative sums from the input list. + +Author: Falaq Youniss +Date: 29/12/2024 +""" + + +def cumulative_sum(numbers: list) -> list: + """ + Computes the cumulative sum of a list of numbers. + + Args: + numbers (list): A list of numeric values (integers or floats). + + Returns: + list: A list where each element is the cumulative sum up to that index. + + Raises: + AssertionError: + - If the input is not a list. + - If the list contains non-numeric values. + - If the input is `None`. + + >>> cumulative_sum([1, 2, 3, 4]) + [1, 3, 6, 10] + >>> cumulative_sum([-1, -2, -3, -4]) + [-1, -3, -6, -10] + >>> cumulative_sum([1.0, 2.0, 3.0, 4.0]) + [1.0, 3.0, 6.0, 10.0] + """ + # 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." + # Compute cumulative sums + cumulative_list = [] + current_sum = 0 + for num in numbers: + current_sum += num + cumulative_list.append(current_sum) + + return cumulative_list 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_cumulative_sum.py b/solutions/tests/test_cumulative_sum.py new file mode 100644 index 000000000..128907503 --- /dev/null +++ b/solutions/tests/test_cumulative_sum.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + + +""" +Module: test_cumulative_sum + +Description: + This module contains test cases for the `cumulative_sum` function defined + in the `cumulative_sum.py` module. It tests the function's behavior with + various input scenarios, ensuring that it handles different edge cases and + returns the expected cumulative sums. + +Test Categories: + - Standard cases: List of positive integers, negative integers, and floating-point numbers. + - Edge cases: Empty list, single-element list, list with zeros, large number list. + - Defensive tests: None input, Non-list inputs, list with non-numeric elements. + +Author: Falaq Youniss +Date: 29/12/2024 +""" + +import unittest +from ..cumulative_sum import cumulative_sum + + +class TestCumulativeSum(unittest.TestCase): + """Test for cumulative_sum function that handles different cases""" + + # Standard test cases + def test_positive_int(self): + """It should return a cumulative list of positive integers.""" + self.assertEqual(cumulative_sum([1, 2, 3, 4]), [1, 3, 6, 10]) + + def test_negative_int(self): + """It should return a cumulative list of negative integers.""" + self.assertEqual(cumulative_sum([-1, -2, -3, -4]), [-1, -3, -6, -10]) + + def test_positive_float(self): + """It should return a cumulative list of positive floats.""" + self.assertEqual(cumulative_sum([1.0, 2.0, 3.0, 4.0]), [1.0, 3.0, 6.0, 10.0]) + + def test_negative_float(self): + """It should return a cumulative list of negative floats.""" + self.assertEqual( + cumulative_sum([-1.0, -2.0, -3.0, -4.0]), [-1.0, -3.0, -6.0, -10.0] + ) + + def test_positive_negative(self): + """It should return a cumulative list of negative and positive integers.""" + self.assertEqual(cumulative_sum([-1, 2, -3, 4]), [-1, 1, -2, 2]) + + def test_integer_float(self): + """It should return a cumulative list of integers and floats.""" + self.assertEqual(cumulative_sum([1.0, 2, 3.0, 4]), [1, 3, 6.0, 10.0]) + + def test_combination(self): + """It should return a cumulative list of mixed positive and negative integers/floats.""" + self.assertEqual(cumulative_sum([1.0, -2, -3.0, 4]), [1, -1, -4, 0]) + + def test_same(self): + """It should return a cumulative list of same positive integers.""" + self.assertEqual(cumulative_sum([3, 3, 3]), [3, 6, 9]) + + # Edge cases + def test_zero(self): + """It should return a list of zeros.""" + self.assertEqual(cumulative_sum([0, 0, 0, 0]), [0, 0, 0, 0]) + + def test_empty(self): + """It should return an empty list.""" + self.assertEqual(cumulative_sum([]), []) + + def test_one(self): + """It should return the same single-item list.""" + self.assertEqual(cumulative_sum([1]), [1]) + + def test_large_numbers(self): + """It should correctly handle large numbers.""" + self.assertEqual(cumulative_sum([1e6, 2e6, 3e6]), [1e6, 3e6, 6e6]) + + # Defensive tests + def test_none(self): + """It should raise AssertionError for None input.""" + with self.assertRaises(AssertionError): + cumulative_sum(None) + + def test_not_list(self): + """It should raise AssertionError for non-list input.""" + with self.assertRaises(AssertionError): + cumulative_sum("hello") + + def test_not_num(self): + """It should raise AssertionError for non-numeric list elements.""" + with self.assertRaises(AssertionError): + cumulative_sum([1, "cat", 3]) From 6afd85613a024aef57f32c9dbd495e7c62f53285 Mon Sep 17 00:00:00 2001 From: Falaq Abdulmajeed Date: Sun, 29 Dec 2024 17:58:13 +0300 Subject: [PATCH 014/116] adding the deleted file --- solutions/tests/__init__.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) 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..e69de29bb From 628fd50cc1aceb3dfb0f505ac6eab523c6472776 Mon Sep 17 00:00:00 2001 From: Falaq Abdulmajeed Date: Sun, 29 Dec 2024 18:41:10 +0300 Subject: [PATCH 015/116] fixed formatting --- .vscode/settings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bbda5188d..252022b48 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -119,8 +119,8 @@ "editor.defaultFormatter": "charliermarsh.ruff", "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.fixAll.ruff": true, - "source.organizeImports.ruff": true + "source.fixAll.ruff": "explicit", + "source.organizeImports.ruff": "explicit" } } } From 032eaf89cd195929b3f5bc584ebfea73f41265bf Mon Sep 17 00:00:00 2001 From: Falaq Abdulmajeed Date: Sun, 29 Dec 2024 19:11:32 +0300 Subject: [PATCH 016/116] updates in formatt --- .vscode/settings.json | 6 +++++- solutions/cumulative_sum.py | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 252022b48..d3ba05557 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -122,5 +122,9 @@ "source.fixAll.ruff": "explicit", "source.organizeImports.ruff": "explicit" } - } + }, + "cSpell.words": [ + "Falaq", + "Youniss" + ] } diff --git a/solutions/cumulative_sum.py b/solutions/cumulative_sum.py index a1cb44c61..4de900349 100644 --- a/solutions/cumulative_sum.py +++ b/solutions/cumulative_sum.py @@ -4,14 +4,14 @@ """ Module: cumulative_sum -Description: - This module provides a function to calculate the cumulative sum of - a list of numbers. It is useful for applications requiring progressive - accumulation of values, such as financial calculations, data analysis, +Description: + This module provides a function to calculate the cumulative sum of + a list of numbers. It is useful for applications requiring progressive + accumulation of values, such as financial calculations, data analysis, or custom mathematical operations. Module Contents: - - cumulative_sum(numbers: list) -> list: + - cumulative_sum(numbers: list) -> list: Computes and returns a list of cumulative sums from the input list. Author: Falaq Youniss From 639e7c5f07f3d1337c50d7f695826fb7dd474e86 Mon Sep 17 00:00:00 2001 From: Falaq Abdulmajeed Date: Sun, 29 Dec 2024 19:22:26 +0300 Subject: [PATCH 017/116] sum formatting in function --- solutions/cumulative_sum.py | 1 - 1 file changed, 1 deletion(-) diff --git a/solutions/cumulative_sum.py b/solutions/cumulative_sum.py index 4de900349..8f5cbb435 100644 --- a/solutions/cumulative_sum.py +++ b/solutions/cumulative_sum.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- - """ Module: cumulative_sum From 7451b3160587ca0b8096aec1e7802c7737787f42 Mon Sep 17 00:00:00 2001 From: Falaq Abdulmajeed Date: Sun, 29 Dec 2024 19:25:14 +0300 Subject: [PATCH 018/116] some formatt changes in test file --- solutions/tests/test_cumulative_sum.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/solutions/tests/test_cumulative_sum.py b/solutions/tests/test_cumulative_sum.py index 128907503..48d61c6b3 100644 --- a/solutions/tests/test_cumulative_sum.py +++ b/solutions/tests/test_cumulative_sum.py @@ -1,20 +1,18 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- - - """ Module: test_cumulative_sum -Description: +Description: This module contains test cases for the `cumulative_sum` function defined - in the `cumulative_sum.py` module. It tests the function's behavior with - various input scenarios, ensuring that it handles different edge cases and + in the `cumulative_sum.py` module. It tests the function's behavior with + various input scenarios, ensuring that it handles different edge cases and returns the expected cumulative sums. Test Categories: - Standard cases: List of positive integers, negative integers, and floating-point numbers. - Edge cases: Empty list, single-element list, list with zeros, large number list. - - Defensive tests: None input, Non-list inputs, list with non-numeric elements. + - Defensive tests: None input, Non-list inputs, list with non-numeric elements. Author: Falaq Youniss Date: 29/12/2024 From 68a94df99e6aec5c5c2bb9285ed68c2d958232b1 Mon Sep 17 00:00:00 2001 From: Moealfadil <142026026+Moealfadil@users.noreply.github.com> Date: Sun, 29 Dec 2024 18:40:02 +0200 Subject: [PATCH 019/116] setting changes --- .vscode/settings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bbda5188d..252022b48 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -119,8 +119,8 @@ "editor.defaultFormatter": "charliermarsh.ruff", "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.fixAll.ruff": true, - "source.organizeImports.ruff": true + "source.fixAll.ruff": "explicit", + "source.organizeImports.ruff": "explicit" } } } From 99d4787bb30f626eb0a9581002c5722e6ae328d1 Mon Sep 17 00:00:00 2001 From: Moealfadil <142026026+Moealfadil@users.noreply.github.com> Date: Sun, 29 Dec 2024 18:46:10 +0200 Subject: [PATCH 020/116] CI checks --- solutions/IsPrime.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/solutions/IsPrime.py b/solutions/IsPrime.py index a943faff5..3e00390d8 100644 --- a/solutions/IsPrime.py +++ b/solutions/IsPrime.py @@ -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 bc9aeb5954b9aea3f70446a0838d96005f81a3a5 Mon Sep 17 00:00:00 2001 From: Falaq Abdulmajeed Date: Sun, 29 Dec 2024 20:02:22 +0300 Subject: [PATCH 021/116] modified docstring --- solutions/cumulative_sum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/cumulative_sum.py b/solutions/cumulative_sum.py index 8f5cbb435..2e77fb9d0 100644 --- a/solutions/cumulative_sum.py +++ b/solutions/cumulative_sum.py @@ -5,7 +5,7 @@ Description: This module provides a function to calculate the cumulative sum of - a list of numbers. It is useful for applications requiring progressive + a list of numbers(integers\float). It is useful for applications requiring progressive accumulation of values, such as financial calculations, data analysis, or custom mathematical operations. From 37c36be47680adc2535814707846963212f70910 Mon Sep 17 00:00:00 2001 From: Moealfadil <142026026+Moealfadil@users.noreply.github.com> Date: Sun, 29 Dec 2024 19:40:36 +0200 Subject: [PATCH 022/116] settings --- .vscode/settings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 252022b48..bbda5188d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -119,8 +119,8 @@ "editor.defaultFormatter": "charliermarsh.ruff", "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.fixAll.ruff": "explicit", - "source.organizeImports.ruff": "explicit" + "source.fixAll.ruff": true, + "source.organizeImports.ruff": true } } } From cf1c9bcb05180bf2c1cf8607562fc728744d8b38 Mon Sep 17 00:00:00 2001 From: Moealfadil <142026026+Moealfadil@users.noreply.github.com> Date: Sun, 29 Dec 2024 19:44:41 +0200 Subject: [PATCH 023/116] solving conflicts --- .vscode/settings.json | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bbda5188d..058679944 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -114,13 +114,7 @@ // Enable/disable update table of contents on save "markdown.extension.toc.updateOnSave": false, - "[python]": { - "editor.defaultFormatter": "charliermarsh.ruff", - "editor.formatOnSave": true, - "editor.codeActionsOnSave": { - "source.fixAll.ruff": true, - "source.organizeImports.ruff": true - } + "editor.defaultFormatter": "ms-python.black-formatter" } } From 462809144520f72929459c3d1fc6e350cd25bc7e Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Sun, 29 Dec 2024 20:18:34 +0200 Subject: [PATCH 024/116] Add test_is_positive.py from is-even branch --- solutions/tests/test_is_positive.py | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 solutions/tests/test_is_positive.py diff --git a/solutions/tests/test_is_positive.py b/solutions/tests/test_is_positive.py new file mode 100644 index 000000000..cadb586d0 --- /dev/null +++ b/solutions/tests/test_is_positive.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Unit tests for the is_positive function. + +@author: Luyando .E. Chitindi +""" + +import unittest +from solutions.is_positive import is_positive + + +class TestIsPositive(unittest.TestCase): + """Test the is_positive function""" + + def test_positive_number(self): + """It should evaluate 4 to True""" + actual = is_positive(4) + expected = True + self.assertEqual(actual, expected) + + def test_negative_number(self): + """It should evaluate -3 to False""" + actual = is_positive(-3) + expected = False + self.assertEqual(actual, expected) + + def test_zero(self): + """It should evaluate 0 to False""" + actual = is_positive(0) + expected = False + self.assertEqual(actual, expected) + + def test_non_integer_input(self): + """It should raise an assertion error if the argument is not an integer""" + with self.assertRaises(AssertionError): + is_positive(3.5) + + with self.assertRaises(AssertionError): + is_positive("string") + + +if __name__ == "__main__": + unittest.main() From f94e33e3a59a69b563382a9c37c62b9988bdb5db Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Sun, 29 Dec 2024 20:32:02 +0200 Subject: [PATCH 025/116] updated is_positive.py --- solutions/is_positive.py | 76 +++++++++++++++------------------------- 1 file changed, 28 insertions(+), 48 deletions(-) diff --git a/solutions/is_positive.py b/solutions/is_positive.py index 2a8e7bce2..37cb1015c 100644 --- a/solutions/is_positive.py +++ b/solutions/is_positive.py @@ -1,58 +1,38 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- """ -A module for checking if a number is positive. +Created on XX XX XX +A module for checking if an integer is positive. -Author: Luyando Chitindi -Date: 12/22/2024 - - -This module contains a function that deals with checking if a number is positive. -The function will take an integer as an input and returns a boolean value indicating -whether the number is greater than zero. - -Function: -- is positive(number: int) -> bool - - -Exceptions: --Raises TypeError if the input is not an integer. - - -For Example: ->>> is_positive(5) -True ->>> is_positive(-3) -False ->>> is_positive(0) -False +@author: Luyando .E. Chitindi """ def is_positive(number: int) -> bool: """ - This will check if the number is positive. - - - Arguments: - number (int): The number to check if it is positive. - - - Returns: - bool: True if the number is positive, false otherwise. - - - Raises: - TypeError: If the argument that is provided is not an integer. - - - Example: - >>> is_positive(10) - True - >>> is_positive(-5) - False - >>> is_positive(0) - False + This checks if an integer is positive. + + Parameters: + number: int, the number to check + + Returns -> bool: + True if the number is positive, false otherwise. + + Raises: + AssertionError: if the input is not an integer + + Example: + >>> is_positive(4) + True + >>> is_positive(-3) + False + >>> is_positive(0) + False + >>> is_positive("hello") + Traceback (most recent call last): + ... + AssertionError: Input must be an integer. """ - if not isinstance(number, int): - raise TypeError("Input must be an integer.") + assert isinstance(number, int), "Input must be an integer" return number > 0 From ae50aad0427d6c81585183e1ca5e262275fdbbc3 Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Sun, 29 Dec 2024 21:50:57 +0200 Subject: [PATCH 026/116] Resolve conflicts in .vscode/settings.json --- .vscode/settings.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index bbda5188d..c25cbf91b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -122,5 +122,8 @@ "source.fixAll.ruff": true, "source.organizeImports.ruff": true } + }, + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" } } From f84a739d797934ce79960efb9e84bb3aef80a868 Mon Sep 17 00:00:00 2001 From: Luyando Chitindi Date: Sun, 29 Dec 2024 21:59:48 +0200 Subject: [PATCH 027/116] Resolve conflicts in .vscode/settings.json --- .vscode/settings.json | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index c25cbf91b..058679944 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -114,15 +114,6 @@ // Enable/disable update table of contents on save "markdown.extension.toc.updateOnSave": false, - - "[python]": { - "editor.defaultFormatter": "charliermarsh.ruff", - "editor.formatOnSave": true, - "editor.codeActionsOnSave": { - "source.fixAll.ruff": true, - "source.organizeImports.ruff": true - } - }, "[python]": { "editor.defaultFormatter": "ms-python.black-formatter" } From 44fcb9021cc92b5565d0e529c6c297011723f11b Mon Sep 17 00:00:00 2001 From: Falaq Abdulmajeed Date: Mon, 30 Dec 2024 11:58:24 +0300 Subject: [PATCH 028/116] modified test_same string --- solutions/tests/test_cumulative_sum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/tests/test_cumulative_sum.py b/solutions/tests/test_cumulative_sum.py index 48d61c6b3..a1c29af72 100644 --- a/solutions/tests/test_cumulative_sum.py +++ b/solutions/tests/test_cumulative_sum.py @@ -57,7 +57,7 @@ def test_combination(self): self.assertEqual(cumulative_sum([1.0, -2, -3.0, 4]), [1, -1, -4, 0]) def test_same(self): - """It should return a cumulative list of same positive integers.""" + """It should return a cumulative list of positive integers.""" self.assertEqual(cumulative_sum([3, 3, 3]), [3, 6, 9]) # Edge cases From 9e8e89b3e104d9e50ef0e76c926cd890d36923b5 Mon Sep 17 00:00:00 2001 From: Falaq Abdulmajeed Date: Mon, 30 Dec 2024 16:32:36 +0300 Subject: [PATCH 029/116] created my list to string challenge --- .vscode/settings.json | 9 ++- solutions/list_to_string.py | 61 +++++++++++++++++++ solutions/tests/test_list_to_string.py | 84 ++++++++++++++++++++++++++ 3 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 solutions/list_to_string.py create mode 100644 solutions/tests/test_list_to_string.py diff --git a/.vscode/settings.json b/.vscode/settings.json index 058679944..c650fa46d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -116,5 +116,12 @@ "markdown.extension.toc.updateOnSave": false, "[python]": { "editor.defaultFormatter": "ms-python.black-formatter" - } + }, + "cSpell.words": [ + "catdog", + "cathatbat", + "Falaq", + "Truehello", + "Youniss" + ] } diff --git a/solutions/list_to_string.py b/solutions/list_to_string.py new file mode 100644 index 000000000..3435d0bb1 --- /dev/null +++ b/solutions/list_to_string.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Module: List to String Converter + +Description: + This module provides a function to convert a list of elements (integers, floats, + strings, booleans) into a single concatenated string. It handles various data + types and ensures that all elements are appropriately converted to strings and joined together. + +Module Contents: + - list_to_string(lst: list) -> str: + Converts a list of elements into a single concatenated string. + Ensures proper handling of different data types and raises appropriate errors + for invalid inputs. + +Author: Falaq Youniss +Date: 30/12/2024 +""" + + +def list_to_string(lst: list) -> str: + """ + Converts a list of elements into a single concatenated string. + + Args: + lst (list): A list of items which can include integers, floats, strings, + or booleans. + + Returns: + str: A string that combines all elements of the list. + + Raises: + AssertionError: + - If the input is not a list. + - If the input is `None`. + - If the list is empty. + + >>> list_to_string([1, -4, 3.14]) + '1-43.14' + + >>> list_to_string([True, 'hello']) + 'Truehello' + + >>> list_to_string(['cat', 'hat', 'bat']) + 'cathatbat' + """ + # Validate Input + assert isinstance(lst, list), "Input must be a list." + assert lst is not None, "The input cannot be None." + assert len(lst) > 0, "The list cannot be empty." + + # Initialize an empty result string + result = "" + + # Iterate through the list and convert each element to a string + for element in lst: + + result += str(element) # Convert each element to string and concatenate + + return result diff --git a/solutions/tests/test_list_to_string.py b/solutions/tests/test_list_to_string.py new file mode 100644 index 000000000..db3769c62 --- /dev/null +++ b/solutions/tests/test_list_to_string.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Module: test_list_to_string + +Description: + This module contains test cases for the `list_to_string` function defined + in the `list_to_string_converter.py` module. It tests the function's behavior + with various input scenarios, ensuring that it handles different edge cases and + returns the expected concatenated string. + +Test Categories: + - Standard cases: List of integers, floats, strings, and booleans. + - Edge cases: single-element list, list with mixed data types. + - Defensive tests: None input, Non-list inputs, Empty list. + +Author: Falaq Youniss +Date: 30/12/2024 +""" + +import unittest +from ..list_to_string import list_to_string + + +class TestListToString(unittest.TestCase): + """Test cases for the `list_to_string` function.""" + + # Standard test cases + def test_integers(self): + """It should return a concatenated string of integers.""" + self.assertEqual(list_to_string([1, 2, 3]), "123") + + def test_floats(self): + """It should return a concatenated string of floats.""" + self.assertEqual(list_to_string([1.1, 2.2, 3.3]), "1.12.23.3") + + def test_strings(self): + """It should return a concatenated string of strings.""" + self.assertEqual(list_to_string(["cat", "hat", "bat"]), "cathatbat") + + def test_booleans(self): + """It should return a concatenated string of booleans.""" + self.assertEqual(list_to_string([True, False]), "TrueFalse") + + # Edge cases + def test_mixed_types(self): + """It should return a concatenated string of mixed types.""" + self.assertEqual(list_to_string([1, "cat", 3.5, True]), "1cat3.5True") + + def test_single_element(self): + """It should return the same single element as a string.""" + self.assertEqual(list_to_string([42]), "42") + + def test_repeated_element(self): + """It should return repeated elements""" + self.assertEqual(list_to_string([1, 1, 1, 1]), "1111") + + def test_empty_element(self): + """It should ignore empty elements""" + self.assertEqual(list_to_string(["cat", "", "dog", ""]), "catdog") + + def test_space_element(self): + """It should return elements with space elements""" + self.assertEqual(list_to_string(["cat", " ", "dog", " "]), "cat dog ") + + # Defensive tests + def test_none_input(self): + """It should raise an AssertionError for None input.""" + with self.assertRaises(AssertionError): + list_to_string(None) + + def test_non_list_input(self): + """It should raise an AssertionError for non-list input.""" + with self.assertRaises(AssertionError): + list_to_string("not a list") + + def test_empty_list(self): + """It should raise an AssertionError for empty list.""" + with self.assertRaises(AssertionError): + list_to_string([]) + + +if __name__ == "__main__": + unittest.main() From 0616185351158844615bd499bb5b81d0df13cd0a Mon Sep 17 00:00:00 2001 From: Falaq Abdulmajeed Date: Mon, 30 Dec 2024 16:48:12 +0300 Subject: [PATCH 030/116] some formatting error --- solutions/list_to_string.py | 12 ++++++------ solutions/tests/test_list_to_string.py | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/solutions/list_to_string.py b/solutions/list_to_string.py index 3435d0bb1..363b12dc0 100644 --- a/solutions/list_to_string.py +++ b/solutions/list_to_string.py @@ -36,14 +36,14 @@ def list_to_string(lst: list) -> str: - If the input is `None`. - If the list is empty. - >>> list_to_string([1, -4, 3.14]) - '1-43.14' + >>> list_to_string([1, -4, 3.14]) + '1-43.14' - >>> list_to_string([True, 'hello']) - 'Truehello' + >>> list_to_string([True, 'hello']) + 'Truehello' - >>> list_to_string(['cat', 'hat', 'bat']) - 'cathatbat' + >>> list_to_string(['cat', 'hat', 'bat']) + 'cathatbat' """ # Validate Input assert isinstance(lst, list), "Input must be a list." diff --git a/solutions/tests/test_list_to_string.py b/solutions/tests/test_list_to_string.py index db3769c62..1c7aa2fdf 100644 --- a/solutions/tests/test_list_to_string.py +++ b/solutions/tests/test_list_to_string.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ -Module: test_list_to_string +Module: test_list_to_string. Description: This module contains test cases for the `list_to_string` function defined From 4c76bbadbf120f2a38f300b40471cc15b65b18b3 Mon Sep 17 00:00:00 2001 From: Falaq Abdulmajeed Date: Mon, 30 Dec 2024 20:07:28 +0300 Subject: [PATCH 031/116] format changes --- solutions/list_to_string.py | 1 - 1 file changed, 1 deletion(-) diff --git a/solutions/list_to_string.py b/solutions/list_to_string.py index 363b12dc0..44c8e7f63 100644 --- a/solutions/list_to_string.py +++ b/solutions/list_to_string.py @@ -55,7 +55,6 @@ def list_to_string(lst: list) -> str: # Iterate through the list and convert each element to a string for element in lst: - result += str(element) # Convert each element to string and concatenate return result From aeea0dc227de130b7477e41599b3a62cf3b26050 Mon Sep 17 00:00:00 2001 From: Falaq Abdulmajeed Date: Mon, 30 Dec 2024 20:10:15 +0300 Subject: [PATCH 032/116] modified to have all ci checks correct --- solutions/tests/test_list_to_string.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/tests/test_list_to_string.py b/solutions/tests/test_list_to_string.py index 1c7aa2fdf..db3769c62 100644 --- a/solutions/tests/test_list_to_string.py +++ b/solutions/tests/test_list_to_string.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ -Module: test_list_to_string. +Module: test_list_to_string Description: This module contains test cases for the `list_to_string` function defined From b49c77c19f436e65a39015c2d8a8df87647faa2b Mon Sep 17 00:00:00 2001 From: Heba Shaheen Date: Mon, 30 Dec 2024 23:06:33 +0300 Subject: [PATCH 033/116] remove_duplicates function --- solutions/remove_duplicates.py | 40 +++++++++++++++++++++++ solutions/tests/test_remove_duplicates.py | 0 2 files changed, 40 insertions(+) create mode 100644 solutions/remove_duplicates.py create mode 100644 solutions/tests/test_remove_duplicates.py diff --git a/solutions/remove_duplicates.py b/solutions/remove_duplicates.py new file mode 100644 index 000000000..3b72fd373 --- /dev/null +++ b/solutions/remove_duplicates.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +A Function for removing the duplicates items in a list. + +Created on 2024-12-30 +Author: Heba Shaheen +""" + + +def remove_duplicates(nums: list) -> list: + """ + Given a list, return a new list without any repeated values. + The function goes item by item; if an item is not in the result list, + it appends it; otherwise, it skips it. + + Args: + nums (list): The list from which duplicates will be removed. + + Returns: + list: A list without duplicates. + Raises: + AssertionError: If the input not a list. + + >>> remove_duplicates([2, 4, 2, 5, 5, 7, 2, 6]) + [2, 4, 5, 7, 6] + + >>> remove_duplicates(["a", "v", "e", "e", "q", "v", "q", "a"]) + ['a', 'v', 'e', 'q'] + + >>> remove_duplicates(["Heba", "Noor", "Heba", "Noor"]) + ['Heba', 'Noor'] + """ + assert isinstance(nums, list), "The input should be a list" + result = [] # List to store the result without duplicates + + for num in nums: + if num not in result: + result.append(num) # Add the number to the result list + return result diff --git a/solutions/tests/test_remove_duplicates.py b/solutions/tests/test_remove_duplicates.py new file mode 100644 index 000000000..e69de29bb From f4ec29230aaf0d0a20364a2b5bba31b5a83ed1b9 Mon Sep 17 00:00:00 2001 From: Heba Shaheen Date: Mon, 30 Dec 2024 23:22:33 +0300 Subject: [PATCH 034/116] test file --- solutions/tests/test_remove_duplicates.py | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/solutions/tests/test_remove_duplicates.py b/solutions/tests/test_remove_duplicates.py index e69de29bb..05abcdb33 100644 --- a/solutions/tests/test_remove_duplicates.py +++ b/solutions/tests/test_remove_duplicates.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Test module for remove_duplicates function. + +Created on 2024-12-30 +Author: Heba Shaheen +""" + +import unittest + +from ..remove_duplicates import remove_duplicates + + +class TestCountBetween(unittest.TestCase): + """Test remove_duplicates function""" + + # Standard test cases + def test_numbers_list(self): + """It should remove duplicates numbers""" + self.assertEqual(remove_duplicates([1, 2, 3, 2, 3, 4]), [1, 2, 3, 4]) + + def test_letters_list(self): + """It should remove duplicates letters""" + self.assertEqual( + remove_duplicates(["a", "v", "e", "e", "q"]), ["a", "v", "e", "q"] + ) + + def test_mix_list(self): + """It should remove duplicates items""" + self.assertEqual( + remove_duplicates([1, 2, 3, "e", 2, 1, "e", 5, "a"]), [1, 2, 3, "e", 5, "a"] + ) + + # Edge cases + def test_empty_list(self): + """It should return empty list""" + self.assertEqual(remove_duplicates([]), []) + + # Defensive tests + def test_invalid_type(self): + """It should raise AssertionError if numbers is not a list""" + with self.assertRaises(AssertionError): + remove_duplicates("1, 2, 2") + + +if __name__ == "__main__": + unittest.main() From f99c170e641ed7388055b9e510e0239811b33fbe Mon Sep 17 00:00:00 2001 From: Heba Shaheen Date: Mon, 30 Dec 2024 23:25:07 +0300 Subject: [PATCH 035/116] change code --- solutions/tests/test_remove_duplicates.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/tests/test_remove_duplicates.py b/solutions/tests/test_remove_duplicates.py index 05abcdb33..33bcd99e4 100644 --- a/solutions/tests/test_remove_duplicates.py +++ b/solutions/tests/test_remove_duplicates.py @@ -12,7 +12,7 @@ from ..remove_duplicates import remove_duplicates -class TestCountBetween(unittest.TestCase): +class TestRemoveDuplicates(unittest.TestCase): """Test remove_duplicates function""" # Standard test cases From 7fafebf501948ffcdf1c7832cd57ec5955fec369 Mon Sep 17 00:00:00 2001 From: Heba Shaheen Date: Mon, 30 Dec 2024 23:42:38 +0300 Subject: [PATCH 036/116] create __init__ file --- solutions/__init__.py | 0 solutions/tests/__init__.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 solutions/__init__.py create mode 100644 solutions/tests/__init__.py diff --git a/solutions/__init__.py b/solutions/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/solutions/tests/__init__.py b/solutions/tests/__init__.py new file mode 100644 index 000000000..e69de29bb From 26cadb6fa0075ba0a99389e9349a556d0da8ac0d Mon Sep 17 00:00:00 2001 From: "s.ashour82" Date: Mon, 30 Dec 2024 22:46:38 +0200 Subject: [PATCH 037/116] factorial challenge factorial challenge is done --- .vscode/settings.json | 6 +++- solutions/factorial.py | 56 +++++++++++++++++++++++++++++ solutions/tests/test_factorial.py | 59 +++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 solutions/factorial.py create mode 100644 solutions/tests/test_factorial.py diff --git a/.vscode/settings.json b/.vscode/settings.json index 058679944..1b51e567f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -116,5 +116,9 @@ "markdown.extension.toc.updateOnSave": false, "[python]": { "editor.defaultFormatter": "ms-python.black-formatter" - } + }, + "cSpell.words": [ + "Ashour", + "Saad" + ] } diff --git a/solutions/factorial.py b/solutions/factorial.py new file mode 100644 index 000000000..6c9afb155 --- /dev/null +++ b/solutions/factorial.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +A module for Computing the factorial of a non-negative integer n. + +Module contents: + - factorial: is the product of all positive integers less than or equal to n. + +Created on XX XX XX +@author: Saad M. Ashour +""" + + +def factorial(n: int) -> int: + """ + Computes the factorial of a non-negative integer n. + + The factorial of a non-negative integer n + is the product of all positive integers less than or equal to n. + + Parameters: + n (int): A non-negative integer. + + Returns: + int: The factorial of the input integer n. + + Raises: + ValueError: If n is negative, as factorial is not defined for negative numbers. + TypeError: If n is not an integer, as factorials are only defined for integers. + + Examples: + >>> factorial(0) + 1 + + >>> factorial(1) + 1 + + >>> factorial(5) + 120 + + >>> factorial(3) + 6 + """ + # Validate input type and value + if not isinstance(n, int): + raise TypeError("Input must be an integer.") + + if n < 0: + raise ValueError("Factorial is not defined for negative numbers.") + + # Base case for recursion: 0! = 1 + if n == 0 or n == 1: + return 1 + + # Recursive case: n! = n * (n-1)! + return n * factorial(n - 1) diff --git a/solutions/tests/test_factorial.py b/solutions/tests/test_factorial.py new file mode 100644 index 000000000..0c3e3f40c --- /dev/null +++ b/solutions/tests/test_factorial.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Unit tests for factorial function. + +@author: Saad M. Ashour +""" + +import unittest +from solutions.factorial import factorial + + +class TestFactorial(unittest.TestCase): + """ + Unit tests for the factorial function. + + The factorial function computes the factorial of a non-negative integer using recursion. + These tests verify its correctness for various inputs, + including edge cases, valid cases, and invalid cases. + """ + + +def test_factorial_zero(self): + """It should evaluate 0 to 1""" + actual = factorial(0) + expected = 1 + self.assertEqual(actual, expected) + + +def test_factorial_one(self): + """It should evaluate 1 to 1""" + actual = factorial(1) + expected = 1 + self.assertEqual(actual, expected) + + +def test_factorial_positive(self): + """It should evaluate 5 to 120""" + actual = factorial(5) + expected = 120 + self.assertEqual(actual, expected) + + +def test_factorial_negative(self): + """factorial of negative integer will raise Error""" + with self.assertRaises(ValueError): + factorial(-1) + + +def test_factorial_non_integer(self): + """factorial of non integer will raise Error""" + with self.assertRaises(TypeError): + factorial(3.5) + with self.assertRaises(TypeError): + factorial("string") + + +if __name__ == "__main__": + unittest.main() From 7645c04a22daca870d52cabb25ab38466788cd5b Mon Sep 17 00:00:00 2001 From: Moealfadil <142026026+Moealfadil@users.noreply.github.com> Date: Tue, 31 Dec 2024 03:40:36 +0200 Subject: [PATCH 038/116] adding descriptive tests --- solutions/mean.py | 6 +++++- solutions/tests/test_mean.py | 24 ++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/solutions/mean.py b/solutions/mean.py index bb5168f3d..642f2b78c 100644 --- a/solutions/mean.py +++ b/solutions/mean.py @@ -22,8 +22,12 @@ def mean(a: list) -> float: 3.0 >>> mean([10, 20, 30, 40, 50]) 30.0 + >>> mean([1.5, 2.5, 3.5]) + 2.5 + >>>mean([2]) + 2.0 """ if not isinstance(a, list): return "invalid input" - + # return the mean of the list by dividing the sum of the list by the length of the list return sum(a) / len(a) diff --git a/solutions/tests/test_mean.py b/solutions/tests/test_mean.py index 90b160c64..920dfecf3 100644 --- a/solutions/tests/test_mean.py +++ b/solutions/tests/test_mean.py @@ -1,5 +1,15 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +""" +Module: test_mean + +Description: + This module contains the unit tests for the mean function in the solutions package. + the function calculates the mean of a list of numbers. + +Author: Mohammed Elfadil +Date: 31/12/2024 +""" import unittest from solutions.mean import mean @@ -7,25 +17,25 @@ class TestMean(unittest.TestCase): """test the mean function""" - def test_1(self): + def test_positive_numbers(self): """It should evaluate 3.0""" actual = mean([1, 2, 3, 4, 5]) expected = 3.0 self.assertEqual(actual, expected) - def test_2(self): + def test_positive_numbers2(self): """It should evaluate 30.0""" actual = mean([10, 20, 30, 40, 50]) expected = 30.0 self.assertEqual(actual, expected) - def test_3(self): + def test_zeros(self): """It should evaluate 0.0""" actual = mean([0, 0, 0, 0, 0]) expected = 0.0 self.assertEqual(actual, expected) - def test_4(self): + def test_single_input(self): """It should evaluate 1.0""" actual = mean([1]) expected = 1.0 @@ -48,3 +58,9 @@ def test_floats(self): actual = mean([1.5, 2.5, 3.5]) expected = 2.5 self.assertEqual(actual, expected) + + def test_string(self): + """It should evaluate inavlid input""" + actual = mean(["a", "b", "c"]) + expected = "invalid input" + self.assertEqual(actual, expected) From 15314ccc44b0338643eb8d06c7aefb8c6f7fce7e Mon Sep 17 00:00:00 2001 From: Moealfadil <142026026+Moealfadil@users.noreply.github.com> Date: Tue, 31 Dec 2024 03:43:38 +0200 Subject: [PATCH 039/116] fix tests --- solutions/tests/test_mean.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/solutions/tests/test_mean.py b/solutions/tests/test_mean.py index 920dfecf3..0b43e9845 100644 --- a/solutions/tests/test_mean.py +++ b/solutions/tests/test_mean.py @@ -11,6 +11,7 @@ Date: 31/12/2024 """ import unittest + from solutions.mean import mean @@ -61,6 +62,6 @@ def test_floats(self): def test_string(self): """It should evaluate inavlid input""" - actual = mean(["a", "b", "c"]) + actual = mean("2 4 6") expected = "invalid input" self.assertEqual(actual, expected) From 551a3ecf54614ad4d8ff84044a4c3eccb25d452f Mon Sep 17 00:00:00 2001 From: Moealfadil <142026026+Moealfadil@users.noreply.github.com> Date: Tue, 31 Dec 2024 03:45:11 +0200 Subject: [PATCH 040/116] fix formmatting --- solutions/tests/test_mean.py | 1 - 1 file changed, 1 deletion(-) diff --git a/solutions/tests/test_mean.py b/solutions/tests/test_mean.py index 0b43e9845..b1bad4fa8 100644 --- a/solutions/tests/test_mean.py +++ b/solutions/tests/test_mean.py @@ -11,7 +11,6 @@ Date: 31/12/2024 """ import unittest - from solutions.mean import mean From d62b5c1073ec555c7d6ca1660ee0f1be9728dadb Mon Sep 17 00:00:00 2001 From: Moealfadil <142026026+Moealfadil@users.noreply.github.com> Date: Tue, 31 Dec 2024 03:56:22 +0200 Subject: [PATCH 041/116] fixed formatting --- solutions/mean.py | 7 ++++--- solutions/tests/test_mean.py | 13 ++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/solutions/mean.py b/solutions/mean.py index 642f2b78c..9c9d4cf01 100644 --- a/solutions/mean.py +++ b/solutions/mean.py @@ -6,7 +6,7 @@ Module contents: - mean: finds the mean of a list of numbers. -Created on XX XX XX +Created on 29/12/2024 @author: Mohammed Elfadil """ @@ -27,7 +27,8 @@ def mean(a: list) -> float: >>>mean([2]) 2.0 """ - if not isinstance(a, list): - return "invalid input" + # check if the argument is a list + assert isinstance(a, list), "invalid input" + # return the mean of the list by dividing the sum of the list by the length of the list return sum(a) / len(a) diff --git a/solutions/tests/test_mean.py b/solutions/tests/test_mean.py index b1bad4fa8..6acc4cfc9 100644 --- a/solutions/tests/test_mean.py +++ b/solutions/tests/test_mean.py @@ -10,6 +10,7 @@ Author: Mohammed Elfadil Date: 31/12/2024 """ + import unittest from solutions.mean import mean @@ -43,9 +44,8 @@ def test_single_input(self): def test_integer(self): """It should evaluate invalid input""" - actual = mean(1) - expected = "invalid input" - self.assertEqual(actual, expected) + with self.assertRaises(AssertionError): + mean(2) def test_negatives(self): """It should evaluate -4.0""" @@ -60,7 +60,6 @@ def test_floats(self): self.assertEqual(actual, expected) def test_string(self): - """It should evaluate inavlid input""" - actual = mean("2 4 6") - expected = "invalid input" - self.assertEqual(actual, expected) + """Test that invalid input raises an AssertionError.""" + with self.assertRaises(AssertionError): + mean("2, 3, 4, 5") From cd062fe86e66715dab7a8e84d54170f78a3a06aa Mon Sep 17 00:00:00 2001 From: colevandersWands <18554853+colevandersWands@users.noreply.github.com> Date: Tue, 31 Dec 2024 00:45:28 -0500 Subject: [PATCH 042/116] no commented code, no print statements --- .github/PULL_REQUEST_TEMPLATE.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 330a04cbc..a211d8686 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -82,5 +82,7 @@ about: A template PR for code review with a checklist - [ ] Variable names are clear and helpful - [ ] The code follows the strategy as simply as possible - [ ] The implementation is as simple as possible given the strategy +- [ ] There are no commented lines of code +- [ ] There are no `print` statements anywhere - [ ] The code includes defensive assertions - [ ] Defensive assertions include as little logic as possible From 5effaf514caab0f6733a46c631b24268e4dd3f9d Mon Sep 17 00:00:00 2001 From: colevandersWands <18554853+colevandersWands@users.noreply.github.com> Date: Tue, 31 Dec 2024 00:46:35 -0500 Subject: [PATCH 043/116] do not call the function in the function file --- .github/PULL_REQUEST_TEMPLATE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index a211d8686..6e269b4ad 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -55,6 +55,7 @@ about: A template PR for code review with a checklist - [ ] The function's name describes it's behavior - [ ] The function's name matches the file name - [ ] The function has correct type annotations +- [ ] The function is not called in the function file ## Strategy From ba6952dbf29cfb08dd21900e710ac04df216cf5b Mon Sep 17 00:00:00 2001 From: "s.ashour82" Date: Tue, 31 Dec 2024 13:03:51 +0200 Subject: [PATCH 044/116] Update settings.json --- .vscode/settings.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 1b51e567f..058679944 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -116,9 +116,5 @@ "markdown.extension.toc.updateOnSave": false, "[python]": { "editor.defaultFormatter": "ms-python.black-formatter" - }, - "cSpell.words": [ - "Ashour", - "Saad" - ] + } } From ad84209e8d6e1b668d7362513d865a17a8ae003f Mon Sep 17 00:00:00 2001 From: raghad598 Date: Tue, 31 Dec 2024 17:19:06 +0200 Subject: [PATCH 045/116] function for counting words and unit test done --- count words.py | 18 ++++++++++++++++++ unit test.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 count words.py create mode 100644 unit test.py diff --git a/count words.py b/count words.py new file mode 100644 index 000000000..78d5aff76 --- /dev/null +++ b/count words.py @@ -0,0 +1,18 @@ +def count_words(text): + """ + Counts the number of words in a given string. + + Args: + text (str): The string to analyze. + + Returns: + int: The number of words in the string. + """ + # Split the text by whitespace and count the resulting parts + words = text.split() + return len(words) + +# Example usage +example_text = "Hello, Nova! How many words are in this sentence?" +word_count = count_words(example_text) +print(f"The text contains {word_count} words.") diff --git a/unit test.py b/unit test.py new file mode 100644 index 000000000..4fea2c415 --- /dev/null +++ b/unit test.py @@ -0,0 +1,42 @@ +import unittest + +def count_words(text): + """ + Counts the number of words in a given string. + + Args: + text (str): The string to analyze. + + Returns: + int: The number of words in the string. + """ + words = text.split() + return len(words) + +class TestCountWords(unittest.TestCase): + def test_empty_string(self): + """Test with an empty string""" + self.assertEqual(count_words(""), 0) + + def test_single_word(self): + """Test with a single word""" + self.assertEqual(count_words("hello"), 1) + + def test_multiple_words(self): + """Test with multiple words""" + self.assertEqual(count_words("Hello, world!"), 2) + + def test_extra_spaces(self): + """Test with extra spaces""" + self.assertEqual(count_words(" Hello world "), 2) + + def test_numbers_and_words(self): + """Test with a mix of numbers and words""" + self.assertEqual(count_words("123 hello 456 world"), 4) + + def test_special_characters(self): + """Test with special characters""" + self.assertEqual(count_words("!@# $%^ &*()"), 3) + +if __name__ == "__main__": + unittest.main() \ No newline at end of file From 33b19bae8217a130f7b7408f437d9aba87bd6b8d Mon Sep 17 00:00:00 2001 From: "s.ashour82" Date: Tue, 31 Dec 2024 20:21:08 +0200 Subject: [PATCH 046/116] is_palindrome function coding is_palindrome function and its unit test --- solutions/is_palindrome.py | 40 ++++++++++++++++++ solutions/tests/test_is_palindrome.py | 60 +++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 solutions/is_palindrome.py create mode 100644 solutions/tests/test_is_palindrome.py diff --git a/solutions/is_palindrome.py b/solutions/is_palindrome.py new file mode 100644 index 000000000..797da018d --- /dev/null +++ b/solutions/is_palindrome.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +A module for checking if a given string is a palindrome (reads the same backward as forward) + +Module contents: + - palindrome: input string is palindrome if it reads the same backward as forward + +Created on XX XX XX +@author: Saad M. Ashour +""" + + +def is_palindrome(s: str) -> bool: + """ + Check if a given string is a palindrome. + + A palindrome is a word, phrase, number, or other sequence of characters + that reads the same forward and backward, ignoring spaces, punctuation, + and case sensitivity. + + Parameters: + s (str): The input string to be checked. + + Returns: + bool: True if the input string is a palindrome, False otherwise. + + Examples: + >>> is_palindrome("A man, a plan, a canal, Panama") + True + >>> is_palindrome("hello") + False + >>> is_palindrome("Madam") + True + """ + # Remove non-alphanumeric characters and convert to lowercase + cleaned = "".join(char.lower() for char in s if char.isalnum()) + + # Check if the cleaned string is equal to its reverse + return cleaned == cleaned[::-1] diff --git a/solutions/tests/test_is_palindrome.py b/solutions/tests/test_is_palindrome.py new file mode 100644 index 000000000..f6d746a61 --- /dev/null +++ b/solutions/tests/test_is_palindrome.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Unit tests for is_palindrome function. + +@author: Saad M. Ashour +""" + +import unittest + +from ..is_palindrome import is_palindrome + + +class TestIsPalindrome(unittest.TestCase): + """ + Unit tests for the is_palindrome function. + + These tests check various cases to ensure that the is_palindrome function correctly + identifies palindromes, considering case insensitivity, non-alphanumeric characters, + and other edge cases. + """ + + def test_palindrome(self): + """ + Test cases where the string is a palindrome. + """ + self.assertTrue(is_palindrome("A man, a plan, a canal, Panama")) + self.assertTrue(is_palindrome("racecar")) + self.assertTrue(is_palindrome("Madam")) + + def test_non_palindrome(self): + """ + Test cases where the string is not a palindrome. + """ + self.assertFalse(is_palindrome("hello")) + self.assertFalse(is_palindrome("world")) + + def test_empty_string(self): + """ + Test case where the input is an empty string, which is considered a palindrome. + """ + self.assertTrue(is_palindrome("")) + + def test_single_character(self): + """ + Test case where the input is a single character, which is always a palindrome. + """ + self.assertTrue(is_palindrome("a")) + self.assertTrue(is_palindrome("1")) + + def test_only_non_alphanumeric(self): + """ + Test case where the input contains only non-alphanumeric characters. + The function should ignore them and return True for empty string. + """ + self.assertTrue(is_palindrome("!@#$$@!")) + + +if __name__ == "__main__": + unittest.main() From 11329c75d3d242d73ccf38d5d283a957cadd43f1 Mon Sep 17 00:00:00 2001 From: Heba Shaheen Date: Wed, 1 Jan 2025 19:34:06 +0300 Subject: [PATCH 047/116] decimal to binary challenge --- solutions/decimal_to_binary.py | 41 +++++++++++++++++++ solutions/tests/test_decimal_to_binary.py | 49 +++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 solutions/decimal_to_binary.py create mode 100644 solutions/tests/test_decimal_to_binary.py diff --git a/solutions/decimal_to_binary.py b/solutions/decimal_to_binary.py new file mode 100644 index 000000000..b8a74ecac --- /dev/null +++ b/solutions/decimal_to_binary.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +A function to convert decimal numbers to binary. + +Created on 1/1/2025 +@author: Heba Shaheen +""" + + +def decimal_to_binary(n: int) -> str: + """Give the binary number for a decimal + + Args: + n (int): Decimal number to be converted + + Returns: + str: Binary representation of the decimal number + + Raises: + AssertionError: if the input is not an integer + + >>> decimal_to_binary(10) + "1010" + + >>> decimal_to_binary(20) + "10100" + + >>> decimal_to_binary(255) + "11111111" + """ + # Handle the edge case for 0 + assert isinstance(n, int), "The input should be integer" + assert n >= 0, "Give a positive input" + if n == 0: + return "0" + binary = "" + while n > 0: + binary = str(n % 2) + binary + n //= 2 + return binary diff --git a/solutions/tests/test_decimal_to_binary.py b/solutions/tests/test_decimal_to_binary.py new file mode 100644 index 000000000..cab9b4c46 --- /dev/null +++ b/solutions/tests/test_decimal_to_binary.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Unit tests for decimal_to_binary function. + +@author: Heba Shaheen +""" + +import unittest + +from ..decimal_to_binary import decimal_to_binary + + +class TestBinary(unittest.TestCase): + """Unit tests for decimal_to_binary function.""" + + def test_number_0(self): + """It should give the binary""" + actual = decimal_to_binary(0) + expected = "0" + self.assertEqual(actual, expected) + + def test_number_2(self): + """It should give the binary""" + actual = decimal_to_binary(2) + expected = "10" + self.assertEqual(actual, expected) + + def test_number_5(self): + """It should give the binary""" + actual = decimal_to_binary(5) + expected = "101" + self.assertEqual(actual, expected) + + def test_number_15(self): + """It should give the binary""" + actual = decimal_to_binary(15) + expected = "1111" + self.assertEqual(actual, expected) + + def test_non_integer_input(self): + """It should raise an assertion error if the argument is not an integer""" + with self.assertRaises(AssertionError): + decimal_to_binary("1") + + def test_non_negative_input(self): + """It should raise an assertion error if the argument is negative""" + with self.assertRaises(AssertionError): + decimal_to_binary(-3) From e3775f5ec7d5ff21d5c52cc877b01c55fd2917ff Mon Sep 17 00:00:00 2001 From: Raghad Abdul Rahim Date: Thu, 2 Jan 2025 13:52:26 +0300 Subject: [PATCH 048/116] Update count words.py --- count words.py | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/count words.py b/count words.py index 78d5aff76..c2ef107ca 100644 --- a/count words.py +++ b/count words.py @@ -1,18 +1,35 @@ -def count_words(text): - """ - Counts the number of words in a given string. +""" +A module for counting words in a string. + +Module contents: + - count_words: counts the number of words in a string. + +Created on 01 01 2025 +@author: Raghad +""" + + +def count_words(text: str) -> int: + """Count the number of words in a given string. - Args: - text (str): The string to analyze. + Parameters: + text: str, the input string to analyze - Returns: - int: The number of words in the string. + Returns -> int: number of words in the text + + Raises: + AssertionError: if the argument is not a string + + >>> count_words("Hello World") + 2 + >>> count_words("Python programming is fun") + 4 + >>> count_words("") + 0 """ + # Validate input + assert isinstance(text, str), "Input must be a string" + # Split the text by whitespace and count the resulting parts words = text.split() return len(words) - -# Example usage -example_text = "Hello, Nova! How many words are in this sentence?" -word_count = count_words(example_text) -print(f"The text contains {word_count} words.") From caf684758a9c3d6ec8e79dac44cbce1f7d0643cd Mon Sep 17 00:00:00 2001 From: Raghad Abdul Rahim Date: Thu, 2 Jan 2025 13:53:12 +0300 Subject: [PATCH 049/116] Rename unit test.py to test_count_words.py --- unit test.py => test_count_words.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename unit test.py => test_count_words.py (98%) diff --git a/unit test.py b/test_count_words.py similarity index 98% rename from unit test.py rename to test_count_words.py index 4fea2c415..491a4d1ad 100644 --- a/unit test.py +++ b/test_count_words.py @@ -39,4 +39,4 @@ def test_special_characters(self): self.assertEqual(count_words("!@# $%^ &*()"), 3) if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main() From fb077d02b1cc457be166d0a40df2e41c4667a09d Mon Sep 17 00:00:00 2001 From: Raghad Abdul Rahim Date: Thu, 2 Jan 2025 13:53:24 +0300 Subject: [PATCH 050/116] Rename count words.py to count_words.py --- count words.py => count_words.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename count words.py => count_words.py (100%) diff --git a/count words.py b/count_words.py similarity index 100% rename from count words.py rename to count_words.py From 4d00190f7aae2a7df27f5d179f73c14bac9b6ebd Mon Sep 17 00:00:00 2001 From: Raghad Abdul Rahim Date: Thu, 2 Jan 2025 14:02:29 +0300 Subject: [PATCH 051/116] Create count_words.py --- solutions/count_words.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 solutions/count_words.py diff --git a/solutions/count_words.py b/solutions/count_words.py new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/solutions/count_words.py @@ -0,0 +1 @@ + From 3471944eb3fe3165a9fbcb092518c1fab252ccb5 Mon Sep 17 00:00:00 2001 From: Raghad Abdul Rahim Date: Thu, 2 Jan 2025 14:02:54 +0300 Subject: [PATCH 052/116] Update count_words.py --- solutions/count_words.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/solutions/count_words.py b/solutions/count_words.py index 8b1378917..c2ef107ca 100644 --- a/solutions/count_words.py +++ b/solutions/count_words.py @@ -1 +1,35 @@ +""" +A module for counting words in a string. +Module contents: + - count_words: counts the number of words in a string. + +Created on 01 01 2025 +@author: Raghad +""" + + +def count_words(text: str) -> int: + """Count the number of words in a given string. + + Parameters: + text: str, the input string to analyze + + Returns -> int: number of words in the text + + Raises: + AssertionError: if the argument is not a string + + >>> count_words("Hello World") + 2 + >>> count_words("Python programming is fun") + 4 + >>> count_words("") + 0 + """ + # Validate input + assert isinstance(text, str), "Input must be a string" + + # Split the text by whitespace and count the resulting parts + words = text.split() + return len(words) From ebe48d0230ee9425c2269ad97e5396e1bb41104c Mon Sep 17 00:00:00 2001 From: Raghad Abdul Rahim Date: Thu, 2 Jan 2025 14:03:10 +0300 Subject: [PATCH 053/116] Delete count_words.py --- count_words.py | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 count_words.py diff --git a/count_words.py b/count_words.py deleted file mode 100644 index c2ef107ca..000000000 --- a/count_words.py +++ /dev/null @@ -1,35 +0,0 @@ -""" -A module for counting words in a string. - -Module contents: - - count_words: counts the number of words in a string. - -Created on 01 01 2025 -@author: Raghad -""" - - -def count_words(text: str) -> int: - """Count the number of words in a given string. - - Parameters: - text: str, the input string to analyze - - Returns -> int: number of words in the text - - Raises: - AssertionError: if the argument is not a string - - >>> count_words("Hello World") - 2 - >>> count_words("Python programming is fun") - 4 - >>> count_words("") - 0 - """ - # Validate input - assert isinstance(text, str), "Input must be a string" - - # Split the text by whitespace and count the resulting parts - words = text.split() - return len(words) From d3c1950e5c9f621b346b859951b99e8dbb28014b Mon Sep 17 00:00:00 2001 From: Raghad Abdul Rahim Date: Thu, 2 Jan 2025 14:04:34 +0300 Subject: [PATCH 054/116] Create test_count_words --- solutions/tests/test_count_words | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 solutions/tests/test_count_words diff --git a/solutions/tests/test_count_words b/solutions/tests/test_count_words new file mode 100644 index 000000000..2e201cfaf --- /dev/null +++ b/solutions/tests/test_count_words @@ -0,0 +1,46 @@ +import unittest +from solutions.count_words import count_words + + +def count_words(text): + """ + Counts the number of words in a given string. + + Args: + text (str): The string to analyze. + + Returns: + int: The number of words in the string. + """ + words = text.split() + return len(words) + + +class TestCountWords(unittest.TestCase): + def test_empty_string(self): + """Test with an empty string""" + self.assertEqual(count_words(""), 0) + + def test_single_word(self): + """Test with a single word""" + self.assertEqual(count_words("hello"), 1) + + def test_multiple_words(self): + """Test with multiple words""" + self.assertEqual(count_words("Hello, world!"), 2) + + def test_extra_spaces(self): + """Test with extra spaces""" + self.assertEqual(count_words(" Hello world "), 2) + + def test_numbers_and_words(self): + """Test with a mix of numbers and words""" + self.assertEqual(count_words("123 hello 456 world"), 4) + + def test_special_characters(self): + """Test with special characters""" + self.assertEqual(count_words("!@# $%^ &*()"), 3) + + +if __name__ == "__main__": + unittest.main() From bda59e41b5a916260a968a787cda11e0df30d2a6 Mon Sep 17 00:00:00 2001 From: Raghad Abdul Rahim Date: Thu, 2 Jan 2025 14:04:53 +0300 Subject: [PATCH 055/116] Delete test_count_words.py --- test_count_words.py | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 test_count_words.py diff --git a/test_count_words.py b/test_count_words.py deleted file mode 100644 index 491a4d1ad..000000000 --- a/test_count_words.py +++ /dev/null @@ -1,42 +0,0 @@ -import unittest - -def count_words(text): - """ - Counts the number of words in a given string. - - Args: - text (str): The string to analyze. - - Returns: - int: The number of words in the string. - """ - words = text.split() - return len(words) - -class TestCountWords(unittest.TestCase): - def test_empty_string(self): - """Test with an empty string""" - self.assertEqual(count_words(""), 0) - - def test_single_word(self): - """Test with a single word""" - self.assertEqual(count_words("hello"), 1) - - def test_multiple_words(self): - """Test with multiple words""" - self.assertEqual(count_words("Hello, world!"), 2) - - def test_extra_spaces(self): - """Test with extra spaces""" - self.assertEqual(count_words(" Hello world "), 2) - - def test_numbers_and_words(self): - """Test with a mix of numbers and words""" - self.assertEqual(count_words("123 hello 456 world"), 4) - - def test_special_characters(self): - """Test with special characters""" - self.assertEqual(count_words("!@# $%^ &*()"), 3) - -if __name__ == "__main__": - unittest.main() From 6b1e0425f7369a511542cdec90af6d6efe600b43 Mon Sep 17 00:00:00 2001 From: colevandersWands <18554853+colevandersWands@users.noreply.github.com> Date: Fri, 3 Jan 2025 16:22:14 -0500 Subject: [PATCH 056/116] fix config error --- .vscode/settings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bbda5188d..252022b48 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -119,8 +119,8 @@ "editor.defaultFormatter": "charliermarsh.ruff", "editor.formatOnSave": true, "editor.codeActionsOnSave": { - "source.fixAll.ruff": true, - "source.organizeImports.ruff": true + "source.fixAll.ruff": "explicit", + "source.organizeImports.ruff": "explicit" } } } From 553b1c326733ed0e1efc60514d3e9ec5b7f221af Mon Sep 17 00:00:00 2001 From: raghad598 Date: Sat, 4 Jan 2025 15:51:18 +0200 Subject: [PATCH 057/116] 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 9d85d3a4c4373189aaefccae3fd5433f91050d10 Mon Sep 17 00:00:00 2001 From: colevandersWands <18554853+colevandersWands@users.noreply.github.com> Date: Mon, 6 Jan 2025 14:35:14 -0500 Subject: [PATCH 058/116] clarify "no function calls" item --- .github/PULL_REQUEST_TEMPLATE.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6e269b4ad..eb18b4638 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -55,7 +55,8 @@ about: A template PR for code review with a checklist - [ ] The function's name describes it's behavior - [ ] The function's name matches the file name - [ ] The function has correct type annotations -- [ ] The function is not called in the function file +- [ ] The function is not called at the top level of the function file + - _Recursive solutions **can** call the function from **inside** the function body_ ## Strategy From 6fecc20c7575acca304b610bc964f36bc6cd5fd6 Mon Sep 17 00:00:00 2001 From: Falaq Abdulmajeed Date: Tue, 7 Jan 2025 14:51:26 +0300 Subject: [PATCH 059/116] updated readme --- .vscode/settings.json | 12 +++++- README.md | 91 +++++++++++++++++++++++++++++++++---------- 2 files changed, 81 insertions(+), 22 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5a90e202f..f4cc56b56 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -113,5 +113,15 @@ }, // Enable/disable update table of contents on save - "markdown.extension.toc.updateOnSave": false + "markdown.extension.toc.updateOnSave": false, + "cSpell.words": [ + "Falag", + "Falaq", + "Heba", + "Luyando", + "Muna", + "Raghad", + "Saad", + "Taqwa" + ] } diff --git a/README.md b/README.md index 9f8654427..2c8cf2e04 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,86 @@ -# WELCOME TO THE CODE COLLABORATORS' REPOSITORY +# [![Typing SVG](https://readme-typing-svg.herokuapp.com?font=Fira+Code&size=26&pause=1000&width=435&lines=Welcome+to++RepoRangers!+%F0%9F%A4%A0%F0%9F%8C%B2)](https://git.io/typing-svg) -![Visual aid code collaborators are from different parts of the world!](assets/collaboration.jpg) -We are a collaborative group of problem-solvers who are working together to tackle -exciting challenges in this particular project. +![Technology GIF](https://media.giphy.com/media/bGgsc5mWoryfgKBx1u/giphy.gif) + +We are a collaborative group of problem-solvers working together to tackle +exciting Python challenges in this particular project. + +## 🀝 Meet Us + +Here's a fun fact about each of us and our GitHub accounts: + +- **[Agnes](https://github.com/lwjskidsister)** πŸ€“πŸ’Ž + *Fun Fact:* "I'm a nerd when it comes to diamonds." + +- **[Falaq](https://github.com/FalaqMajeed)** βš½πŸ“Š + *Fun Fact:* "Watching and analyzing football matches is my ultimate favorite pastime!" + +- **[Heba](https://github.com/HebaShaheen)** β˜•οΈπŸ˜… + *Fun Fact:* "I drink a lot of Nescafe, 2 or 3 cups a day." + +- **[Luyando](https://github.com/Luyando-Chitindi)** πŸ˜‚πŸ˜‚ + *Fun Fact:* "I absolutely love laughingβ€”it’s my favorite thing to do!" + +- **[Marc](https://github.com/MarcDarazi99)** πŸ‹πŸ˜‹ + *Fun Fact:* "I’m a proud mango loverβ€”if coding were a fruit, it’d be a mango: + sweet, versatile, and endlessly satisfying!" + +- **[Mohammed](https://github.com/Moealfadil)** πŸ€“πŸ“š + *Fun Fact:* "I like mathematical theories." + +- **[Muna](https://github.com/Muna-S)** 🐎❀️ + *Fun Fact:* "I’m completely obsessed with horsesβ€”they're my passion." + +- **[Raghad](https://github.com/raghad598)** πŸ’‡β€β™€οΈ + *Fun Fact:* "Every night before bed, I brush my hair and spritz on some perfume." + +- **[Saad](https://github.com/sashour82)** πŸ‘¨β€πŸ’» + *Fun Fact:* "Failed my first coding course, but graduated with a great GPA and + 12 years in tech!" + +- **[Taqwa](https://github.com/TagwaHashim)** πŸ“šπŸ˜„ + *Fun Fact:* "I'm like a hardcover book full of funny stories." ## πŸš€ Mission -Our main mission is to build a foundation of creativity, collaboration, and learning -while developing basic solutions that help in the build-up of solutions that -provide aid to real-world problems. +Our main mission is to cultivate creativity, collaboration, and continuous +learning, while crafting innovative Python solutions and documenting them +in the best possible way. πŸπŸ“ ## πŸ” Our Current Focus -We are currently exploring the endless world of project challenges. -Each member of this group will select two challenges and share their progress in -this repository. +We are currently exploring the endless world of project challenges. Each member +of this group will select two challenges and share their progress in this +repository. πŸ† -## Repository Overview +## πŸ“‚ Repository Overview This repository contains the following: -- Group collaborations -- Solutions and Tests to individual challenge projects. +- Group collaborations 🀝 +- Solutions and tests for individual challenge projects πŸ”¬ + +## πŸ’‘ Contributions + +Our aim is to promote collaboration among members. We believe there is always room +for improvement in everything we do, and we welcome contributions, suggestions, +and feedback from all members. πŸ› οΈ + +## πŸ“š Want to Know More About Our Collaboration? -## Contributions +- πŸ“ **[Our Group Norms](https://github.com/MIT-Emerging-Talent/ET6-foundations-group-18/tree/main/collaboration)** +- 🎯 **[Learning Goals](https://github.com/MIT-Emerging-Talent/ET6-foundations-group-18/blob/main/collaboration/learning_goals.md)** +- πŸ’¬ **[Communication](https://github.com/MIT-Emerging-Talent/ET6-foundations-group-18/blob/main/collaboration/communication.md)** +- 🚧 **[Constraints](https://github.com/MIT-Emerging-Talent/ET6-foundations-group-18/blob/main/collaboration/communication.md)** +- πŸ”„ **[Retrospective](https://github.com/MIT-Emerging-Talent/ET6-foundations-group-18/blob/main/collaboration/retrospective.md)** +- 🐍 **[Our Python challenges and their tests](https://github.com/MIT-Emerging-Talent/ET6-foundations-group-18/tree/main/solutions)** -Our aim is to promote collaboration among members. As we believe that -there is always room for improvement in everything we do, we welcome -contributions, suggestions, and feedback from all members. +## 🌱 What to Expect? -## 🀩 What to expect? +As our project and challenges evolve, so will this README. Stay tuned for our +regular updates! πŸ”„ -As our project and challenges change, so will this README. Stay tuned for our -regular updates, +## πŸ’¬ Remember -Join us as we grow on this platform together! +*Let's keep the hard work flowing, grow together, and put our heart and soul into +every line of code!* πŸ’– From 50a35d279bd92d18a2886bf55d9c483e8aa859b7 Mon Sep 17 00:00:00 2001 From: colevandersWands <18554853+colevandersWands@users.noreply.github.com> Date: Tue, 7 Jan 2025 18:18:33 -0500 Subject: [PATCH 060/116] checklist updates post-Q&A --- .github/PULL_REQUEST_TEMPLATE.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index eb18b4638..eba8a7be2 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -54,6 +54,7 @@ about: A template PR for code review with a checklist - [ ] The function's name describes it's behavior - [ ] The function's name matches the file name + - _It's ok to have extra helper functions if necessary, like with mergesort_ - [ ] The function has correct type annotations - [ ] The function is not called at the top level of the function file - _Recursive solutions **can** call the function from **inside** the function body_ @@ -68,7 +69,7 @@ about: A template PR for code review with a checklist ### Don'ts -- [ ] The function's strategy _is not_ described in the documentation +- [ ] The function's strategy _is not_ described in any docstrings or tests - [ ] Comments explain the _strategy_, **not** the _implementation_ - [ ] The function _does not_ have more comments than code - If it does, consider finding a new strategy or a simpler implementation From 04870c7b2b0bc58e803b7a9a4f1e5c23db0163cf Mon Sep 17 00:00:00 2001 From: TagwaHashim Date: Wed, 8 Jan 2025 01:25:58 +0200 Subject: [PATCH 061/116] function and test file for myfunction --- solutions/max_in.py | 58 ++++++++++++++++++++++++++++++++ solutions/tests/test_max_in.py | 61 ++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 solutions/max_in.py create mode 100644 solutions/tests/test_max_in.py diff --git a/solutions/max_in.py b/solutions/max_in.py new file mode 100644 index 000000000..ebeebd880 --- /dev/null +++ b/solutions/max_in.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +A module for finding the maximum number of a list of numbers. + +@author: Tagwa Hashim +""" + + +def max_in(numbers): + """ + Finds the maximum number in a list of numbers + + Args: + numbers: A list of numbers (integers or floats). + + Returns: + The maximum number in the list. + + Raises: + ValueError: If the input is not a list. + ValueError: If the input list is empty. + TypeError: If the list contains non-numeric elements. + + Examples: + >>> max_in([1, 5, 3, 9, 2]) + 9 + >>> max_in([2.5, 1.02, 5.7]) + 5.7 + >>> max_in([10.5, -5.2, 8]) + 10.5 + >>> max_in([1, -5, -3]) + 1 + >>> max_in([]) + Traceback (most recent call last): + ValueError: List cannot be empty. + >>> max_in("not a list") + Traceback (most recent call last): + ValueError: Input must be a list. + >>> max_in([1, 2, "three"]) + Traceback (most recent call last): + TypeError: List contains non-numeric elements. + """ + if not isinstance(numbers, list): + raise ValueError("Input must be a list.") + if not numbers: + raise ValueError("List cannot be empty.") + for num in numbers: + if not isinstance(num, (int, float)): # Check if any element is not numeric + raise TypeError("List contains non-numeric elements.") + + max_num = numbers[0] # Initialize max_num with the first element + + for num in numbers[1:]: # Iterate through the list starting from the second element + if num > max_num: + max_num = num + + return max_num diff --git a/solutions/tests/test_max_in.py b/solutions/tests/test_max_in.py new file mode 100644 index 000000000..5b297401e --- /dev/null +++ b/solutions/tests/test_max_in.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Module: test_max_in + +Description: + This module contains unit tests for the 'max_in' function defined + in the 'max_in.py' module. + +Author: Tagwa Hashim + +""" + + +import unittest +from solutions.max_in import max_in + + +class TestMax_in(unittest.TestCase): + """Test the max_in function""" + + def test_positive_integers(self): + """it should return 9 as the maximum number in this list""" + + self.assertEqual(max_in([1, 5, 3, 9, 2]), 9) + + def test_positive_floats(self): + """it should return 10.5 as the maximum number in this list""" + self.assertEqual(max_in([10.5, 5.2, 8.7]), 10.5) + + def test_mix_types(self): + """it should return 1 as the maximum number in this list""" + self.assertEqual(max_in([1, -5.5, -3]), 1) + + def test_empty_list(self): + """""" + with self.assertRaises(ValueError): + + self.assertEqual(max_in([]), "List cannot be empty.") + + def test_single_element_list(self): + """""" + self.assertEqual(max_in([5]), 5) + + def test_non_list_input(self): + """""" + with self.assertRaises(ValueError): + + self.assertEqual(max_in("not a list"), "Input must be a list.") + + def test_list_with_non_numeric_element(self): + """""" + with self.assertRaises(TypeError): + + self.assertEqual( + max_in([1, 2, "three"]), "List contains non-numeric elements." + ) + + +if __name__ == "__main__": + unittest.main() From dbbbfd9512d770eab5733e55b70d7b71ac049e85 Mon Sep 17 00:00:00 2001 From: "s.ashour82" Date: Wed, 8 Jan 2025 09:02:01 +0200 Subject: [PATCH 062/116] update is_palindrome Falaq notes were updated.. --- solutions/is_palindrome.py | 11 +++++++---- solutions/tests/test_is_palindrome.py | 19 ++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/solutions/is_palindrome.py b/solutions/is_palindrome.py index 797da018d..61ee8e2de 100644 --- a/solutions/is_palindrome.py +++ b/solutions/is_palindrome.py @@ -6,12 +6,12 @@ Module contents: - palindrome: input string is palindrome if it reads the same backward as forward -Created on XX XX XX +Created on 30.12.2024 @author: Saad M. Ashour """ -def is_palindrome(s: str) -> bool: +def is_palindrome(input_string: str) -> bool: """ Check if a given string is a palindrome. @@ -20,7 +20,7 @@ def is_palindrome(s: str) -> bool: and case sensitivity. Parameters: - s (str): The input string to be checked. + input_string (str): The input string to be checked. Returns: bool: True if the input string is a palindrome, False otherwise. @@ -33,8 +33,11 @@ def is_palindrome(s: str) -> bool: >>> is_palindrome("Madam") True """ + # AssertionError: Input must be a string + assert isinstance(input_string, str), "Input must be a string" + # Remove non-alphanumeric characters and convert to lowercase - cleaned = "".join(char.lower() for char in s if char.isalnum()) + cleaned = "".join(char.lower() for char in input_string if char.isalnum()) # Check if the cleaned string is equal to its reverse return cleaned == cleaned[::-1] diff --git a/solutions/tests/test_is_palindrome.py b/solutions/tests/test_is_palindrome.py index f6d746a61..1f1c8d4b8 100644 --- a/solutions/tests/test_is_palindrome.py +++ b/solutions/tests/test_is_palindrome.py @@ -24,36 +24,37 @@ def test_palindrome(self): """ Test cases where the string is a palindrome. """ - self.assertTrue(is_palindrome("A man, a plan, a canal, Panama")) - self.assertTrue(is_palindrome("racecar")) - self.assertTrue(is_palindrome("Madam")) + actual = is_palindrome("A man, a plan, a canal, Panama") + self.assertTrue(actual) def test_non_palindrome(self): """ Test cases where the string is not a palindrome. """ - self.assertFalse(is_palindrome("hello")) - self.assertFalse(is_palindrome("world")) + actual = is_palindrome("hello") + self.assertFalse(actual) def test_empty_string(self): """ Test case where the input is an empty string, which is considered a palindrome. """ - self.assertTrue(is_palindrome("")) + actual = is_palindrome("") + self.assertTrue(actual) def test_single_character(self): """ Test case where the input is a single character, which is always a palindrome. """ - self.assertTrue(is_palindrome("a")) - self.assertTrue(is_palindrome("1")) + actual = is_palindrome("a") + self.assertTrue(actual) def test_only_non_alphanumeric(self): """ Test case where the input contains only non-alphanumeric characters. The function should ignore them and return True for empty string. """ - self.assertTrue(is_palindrome("!@#$$@!")) + actual = is_palindrome("!@#$$@!") + self.assertTrue(actual) if __name__ == "__main__": From cc479c18aedd4766a3b4884a449998b89055b4b6 Mon Sep 17 00:00:00 2001 From: "s.ashour82" Date: Wed, 8 Jan 2025 10:06:56 +0200 Subject: [PATCH 063/116] Update retrospective.md Retrospective md file created from starch --- collaboration/retrospective.md | 56 ++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/collaboration/retrospective.md b/collaboration/retrospective.md index 74e18813b..8b0930e22 100644 --- a/collaboration/retrospective.md +++ b/collaboration/retrospective.md @@ -1,23 +1,75 @@ -# Retrospective +# Retrospective: Group 18 - Collaborative Work Activity ## Stop Doing +- **Inefficient Coordination:** Stop relying on informal communication + methods that cause misunderstandings or delays. + +- **Overloading Tasks:** Avoid taking on excessive responsibilities + without proper delegation or prioritization. + +- **Passive Participation:** Stop being a silent participant in discussions; + ensure to actively contribute to conversations. + ## Continue Doing +- **Effective Teamwork:** Continue fostering collaboration by sharing ideas + openly and respecting diverse perspectives. + +- **Timely Updates:** Maintain a habit of providing timely progress updates + to keep the team aligned. + +- **Using Tools:** Keep leveraging collaborative tools + (e.g., shared documents, project management software) to enhance productivity. + ## Start Doing +- **Structured Planning:** Begin creating more detailed action plans with + clear milestones and deadlines. + +- **Feedback Loops:** Start implementing regular feedback sessions to + evaluate progress and address challenges early. + +- **Skill Development:** Focus on improving specific skills related + to collaborative work and presentation to contribute more effectively. + ## Lessons Learned +- Effective communication is crucial to avoid duplication of efforts and ensure alignment. + +- Clear roles and responsibilities significantly enhance team productivity. + +- Flexibility in strategy allows for better adaptation to unforeseen challenges. + +- Regular check-ins help maintain momentum and ensure accountability. + ______________________________________________________________________ ## Strategy vs. Board ### What parts of your plan went as expected? +- Collaboration tools were effectively utilized to + share resources and coordinate tasks. + +- The team successfully met initial deadlines for project deliverables. + +- Team members demonstrated a willingness to support each other when challenges arose. + ### What parts of your plan did not work out? +- Some tasks were delayed due to unclear task ownership. + +- Miscommunication led to redundant efforts in certain areas. + +- Time zone differences caused occasional scheduling conflicts. + ### Did you need to add things that weren't in your strategy? -### Or remove extra steps? +- Yes, we added weekly synchronization meetings to + address miscommunications and ensure alignment. + +- Included additional training sessions for team members to + improve tool usage efficiency. From 0b76d7816a51b4eb55af7486f0eceaed89a6a53b Mon Sep 17 00:00:00 2001 From: "s.ashour82" Date: Wed, 8 Jan 2025 10:11:17 +0200 Subject: [PATCH 064/116] Delete retrospective.md remove this file --- collaboration/retrospective.md | 75 ---------------------------------- 1 file changed, 75 deletions(-) delete mode 100644 collaboration/retrospective.md diff --git a/collaboration/retrospective.md b/collaboration/retrospective.md deleted file mode 100644 index 8b0930e22..000000000 --- a/collaboration/retrospective.md +++ /dev/null @@ -1,75 +0,0 @@ - - -# Retrospective: Group 18 - Collaborative Work Activity - -## Stop Doing - -- **Inefficient Coordination:** Stop relying on informal communication - methods that cause misunderstandings or delays. - -- **Overloading Tasks:** Avoid taking on excessive responsibilities - without proper delegation or prioritization. - -- **Passive Participation:** Stop being a silent participant in discussions; - ensure to actively contribute to conversations. - -## Continue Doing - -- **Effective Teamwork:** Continue fostering collaboration by sharing ideas - openly and respecting diverse perspectives. - -- **Timely Updates:** Maintain a habit of providing timely progress updates - to keep the team aligned. - -- **Using Tools:** Keep leveraging collaborative tools - (e.g., shared documents, project management software) to enhance productivity. - -## Start Doing - -- **Structured Planning:** Begin creating more detailed action plans with - clear milestones and deadlines. - -- **Feedback Loops:** Start implementing regular feedback sessions to - evaluate progress and address challenges early. - -- **Skill Development:** Focus on improving specific skills related - to collaborative work and presentation to contribute more effectively. - -## Lessons Learned - -- Effective communication is crucial to avoid duplication of efforts and ensure alignment. - -- Clear roles and responsibilities significantly enhance team productivity. - -- Flexibility in strategy allows for better adaptation to unforeseen challenges. - -- Regular check-ins help maintain momentum and ensure accountability. - -______________________________________________________________________ - -## Strategy vs. Board - -### What parts of your plan went as expected? - -- Collaboration tools were effectively utilized to - share resources and coordinate tasks. - -- The team successfully met initial deadlines for project deliverables. - -- Team members demonstrated a willingness to support each other when challenges arose. - -### What parts of your plan did not work out? - -- Some tasks were delayed due to unclear task ownership. - -- Miscommunication led to redundant efforts in certain areas. - -- Time zone differences caused occasional scheduling conflicts. - -### Did you need to add things that weren't in your strategy? - -- Yes, we added weekly synchronization meetings to - address miscommunications and ensure alignment. - -- Included additional training sessions for team members to - improve tool usage efficiency. From b1c66ab3eaf1e6c55c837a6cffba876d755fae1c Mon Sep 17 00:00:00 2001 From: "s.ashour82" Date: Wed, 8 Jan 2025 10:16:17 +0200 Subject: [PATCH 065/116] Update retrospective.md Retrospective is written from scratch.. --- collaboration/retrospective.md | 56 ++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/collaboration/retrospective.md b/collaboration/retrospective.md index 74e18813b..8b0930e22 100644 --- a/collaboration/retrospective.md +++ b/collaboration/retrospective.md @@ -1,23 +1,75 @@ -# Retrospective +# Retrospective: Group 18 - Collaborative Work Activity ## Stop Doing +- **Inefficient Coordination:** Stop relying on informal communication + methods that cause misunderstandings or delays. + +- **Overloading Tasks:** Avoid taking on excessive responsibilities + without proper delegation or prioritization. + +- **Passive Participation:** Stop being a silent participant in discussions; + ensure to actively contribute to conversations. + ## Continue Doing +- **Effective Teamwork:** Continue fostering collaboration by sharing ideas + openly and respecting diverse perspectives. + +- **Timely Updates:** Maintain a habit of providing timely progress updates + to keep the team aligned. + +- **Using Tools:** Keep leveraging collaborative tools + (e.g., shared documents, project management software) to enhance productivity. + ## Start Doing +- **Structured Planning:** Begin creating more detailed action plans with + clear milestones and deadlines. + +- **Feedback Loops:** Start implementing regular feedback sessions to + evaluate progress and address challenges early. + +- **Skill Development:** Focus on improving specific skills related + to collaborative work and presentation to contribute more effectively. + ## Lessons Learned +- Effective communication is crucial to avoid duplication of efforts and ensure alignment. + +- Clear roles and responsibilities significantly enhance team productivity. + +- Flexibility in strategy allows for better adaptation to unforeseen challenges. + +- Regular check-ins help maintain momentum and ensure accountability. + ______________________________________________________________________ ## Strategy vs. Board ### What parts of your plan went as expected? +- Collaboration tools were effectively utilized to + share resources and coordinate tasks. + +- The team successfully met initial deadlines for project deliverables. + +- Team members demonstrated a willingness to support each other when challenges arose. + ### What parts of your plan did not work out? +- Some tasks were delayed due to unclear task ownership. + +- Miscommunication led to redundant efforts in certain areas. + +- Time zone differences caused occasional scheduling conflicts. + ### Did you need to add things that weren't in your strategy? -### Or remove extra steps? +- Yes, we added weekly synchronization meetings to + address miscommunications and ensure alignment. + +- Included additional training sessions for team members to + improve tool usage efficiency. From 5970adf6a8ffe7d07fab8ae6f0f0544adefa5428 Mon Sep 17 00:00:00 2001 From: Raghad Abdul Rahim Date: Wed, 8 Jan 2025 11:37:42 +0300 Subject: [PATCH 066/116] Update test_count_words --- solutions/tests/test_count_words | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/solutions/tests/test_count_words b/solutions/tests/test_count_words index 2e201cfaf..1429ea00c 100644 --- a/solutions/tests/test_count_words +++ b/solutions/tests/test_count_words @@ -1,19 +1,15 @@ -import unittest -from solutions.count_words import count_words - +""" +A module for testing count_words.py -def count_words(text): - """ - Counts the number of words in a given string. +Module contents: + - Unit Test cases for function count_words - Args: - text (str): The string to analyze. +Created on 01 01 2025 +@author: Raghad +""" - Returns: - int: The number of words in the string. - """ - words = text.split() - return len(words) +import unittest +from solutions.count_words import count_words class TestCountWords(unittest.TestCase): From c7cc0de2a9ceeab88cefa16b1021fc065c7b8bf6 Mon Sep 17 00:00:00 2001 From: Raghad Abdul Rahim Date: Wed, 8 Jan 2025 11:57:10 +0300 Subject: [PATCH 067/116] 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 068/116] 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 069/116] 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 070/116] 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 071/116] 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 c0ddc514dd97d65a7dae12e1e9bc5e9040085cf5 Mon Sep 17 00:00:00 2001 From: Heba Shaheen Date: Wed, 8 Jan 2025 13:23:28 +0300 Subject: [PATCH 072/116] make changes --- solutions/decimal_to_binary.py | 16 ++++++++-------- solutions/tests/test_decimal_to_binary.py | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/solutions/decimal_to_binary.py b/solutions/decimal_to_binary.py index b8a74ecac..ba2f9e08e 100644 --- a/solutions/decimal_to_binary.py +++ b/solutions/decimal_to_binary.py @@ -8,11 +8,11 @@ """ -def decimal_to_binary(n: int) -> str: +def decimal_to_binary(decimal_input: int) -> str: """Give the binary number for a decimal Args: - n (int): Decimal number to be converted + decimal_input (int): Decimal number to be converted Returns: str: Binary representation of the decimal number @@ -30,12 +30,12 @@ def decimal_to_binary(n: int) -> str: "11111111" """ # Handle the edge case for 0 - assert isinstance(n, int), "The input should be integer" - assert n >= 0, "Give a positive input" - if n == 0: + assert isinstance(decimal_input, int), "The input should be integer" + assert decimal_input >= 0, "Give a positive input" + if decimal_input == 0: return "0" binary = "" - while n > 0: - binary = str(n % 2) + binary - n //= 2 + while decimal_input > 0: + binary = str(decimal_input % 2) + binary + decimal_input //= 2 return binary diff --git a/solutions/tests/test_decimal_to_binary.py b/solutions/tests/test_decimal_to_binary.py index cab9b4c46..a2635e9b6 100644 --- a/solutions/tests/test_decimal_to_binary.py +++ b/solutions/tests/test_decimal_to_binary.py @@ -11,29 +11,29 @@ from ..decimal_to_binary import decimal_to_binary -class TestBinary(unittest.TestCase): +class TestDecimalToBinary(unittest.TestCase): """Unit tests for decimal_to_binary function.""" def test_number_0(self): - """It should give the binary""" + """It should return "0" as binary""" actual = decimal_to_binary(0) expected = "0" self.assertEqual(actual, expected) def test_number_2(self): - """It should give the binary""" + """It should return "10" as binary""" actual = decimal_to_binary(2) expected = "10" self.assertEqual(actual, expected) def test_number_5(self): - """It should give the binary""" + """It should return "101" as binary""" actual = decimal_to_binary(5) expected = "101" self.assertEqual(actual, expected) def test_number_15(self): - """It should give the binary""" + """It should return "1111" as binary""" actual = decimal_to_binary(15) expected = "1111" self.assertEqual(actual, expected) @@ -43,7 +43,7 @@ def test_non_integer_input(self): with self.assertRaises(AssertionError): decimal_to_binary("1") - def test_non_negative_input(self): + def test_negative_input(self): """It should raise an assertion error if the argument is negative""" with self.assertRaises(AssertionError): decimal_to_binary(-3) From f5fa756d74991a571417a31326dab996b89956a5 Mon Sep 17 00:00:00 2001 From: Heba Shaheen Date: Wed, 8 Jan 2025 14:24:22 +0300 Subject: [PATCH 073/116] remove duplicates --- solutions/remove_duplicates.py | 4 ++-- solutions/tests/test_remove_duplicates.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/solutions/remove_duplicates.py b/solutions/remove_duplicates.py index 3b72fd373..8f3d46346 100644 --- a/solutions/remove_duplicates.py +++ b/solutions/remove_duplicates.py @@ -32,9 +32,9 @@ def remove_duplicates(nums: list) -> list: ['Heba', 'Noor'] """ assert isinstance(nums, list), "The input should be a list" - result = [] # List to store the result without duplicates + result = [] # List to store the result without duplicates. for num in nums: if num not in result: - result.append(num) # Add the number to the result list + result.append(num) # Add the number to the result list. return result diff --git a/solutions/tests/test_remove_duplicates.py b/solutions/tests/test_remove_duplicates.py index 33bcd99e4..9416ab8b2 100644 --- a/solutions/tests/test_remove_duplicates.py +++ b/solutions/tests/test_remove_duplicates.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ -Test module for remove_duplicates function. +Test module for remove_duplicates function Created on 2024-12-30 Author: Heba Shaheen @@ -17,17 +17,17 @@ class TestRemoveDuplicates(unittest.TestCase): # Standard test cases def test_numbers_list(self): - """It should remove duplicates numbers""" + """It should remove duplicates numbers. give [1, 2, 3, 4]""" self.assertEqual(remove_duplicates([1, 2, 3, 2, 3, 4]), [1, 2, 3, 4]) def test_letters_list(self): - """It should remove duplicates letters""" + """It should remove duplicates letters. give ["a", "v", "e", "q"]""" self.assertEqual( remove_duplicates(["a", "v", "e", "e", "q"]), ["a", "v", "e", "q"] ) def test_mix_list(self): - """It should remove duplicates items""" + """It should remove duplicates items. give [1, 2, 3, "e", 5, "a"]""" self.assertEqual( remove_duplicates([1, 2, 3, "e", 2, 1, "e", 5, "a"]), [1, 2, 3, "e", 5, "a"] ) From 4051cae0456c5981098b231eeb75db46baa02686 Mon Sep 17 00:00:00 2001 From: Falaq Abdulmajeed Date: Wed, 8 Jan 2025 16:35:57 +0300 Subject: [PATCH 074/116] added some references and guides --- notes/Extensions.md | 134 ++++++++++++++++++++++++++++++++ notes/cheetsheets.md | 9 +++ notes/creating_linking_issue.md | 34 ++++++++ 3 files changed, 177 insertions(+) create mode 100644 notes/Extensions.md create mode 100644 notes/cheetsheets.md create mode 100644 notes/creating_linking_issue.md diff --git a/notes/Extensions.md b/notes/Extensions.md new file mode 100644 index 000000000..da68356c7 --- /dev/null +++ b/notes/Extensions.md @@ -0,0 +1,134 @@ +# πŸš€ Guide: Installing and Running Ruff, Black, Pylint, and MarkdownLint in VS Code + +This guide will help you set up and use Ruff, Black, Pylint, and MarkdownLint in +Visual Studio Code (VS Code) to maintain clean and consistent code and Markdown +files and pass all the CI checks. + +--- + +## πŸ› οΈ Prerequisites + +Before starting, ensure the following are installed on your system: + +- [Python](https://www.python.org/) +- [VS Code](https://code.visualstudio.com/) +- [Node.js](https://nodejs.org/) (for MarkdownLint) + +--- + +## πŸ”§ Install Extensions in VS Code + +1. Open VS Code. +2. Go to the Extensions Marketplace (`Ctrl+Shift+X` or `Cmd+Shift+X` on Mac). +3. Install the following extensions: + - **Python** (by Microsoft) + - **MarkdownLint** (by David Anson) + +--- + +## βš™οΈ Setting Up Ruff, Black, and Pylint + +### 1️⃣ Install Ruff + +Ruff is a fast Python linter and formatter. + +```bash +pip install ruff +``` + +To integrate Ruff with VS Code: + +1. Open the VS Code settings (`Ctrl+,` or `Cmd+,` on Mac). +2. Search for `Python β€Ί Linting: Enabled` and ensure it is checked. + +### 2️⃣ Install Black + +Black is a Python code formatter. + +```bash +pip install black +``` + +To use Black in VS Code: + +1. Go to the VS Code settings. +2. Search for `Python β€Ί Formatting: Provider` and set it to `black`. + +### 3️⃣ Install Pylint + +Pylint is a Python linter that checks for errors and enforces a coding standard. + +```bash +pip install pylint +``` + +Enable Pylint in VS Code: + +1. Open the VS Code settings. +2. Search for `Python β€Ί Linting: Pylint Enabled` and ensure it is checked. + +--- + +## πŸ“œ Setting Up MarkdownLint + +MarkdownLint checks for style and consistency issues in Markdown files. + +### Install MarkdownLint + +1. Use npm to install MarkdownLint globally: + + ```bash + npm install -g markdownlint-cli + ``` + +### Run MarkdownLint + +- **From the command line**: + + ```bash + markdownlint yourfile.md + ``` + +- **In VS Code**: + MarkdownLint will automatically highlight issues in your `.md` files as you +edit them. + +--- + +## ▢️ Running the Tools + +### Run Ruff, Black, and Pylint for Python Files + +1. **Ruff**: + + ```bash + ruff path/to/your/code + ``` + +2. **Black**: + + ```bash + black path/to/your/code + ``` + +3. **Pylint**: + + ```bash + pylint path/to/your/code + ``` + +### Run MarkdownLint for Markdown Files + +1. **MarkdownLint**: + + ```bash + markdownlint path/to/your/file.md + ``` + +--- + +## πŸŽ‰ You're All Set + +You are now ready to use Ruff, Black, Pylint, and MarkdownLint in VS Code to +ensure your code and documentation are clean, consistent, and professional. +Happy coding! πŸš€ diff --git a/notes/cheetsheets.md b/notes/cheetsheets.md new file mode 100644 index 000000000..c8037157a --- /dev/null +++ b/notes/cheetsheets.md @@ -0,0 +1,9 @@ +# πŸ“ Cheat Sheets That We Can Use + +## πŸš€ These cheat sheets will cover Python and VS Code + +- πŸ”§ [**VS Code Cheat Sheet**](https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf) + β€” Boost your productivity with essential shortcuts. πŸš€ + +- 🐍 [**Python Cheat Sheet**](https://kieranholland.com/best-python-cheat-sheet/) + β€” Quickly reference key Python concepts and syntax. ✏️ diff --git a/notes/creating_linking_issue.md b/notes/creating_linking_issue.md new file mode 100644 index 000000000..b8ffcc4e7 --- /dev/null +++ b/notes/creating_linking_issue.md @@ -0,0 +1,34 @@ +# πŸš€ How to create and link an issue to a pull request + +## πŸ“ How to Create an Issue + +1. Go to the **Issues** tab. πŸ› +2. Click on **New Issue** βž•. +3. Fill out the issue template with all relevant details. πŸ“‹ +4. Assign labels 🏷️ and add it to the project board πŸ“Œ. + +--- + +## πŸ”— Linking an Issue to a Pull Request + +1. Create a branch for your changes. 🌱 +2. Make the necessary edits. ✏️ +3. Open a Pull Request (PR) πŸ› οΈ: + - Use `Fixes #` in the description to close the issue automatically + on merge. βœ… + - For example: + + ```markdown + Fixes #123 + ``` + +--- + +### Link the issue manually if needed + +- Go to the **Linked Issues** section in the PR. +- Search for the issue and add it. πŸ”— + +## πŸ“£ Need Help? + +If you're stuck, don't hesitate to reach out! πŸ†˜ From 547187f3c1e6213494cb0bf92b7b5d717701d925 Mon Sep 17 00:00:00 2001 From: Falaq Abdulmajeed Date: Wed, 8 Jan 2025 16:45:06 +0300 Subject: [PATCH 075/116] fix format error --- notes/{Extensions.md => extenstions.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename notes/{Extensions.md => extenstions.md} (100%) diff --git a/notes/Extensions.md b/notes/extenstions.md similarity index 100% rename from notes/Extensions.md rename to notes/extenstions.md From 37b2e753edc64d63943790d3519e8220c11c6a5b Mon Sep 17 00:00:00 2001 From: TagwaHashim Date: Wed, 8 Jan 2025 22:52:06 +0200 Subject: [PATCH 076/116] try to fix py formatting error --- solutions/tests/test_max_in.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/solutions/tests/test_max_in.py b/solutions/tests/test_max_in.py index 5b297401e..aacd1096f 100644 --- a/solutions/tests/test_max_in.py +++ b/solutions/tests/test_max_in.py @@ -13,10 +13,10 @@ import unittest -from solutions.max_in import max_in +from ..max_in import max_in -class TestMax_in(unittest.TestCase): +class TestMaxIn(unittest.TestCase): """Test the max_in function""" def test_positive_integers(self): @@ -33,23 +33,23 @@ def test_mix_types(self): self.assertEqual(max_in([1, -5.5, -3]), 1) def test_empty_list(self): - """""" + """It should raise AssertionError for empty list.""" with self.assertRaises(ValueError): self.assertEqual(max_in([]), "List cannot be empty.") def test_single_element_list(self): - """""" + """It should return the single element.""" self.assertEqual(max_in([5]), 5) def test_non_list_input(self): - """""" + """It should raise AssertionError for non list input.""" with self.assertRaises(ValueError): self.assertEqual(max_in("not a list"), "Input must be a list.") - def test_list_with_non_numeric_element(self): - """""" + def test_non_numeric_list(self): + """It should raise AssertionError for non-numeric list elements.""" with self.assertRaises(TypeError): self.assertEqual( From 70b049e8e322884300b1c3fe4306b9124220b010 Mon Sep 17 00:00:00 2001 From: TagwaHashim Date: Wed, 8 Jan 2025 23:21:22 +0200 Subject: [PATCH 077/116] formatting --- solutions/tests/test_max_in.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/solutions/tests/test_max_in.py b/solutions/tests/test_max_in.py index aacd1096f..7f0229688 100644 --- a/solutions/tests/test_max_in.py +++ b/solutions/tests/test_max_in.py @@ -4,14 +4,13 @@ Module: test_max_in Description: - This module contains unit tests for the 'max_in' function defined + This module contains unit tests for the 'max_in' function defined in the 'max_in.py' module. Author: Tagwa Hashim """ - import unittest from ..max_in import max_in @@ -35,7 +34,6 @@ def test_mix_types(self): def test_empty_list(self): """It should raise AssertionError for empty list.""" with self.assertRaises(ValueError): - self.assertEqual(max_in([]), "List cannot be empty.") def test_single_element_list(self): @@ -45,13 +43,11 @@ def test_single_element_list(self): def test_non_list_input(self): """It should raise AssertionError for non list input.""" with self.assertRaises(ValueError): - self.assertEqual(max_in("not a list"), "Input must be a list.") def test_non_numeric_list(self): """It should raise AssertionError for non-numeric list elements.""" with self.assertRaises(TypeError): - self.assertEqual( max_in([1, 2, "three"]), "List contains non-numeric elements." ) From ecd0b07b3ff34cac74110c2ac5b904810561a1f8 Mon Sep 17 00:00:00 2001 From: raghad598 Date: Thu, 9 Jan 2025 10:50:03 +0200 Subject: [PATCH 078/116] 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 079/116] 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 080/116] 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 c4970e5dd44c0c1035f991084c4055275e35337b Mon Sep 17 00:00:00 2001 From: Moealfadil <142026026+Moealfadil@users.noreply.github.com> Date: Thu, 9 Jan 2025 19:57:13 +0200 Subject: [PATCH 081/116] fixed py_format From 4f6f9f0deb30d229fcd4a022015ecc7ea3ac1bda Mon Sep 17 00:00:00 2001 From: Moealfadil <142026026+Moealfadil@users.noreply.github.com> Date: Thu, 9 Jan 2025 20:05:58 +0200 Subject: [PATCH 082/116] Revert "Merge branch 'main' into crafting_retrospective" This reverts commit 04aa0b86013ee0f076c8a622611d0d3e00c2bad5, reversing changes made to 550d65a3bfd1a35e6eda9a7fa58a32b1866f8e55. --- .github/PULL_REQUEST_TEMPLATE.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index eba8a7be2..eb18b4638 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -54,7 +54,6 @@ about: A template PR for code review with a checklist - [ ] The function's name describes it's behavior - [ ] The function's name matches the file name - - _It's ok to have extra helper functions if necessary, like with mergesort_ - [ ] The function has correct type annotations - [ ] The function is not called at the top level of the function file - _Recursive solutions **can** call the function from **inside** the function body_ @@ -69,7 +68,7 @@ about: A template PR for code review with a checklist ### Don'ts -- [ ] The function's strategy _is not_ described in any docstrings or tests +- [ ] The function's strategy _is not_ described in the documentation - [ ] Comments explain the _strategy_, **not** the _implementation_ - [ ] The function _does not_ have more comments than code - If it does, consider finding a new strategy or a simpler implementation From a7106a5622de92087f270643d8e3caf1a7388b42 Mon Sep 17 00:00:00 2001 From: Muna Sattouf Date: Thu, 9 Jan 2025 21:13:51 +0200 Subject: [PATCH 083/116] 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 084/116] 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 085/116] 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 1a878b9bf49e03b2dba9d1f76304954fe9b5853f Mon Sep 17 00:00:00 2001 From: Falaq Abdulmajeed Date: Thu, 9 Jan 2025 23:32:38 +0300 Subject: [PATCH 086/116] fix format --- solutions/cumulative_sum.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/cumulative_sum.py b/solutions/cumulative_sum.py index 2e77fb9d0..eb6d37207 100644 --- a/solutions/cumulative_sum.py +++ b/solutions/cumulative_sum.py @@ -13,7 +13,7 @@ - cumulative_sum(numbers: list) -> list: Computes and returns a list of cumulative sums from the input list. -Author: Falaq Youniss +Author: Falaq Youniss. Date: 29/12/2024 """ From 08729717047b1d385b13a932495a28e2428ad925 Mon Sep 17 00:00:00 2001 From: raghad598 Date: Fri, 10 Jan 2025 11:14:55 +0200 Subject: [PATCH 087/116] 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 088/116] 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 089/116] 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 090/116] 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 091/116] 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 092/116] 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 093/116] 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 094/116] 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 095/116] 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 f367fe17018b336cfa1e7555be5f36e2eaa0741d Mon Sep 17 00:00:00 2001 From: Moealfadil <142026026+Moealfadil@users.noreply.github.com> Date: Fri, 10 Jan 2025 16:45:21 +0200 Subject: [PATCH 096/116] ruff format --- solutions/cumulative_sum.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 From 922b056c722212b0a16963d6e94f911cd35ef14f Mon Sep 17 00:00:00 2001 From: raghad598 Date: Fri, 10 Jan 2025 21:55:15 +0200 Subject: [PATCH 097/116] 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 098/116] 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 099/116] 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 100/116] 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 101/116] 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 102/116] 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 103/116] 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 104/116] 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 105/116] 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 106/116] 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 107/116] 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 108/116] 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 109/116] 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 110/116] 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 111/116] 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 112/116] 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 113/116] 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 114/116] 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 115/116] 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 116/116] 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)