From 4da5808fe82251dbfa6493af482273ad8f67c5d2 Mon Sep 17 00:00:00 2001 From: Frank2446-dotcom Date: Tue, 7 Jan 2025 22:01:48 +0300 Subject: [PATCH 01/38] Updated test_dummy and fixed Pylint warnings for Anagram-Finder tests --- .vscode/settings.json | 3 +- solutions/README.md | 18 +++++++ solutions/anagram_finder.py | 34 ++++++++++++++ solutions/tests/README.md | 14 ++++++ solutions/tests/test_anagram_finder.py | 65 ++++++++++++++++++++++++++ 5 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 solutions/anagram_finder.py create mode 100644 solutions/tests/test_anagram_finder.py diff --git a/.vscode/settings.json b/.vscode/settings.json index 252022b48..ee54a0333 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -122,5 +122,6 @@ "source.fixAll.ruff": "explicit", "source.organizeImports.ruff": "explicit" } - } + }, + "cSpell.words": ["dcbae"] } diff --git a/solutions/README.md b/solutions/README.md index 9852346d2..de3dc3ca8 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -1 +1,19 @@ # Solutions + +# Solutions Folder + +This folder contains implementations for various challenges. + +## Challenges + +1. **Merge Dictionaries**: + - A utility to merge two dictionaries with conflict resolution. + - See `merge_dictionaries.py` for the implementation. + +2. **Anagram Finder**: + - A function to check if two strings are anagrams. + - See `anagram_finder.py` for the implementation. + +## Usage + +To use any solution, simply import the required function and pass the appropriate arguments. diff --git a/solutions/anagram_finder.py b/solutions/anagram_finder.py new file mode 100644 index 000000000..aea200903 --- /dev/null +++ b/solutions/anagram_finder.py @@ -0,0 +1,34 @@ +""" +Anagram Finder +This script provides a function to determine if two strings are anagrams. +""" + + +def is_anagram(string1: str, string2: str) -> bool: + """ + Check if two strings are anagrams of each other. + + Args: + string1 (str): The first string. + string2 (str): The second string. + + Returns: + bool: True if the strings are anagrams, False otherwise. + """ + # Normalize strings: convert to lowercase and remove spaces + string1 = "".join(string1.lower().split()) + string2 = "".join(string2.lower().split()) + + # Compare sorted characters + return sorted(string1) == sorted(string2) + + +if __name__ == "__main__": + # Example usage + word1 = "listen" + word2 = "silent" + print(f"Are '{word1}' and '{word2}' anagrams? {is_anagram(word1, word2)}") + + word3 = "hello" + word4 = "world" + print(f"Are '{word3}' and '{word4}' anagrams? {is_anagram(word3, word4)}") diff --git a/solutions/tests/README.md b/solutions/tests/README.md index 007eb9551..9d35c0abf 100644 --- a/solutions/tests/README.md +++ b/solutions/tests/README.md @@ -1 +1,15 @@ # Tests + +This folder contains unit tests for the challenges in the `solutions` module. + +## Test Files + +- `test_merge_dictionaries.py`: Tests for the Merge Dictionaries challenge. +- `test_anagram_finder.py`: Tests for the Anagram Finder challenge. + +## Running Tests + +Run the following command to execute all tests: + +```bash +python -m unittest discover -s solutions/tests -p "test_*.py" diff --git a/solutions/tests/test_anagram_finder.py b/solutions/tests/test_anagram_finder.py new file mode 100644 index 000000000..bc47c39c9 --- /dev/null +++ b/solutions/tests/test_anagram_finder.py @@ -0,0 +1,65 @@ +import unittest + +from solutions.anagram_finder import is_anagram + + +class TestAnagramFinder(unittest.TestCase): + """Test cases for the is_anagram function.""" + + def test_anagrams(self): + """Test cases for valid anagrams.""" + self.assertTrue(is_anagram("listen", "silent")) + self.assertTrue(is_anagram("evil", "vile")) + self.assertTrue(is_anagram("dusty", "study")) + self.assertTrue(is_anagram("night", "thing")) + self.assertTrue(is_anagram("brag", "grab")) + + def test_not_anagrams(self): + """Test cases for invalid anagrams.""" + self.assertFalse(is_anagram("hello", "world")) + self.assertFalse(is_anagram("python", "java")) + self.assertFalse(is_anagram("test", "tess")) + self.assertFalse(is_anagram("abcd", "dcbae")) + + def test_case_insensitivity(self): + """Test that the function is case-insensitive.""" + self.assertTrue(is_anagram("Listen", "Silent")) + self.assertTrue(is_anagram("Evil", "Vile")) + + def test_different_lengths(self): + """Test cases where the strings have different lengths.""" + self.assertFalse(is_anagram("abc", "ab")) + self.assertFalse(is_anagram("abcd", "abcde")) + + def test_empty_strings(self): + """Test edge cases with empty strings.""" + self.assertTrue(is_anagram("", "")) + self.assertFalse(is_anagram("a", "")) + self.assertFalse(is_anagram("", "a")) + + def test_special_characters(self): + """Test cases with special characters and spaces.""" + self.assertTrue(is_anagram("a gentleman", "elegant man")) + self.assertTrue(is_anagram("clint eastwood", "old west action")) + self.assertFalse(is_anagram("hello world", "world hello!")) + + def test_dummy(self): + """Dummy test to ensure the test suite runs without errors.""" + self.assertEqual(1, 1) # Trivial assertion to satisfy the test framework + + +if __name__ == "__main__": + # Run the tests and capture results + result = unittest.TextTestRunner().run( + unittest.TestLoader().loadTestsFromTestCase(TestAnagramFinder) + ) + + # Print the results summary with "Failed: 0" + print("\nTest Summary:") + print(f"Tests Run: {result.testsRun}") + print(f"Failed: {len(result.failures)}") + print(f"Errors: {len(result.errors)}") + if result.wasSuccessful(): + print("All tests passed!") + else: + print("Some tests failed.") From 8bfcdb551f794acae1c010374d4be39bce7c9a98 Mon Sep 17 00:00:00 2001 From: Frank2446-dotcom Date: Tue, 7 Jan 2025 22:12:08 +0300 Subject: [PATCH 02/38] Updated test_dummy and fixed Pylint warnings for Anagram-Finder tests --- solutions/README.md | 5 ++--- solutions/tests/README.md | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/solutions/README.md b/solutions/README.md index de3dc3ca8..e284e81c3 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -1,7 +1,5 @@ # Solutions -# Solutions Folder - This folder contains implementations for various challenges. ## Challenges @@ -16,4 +14,5 @@ This folder contains implementations for various challenges. ## Usage -To use any solution, simply import the required function and pass the appropriate arguments. +To use any solution, simply import the required function +and pass the appropriate arguments. diff --git a/solutions/tests/README.md b/solutions/tests/README.md index 9d35c0abf..bc8f69715 100644 --- a/solutions/tests/README.md +++ b/solutions/tests/README.md @@ -7,7 +7,7 @@ This folder contains unit tests for the challenges in the `solutions` module. - `test_merge_dictionaries.py`: Tests for the Merge Dictionaries challenge. - `test_anagram_finder.py`: Tests for the Anagram Finder challenge. -## Running Tests +### Running Tests Run the following command to execute all tests: From 29e7a74e36b654590c8694679ea512dc672e482a Mon Sep 17 00:00:00 2001 From: Frank2446-dotcom Date: Sun, 12 Jan 2025 01:19:46 +0300 Subject: [PATCH 03/38] Complete Anagram Finder implementation with tests and docstrings --- .vscode/settings.json | 2 +- solutions/anagram_finder.py | 60 ++++++++++++++++++++------ solutions/tests/test_anagram_finder.py | 55 ++++++++++++++--------- 3 files changed, 81 insertions(+), 36 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index ee54a0333..edeb92fde 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -123,5 +123,5 @@ "source.organizeImports.ruff": "explicit" } }, - "cSpell.words": ["dcbae"] + "cSpell.words": ["dcbae", "doctests"] } diff --git a/solutions/anagram_finder.py b/solutions/anagram_finder.py index aea200903..defcd8f93 100644 --- a/solutions/anagram_finder.py +++ b/solutions/anagram_finder.py @@ -1,34 +1,66 @@ """ -Anagram Finder -This script provides a function to determine if two strings are anagrams. +Anagram Finder Module + +This module provides a function to determine if two strings are anagrams of each other. +It checks if the strings are anagrams, handling edge cases like empty strings, special characters, and case-insensitivity. + +Created on 03 01 2025 +@author: Frankline Ambetsa """ +import doctest + def is_anagram(string1: str, string2: str) -> bool: """ Check if two strings are anagrams of each other. + Anagrams are words or phrases made by rearranging the letters of another word or phrase. + This function will check for anagram status while ignoring spaces and case sensitivity. + Args: string1 (str): The first string. string2 (str): The second string. Returns: bool: True if the strings are anagrams, False otherwise. + + Raises: + ValueError: If any string is empty except when both are empty. + + >>> is_anagram("listen", "silent") + True + >>> is_anagram("evil", "vile") + True + >>> is_anagram("hello", "world") + False + >>> is_anagram("a gentleman", "elegant man") + True + >>> is_anagram("clint eastwood", "old west action") + True """ - # Normalize strings: convert to lowercase and remove spaces - string1 = "".join(string1.lower().split()) - string2 = "".join(string2.lower().split()) - # Compare sorted characters + # Defensive assertions for valid string inputs + assert isinstance(string1, str), "string1 must be a string" + assert isinstance(string2, str), "string2 must be a string" + + # If any string is empty, raise an error, unless both are empty + if string1 == "" and string2 == "": + return True # Both empty strings are considered anagrams of each other + + if string1 == "": + raise AssertionError("string1 cannot be empty") + if string2 == "": + raise AssertionError("string2 cannot be empty") + + # Remove spaces and convert to lowercase + string1 = string1.replace(" ", "").lower() + string2 = string2.replace(" ", "").lower() + + # Check if sorted strings are equal (anagram check) return sorted(string1) == sorted(string2) +# Run doctests when executed directly if __name__ == "__main__": - # Example usage - word1 = "listen" - word2 = "silent" - print(f"Are '{word1}' and '{word2}' anagrams? {is_anagram(word1, word2)}") - - word3 = "hello" - word4 = "world" - print(f"Are '{word3}' and '{word4}' anagrams? {is_anagram(word3, word4)}") + doctest.testmod() diff --git a/solutions/tests/test_anagram_finder.py b/solutions/tests/test_anagram_finder.py index bc47c39c9..99a0c8e90 100644 --- a/solutions/tests/test_anagram_finder.py +++ b/solutions/tests/test_anagram_finder.py @@ -1,5 +1,14 @@ -import unittest +""" +Unit tests for the `is_anagram` function. + +These tests ensure correct behavior of the `is_anagram` function, +including standard anagram checking, edge cases, input validation, and defensive assertions. + +Created on 03 01 2025 +@author: Frankline Ambetsa +""" +import unittest from solutions.anagram_finder import is_anagram @@ -33,9 +42,17 @@ def test_different_lengths(self): def test_empty_strings(self): """Test edge cases with empty strings.""" - self.assertTrue(is_anagram("", "")) - self.assertFalse(is_anagram("a", "")) - self.assertFalse(is_anagram("", "a")) + self.assertTrue( + is_anagram("", "") + ) # Both empty strings should be considered anagrams + with self.assertRaises(AssertionError): + is_anagram( + "a", "" + ) # A non-empty string and empty string shouldn't be anagrams + with self.assertRaises(AssertionError): + is_anagram( + "", "b" + ) # An empty string and non-empty string shouldn't be anagrams def test_special_characters(self): """Test cases with special characters and spaces.""" @@ -43,23 +60,19 @@ def test_special_characters(self): self.assertTrue(is_anagram("clint eastwood", "old west action")) self.assertFalse(is_anagram("hello world", "world hello!")) - def test_dummy(self): - """Dummy test to ensure the test suite runs without errors.""" - self.assertEqual(1, 1) # Trivial assertion to satisfy the test framework + def test_defensive_assertions(self): + """Test defensive assertions for invalid inputs.""" + with self.assertRaises(AssertionError): + is_anagram(123, "silent") # Non-string input + with self.assertRaises(AssertionError): + is_anagram("listen", 123) # Non-string input + with self.assertRaises(AssertionError): + is_anagram("a", "") # Empty string as second argument + with self.assertRaises(AssertionError): + is_anagram("", "b") # Empty string as first argument -if __name__ == "__main__": - # Run the tests and capture results - result = unittest.TextTestRunner().run( - unittest.TestLoader().loadTestsFromTestCase(TestAnagramFinder) - ) - # Print the results summary with "Failed: 0" - print("\nTest Summary:") - print(f"Tests Run: {result.testsRun}") - print(f"Failed: {len(result.failures)}") - print(f"Errors: {len(result.errors)}") - if result.wasSuccessful(): - print("All tests passed!") - else: - print("Some tests failed.") +if __name__ == "__main__": + # Run the tests + unittest.main() From a61371f9ebbe4dd03ad0b1c7564b40bef11ebd77 Mon Sep 17 00:00:00 2001 From: Frank2446-dotcom Date: Sun, 12 Jan 2025 01:23:56 +0300 Subject: [PATCH 04/38] Complete Anagram Finder implementation with tests and docstrings --- solutions/tests/test_anagram_finder.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/solutions/tests/test_anagram_finder.py b/solutions/tests/test_anagram_finder.py index 99a0c8e90..b996163eb 100644 --- a/solutions/tests/test_anagram_finder.py +++ b/solutions/tests/test_anagram_finder.py @@ -1,13 +1,3 @@ -""" -Unit tests for the `is_anagram` function. - -These tests ensure correct behavior of the `is_anagram` function, -including standard anagram checking, edge cases, input validation, and defensive assertions. - -Created on 03 01 2025 -@author: Frankline Ambetsa -""" - import unittest from solutions.anagram_finder import is_anagram From 2a7afa25310f253ba6c06360cf6270e6a559a80a Mon Sep 17 00:00:00 2001 From: Frank2446-dotcom Date: Sun, 12 Jan 2025 01:29:53 +0300 Subject: [PATCH 05/38] Complete Anagram Finder implementation with tests and docstrings --- solutions/tests/test_anagram_finder.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/solutions/tests/test_anagram_finder.py b/solutions/tests/test_anagram_finder.py index b996163eb..e00d3e773 100644 --- a/solutions/tests/test_anagram_finder.py +++ b/solutions/tests/test_anagram_finder.py @@ -1,4 +1,6 @@ +# Import statements must be at the top of the file import unittest + from solutions.anagram_finder import is_anagram From 6815cdccd7cdcbb9509d7d4e3869cbf61f480597 Mon Sep 17 00:00:00 2001 From: Frank2446-dotcom Date: Sun, 12 Jan 2025 03:21:06 +0300 Subject: [PATCH 06/38] Complete Anagram Finder implementation with tests and docstrings --- solutions/anagram_finder.py | 18 ++++---- solutions/tests/test_anagram_finder.py | 62 +++++++++++++++----------- 2 files changed, 43 insertions(+), 37 deletions(-) diff --git a/solutions/anagram_finder.py b/solutions/anagram_finder.py index defcd8f93..753c6a43d 100644 --- a/solutions/anagram_finder.py +++ b/solutions/anagram_finder.py @@ -8,10 +8,8 @@ @author: Frankline Ambetsa """ -import doctest - -def is_anagram(string1: str, string2: str) -> bool: +def anagram_finder(string1: str, string2: str) -> bool: """ Check if two strings are anagrams of each other. @@ -28,15 +26,15 @@ def is_anagram(string1: str, string2: str) -> bool: Raises: ValueError: If any string is empty except when both are empty. - >>> is_anagram("listen", "silent") + >>> anagram_finder("listen", "silent") True - >>> is_anagram("evil", "vile") + >>> anagram_finder("evil", "vile") True - >>> is_anagram("hello", "world") + >>> anagram_finder("hello", "world") False - >>> is_anagram("a gentleman", "elegant man") + >>> anagram_finder("a gentleman", "elegant man") True - >>> is_anagram("clint eastwood", "old west action") + >>> anagram_finder("clint eastwood", "old west action") True """ @@ -61,6 +59,6 @@ def is_anagram(string1: str, string2: str) -> bool: return sorted(string1) == sorted(string2) -# Run doctests when executed directly +# No doctest or function call here. if __name__ == "__main__": - doctest.testmod() + pass diff --git a/solutions/tests/test_anagram_finder.py b/solutions/tests/test_anagram_finder.py index e00d3e773..fe04ce5cf 100644 --- a/solutions/tests/test_anagram_finder.py +++ b/solutions/tests/test_anagram_finder.py @@ -1,68 +1,76 @@ -# Import statements must be at the top of the file -import unittest +""" +Unit tests for the `anagram_finder` function. + +These tests ensure correct behavior of the `anagram_finder` function, +including standard merging, conflict resolution, edge cases, and input validation. -from solutions.anagram_finder import is_anagram +Created on 03 01 2025 +@author: Frankline Ambetsa +""" + +import unittest +from solutions.anagram_finder import anagram_finder class TestAnagramFinder(unittest.TestCase): - """Test cases for the is_anagram function.""" + """Test cases for the anagram_finder function.""" def test_anagrams(self): """Test cases for valid anagrams.""" - self.assertTrue(is_anagram("listen", "silent")) - self.assertTrue(is_anagram("evil", "vile")) - self.assertTrue(is_anagram("dusty", "study")) - self.assertTrue(is_anagram("night", "thing")) - self.assertTrue(is_anagram("brag", "grab")) + self.assertTrue(anagram_finder("listen", "silent")) + self.assertTrue(anagram_finder("evil", "vile")) + self.assertTrue(anagram_finder("dusty", "study")) + self.assertTrue(anagram_finder("night", "thing")) + self.assertTrue(anagram_finder("brag", "grab")) def test_not_anagrams(self): """Test cases for invalid anagrams.""" - self.assertFalse(is_anagram("hello", "world")) - self.assertFalse(is_anagram("python", "java")) - self.assertFalse(is_anagram("test", "tess")) - self.assertFalse(is_anagram("abcd", "dcbae")) + self.assertFalse(anagram_finder("hello", "world")) + self.assertFalse(anagram_finder("python", "java")) + self.assertFalse(anagram_finder("test", "tess")) + self.assertFalse(anagram_finder("abcd", "dcbae")) def test_case_insensitivity(self): """Test that the function is case-insensitive.""" - self.assertTrue(is_anagram("Listen", "Silent")) - self.assertTrue(is_anagram("Evil", "Vile")) + self.assertTrue(anagram_finder("Listen", "Silent")) + self.assertTrue(anagram_finder("Evil", "Vile")) def test_different_lengths(self): """Test cases where the strings have different lengths.""" - self.assertFalse(is_anagram("abc", "ab")) - self.assertFalse(is_anagram("abcd", "abcde")) + self.assertFalse(anagram_finder("abc", "ab")) + self.assertFalse(anagram_finder("abcd", "abcde")) def test_empty_strings(self): """Test edge cases with empty strings.""" self.assertTrue( - is_anagram("", "") + anagram_finder("", "") ) # Both empty strings should be considered anagrams with self.assertRaises(AssertionError): - is_anagram( + anagram_finder( "a", "" ) # A non-empty string and empty string shouldn't be anagrams with self.assertRaises(AssertionError): - is_anagram( + anagram_finder( "", "b" ) # An empty string and non-empty string shouldn't be anagrams def test_special_characters(self): """Test cases with special characters and spaces.""" - self.assertTrue(is_anagram("a gentleman", "elegant man")) - self.assertTrue(is_anagram("clint eastwood", "old west action")) - self.assertFalse(is_anagram("hello world", "world hello!")) + self.assertTrue(anagram_finder("a gentleman", "elegant man")) + self.assertTrue(anagram_finder("clint eastwood", "old west action")) + self.assertFalse(anagram_finder("hello world", "world hello!")) def test_defensive_assertions(self): """Test defensive assertions for invalid inputs.""" with self.assertRaises(AssertionError): - is_anagram(123, "silent") # Non-string input + anagram_finder(123, "silent") # Non-string input with self.assertRaises(AssertionError): - is_anagram("listen", 123) # Non-string input + anagram_finder("listen", 123) # Non-string input with self.assertRaises(AssertionError): - is_anagram("a", "") # Empty string as second argument + anagram_finder("a", "") # Empty string as second argument with self.assertRaises(AssertionError): - is_anagram("", "b") # Empty string as first argument + anagram_finder("", "b") # Empty string as first argument if __name__ == "__main__": From 56e58cc349f806bea9d3ccc9ccf79f50b19eb565 Mon Sep 17 00:00:00 2001 From: Frank2446-dotcom Date: Sun, 12 Jan 2025 03:52:29 +0300 Subject: [PATCH 07/38] Complete Anagram Finder implementation with tests and docstrings --- solutions/anagram_finder.py | 1 - 1 file changed, 1 deletion(-) diff --git a/solutions/anagram_finder.py b/solutions/anagram_finder.py index 753c6a43d..18a9d1f06 100644 --- a/solutions/anagram_finder.py +++ b/solutions/anagram_finder.py @@ -59,6 +59,5 @@ def anagram_finder(string1: str, string2: str) -> bool: return sorted(string1) == sorted(string2) -# No doctest or function call here. if __name__ == "__main__": pass From bbbd71100da3b5ce0dafeb1c9874c3f086752ef9 Mon Sep 17 00:00:00 2001 From: Frank2446-dotcom Date: Sun, 12 Jan 2025 11:44:41 +0300 Subject: [PATCH 08/38] Added anagram finder files --- solutions/anagram_finder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solutions/anagram_finder.py b/solutions/anagram_finder.py index 18a9d1f06..61b09afeb 100644 --- a/solutions/anagram_finder.py +++ b/solutions/anagram_finder.py @@ -4,7 +4,7 @@ This module provides a function to determine if two strings are anagrams of each other. It checks if the strings are anagrams, handling edge cases like empty strings, special characters, and case-insensitivity. -Created on 03 01 2025 +Created on 12 01 2025 @author: Frankline Ambetsa """ @@ -51,7 +51,7 @@ def anagram_finder(string1: str, string2: str) -> bool: if string2 == "": raise AssertionError("string2 cannot be empty") - # Remove spaces and convert to lowercase + # To Remove spaces and convert to lowercase string1 = string1.replace(" ", "").lower() string2 = string2.replace(" ", "").lower() From 0f321a8d16f54d0e99dcda133abb430ec7dc3b78 Mon Sep 17 00:00:00 2001 From: Frank2446-dotcom Date: Sun, 12 Jan 2025 12:53:42 +0300 Subject: [PATCH 09/38] Added anagram finder files --- solutions/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/README.md b/solutions/README.md index e284e81c3..f74705563 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -1,6 +1,6 @@ # Solutions -This folder contains implementations for various challenges. +This folder contains implementations for the challenges. ## Challenges From 3fd6e394bf525b366712e8a65b5cce0bdf4d166f Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:32:56 +0300 Subject: [PATCH 10/38] Delete solutions/Remove_Duplicates.py --- solutions/Remove_Duplicates.py | 50 ---------------------------------- 1 file changed, 50 deletions(-) delete mode 100644 solutions/Remove_Duplicates.py diff --git a/solutions/Remove_Duplicates.py b/solutions/Remove_Duplicates.py deleted file mode 100644 index 16c1562d9..000000000 --- a/solutions/Remove_Duplicates.py +++ /dev/null @@ -1,50 +0,0 @@ -""" -A module for removing duplicates from a list of numbers - -Module contents: - - Remove_Duplicates: Remove any duplicate numbers in the list - -Created on 2025-1-4 -@author: Safaa Osman -""" - - -def Remove_Duplicates(items: list) -> list: - """ - This Function Removes any duplicates elements from the list - - Arguments: list of elements - - Returns: list of elements without duplicates. - - Raises: - AssertionError: if the input is not a list - - - Examples: - >>> Remove_Duplicates(['a','b','a']) - ['a', 'b'] - - >>> Remove_Duplicates([1,1,2]) - [1, 2] - - >>> Remove_Duplicates([1,2,2,3,3,3]) - [1, 2, 3] - - >>> Remove_Duplicates([1]) - [1] - - >>> Remove_Duplicates([]) - [] - - >>> Remove_Duplicates([5,5,5,5,5,5,5]) - [5] - - """ - assert isinstance(items, list), "input must be a list" - - Final_list = [] - for item in items: - if item not in Final_list: - Final_list.append(item) - return Final_list From 596e83c564e8eda1308fe262cfd604790af72756 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:33:12 +0300 Subject: [PATCH 11/38] Delete solutions/Swap_letters.py --- solutions/Swap_letters.py | 39 --------------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 solutions/Swap_letters.py diff --git a/solutions/Swap_letters.py b/solutions/Swap_letters.py deleted file mode 100644 index 05a21bf18..000000000 --- a/solutions/Swap_letters.py +++ /dev/null @@ -1,39 +0,0 @@ -""" -Created on 08/01/2024 - -@author: Tibyan Khalid - -This file contains the function Swap_letters that swaps the case of each letter in a string. -""" - - -def Swap_letters(string: str) -> str: - """Swap_letters will return the string given with switched cases. - - Parameters: - String(str) "the word that will get modified" - - Returns: modified_string(str) "the string with swapped cases" - - >>> Swap_letters("hello") - 'HELLO' - - >>> Swap_letters("HELLO") - 'hello' - - >>> Swap_letters("HeLlO") - 'hElLo' - """ - if not isinstance(string, str): - "Make sure the expected input is a string" - raise AssertionError("Input must be a string") - - changed_string = "" - for char in string: - if char.islower(): - changed_string += char.upper() - elif char.isupper(): - changed_string += char.lower() - else: - changed_string += char - return changed_string From ee3ed850aa19492fbed1409fdd47ac569a9dc88a Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:33:21 +0300 Subject: [PATCH 12/38] Delete solutions/Time_Conversion.py --- solutions/Time_Conversion.py | 65 ------------------------------------ 1 file changed, 65 deletions(-) delete mode 100644 solutions/Time_Conversion.py diff --git a/solutions/Time_Conversion.py b/solutions/Time_Conversion.py deleted file mode 100644 index 524818bca..000000000 --- a/solutions/Time_Conversion.py +++ /dev/null @@ -1,65 +0,0 @@ -""" -A module for Converting time from Eastern Standard Time zone (EST) to Arabia -Standard Time (AST) - -Created on 2025-01-07 -Author: Safaa Osman -""" - - -def Time_Conversion(est_time: str) -> str: - """Returns a time in Arabia Standard Time zone (AST) - - Takes input time in the format HH:MM (24-hours format) and returns - the equavelent time in AST in the same format. - - Parameters: - EST_Time (str): time in EST in the format 24 hour - - Returns -> str: time in AST in the format 24 hour - - Raises: - TypeError: if the input is not a string - AssertionError: if the hours are not between the boundary of (0-23) - AssertionError: if the minutes are not between the boundary of (0-59) - AssertionError: if the input is empty string - - - Examples: - >>> Time_Conversion("14:30") - '22:30' - - >>> Time_Conversion("08:15") - '16:15' - - >>> Time_Conversion("00:00") - '08:00' - - - """ - assert est_time != "", "input should be a time in HH:MM format" - - assert isinstance(est_time, str), "The input must be string" - - # split the input to hours and minutes in integers - hours, minutes = est_time.split(":") - - # Assert hours and minutes are numbers - assert hours.isdigit(), "hours must be integers" - assert minutes.isdigit(), "minutes must be integers" - - hours = int(hours) - minutes = int(minutes) - - # Assert boundary - if not (0 <= hours <= 23): - raise ValueError("hours must be between 0 and 23") - if not (0 <= minutes <= 59): - raise ValueError("minutes must be between 0 and 59") - - hours += 8 - - if hours >= 24: - hours -= 24 - - return f"{str(hours).zfill(2)}:{str(minutes).zfill(2)}" From 5cf798609938b242f3a467c7bb4aa9c3185ae250 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:33:32 +0300 Subject: [PATCH 13/38] Delete solutions/calculate_square_area.py --- solutions/calculate_square_area.py | 44 ------------------------------ 1 file changed, 44 deletions(-) delete mode 100644 solutions/calculate_square_area.py diff --git a/solutions/calculate_square_area.py b/solutions/calculate_square_area.py deleted file mode 100644 index 2f30ef110..000000000 --- a/solutions/calculate_square_area.py +++ /dev/null @@ -1,44 +0,0 @@ -# !/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -A module for calculating the area of a square given the side_length - -Module contents: - calculate_square_area: calculates the area of a square - -Created on 04 01 2025 -@author: Kareiman Altayeb -""" - - -def calculate_square_area(side_length: float) -> float: - """The function asks the user to enter the side length of the square - and the function returns the area of the square. - - parameter: - side_length in integer or float - - raises: - AssertionError: if side_length was =< 0 - ValueError: if the value entered was or str or text - - returns: - side_length ** 2 - - >>> calculate_square_area(5) - 25 - - >>> calculate_square_area(12.30) - 151.91 - - >>> calculate_square_area(0.42) - 0.1764 - - """ - # The entry cannot be a text or letters, only numbers - assert isinstance(side_length, (int, float)), "input must be a number" - - if side_length <= 0: - raise AssertionError("side length must be bigger than zero") - - return side_length**2 From b1f5b2f5b5f12b8067b68120136c5e52da43ba93 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:33:43 +0300 Subject: [PATCH 14/38] Delete solutions/check_number_type.py --- solutions/check_number_type.py | 59 ---------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 solutions/check_number_type.py diff --git a/solutions/check_number_type.py b/solutions/check_number_type.py deleted file mode 100644 index 3fe4685dc..000000000 --- a/solutions/check_number_type.py +++ /dev/null @@ -1,59 +0,0 @@ -""" -This function asks the user to enter a number and checks if the number -is even or odd. It then returns the result as a string. - -Created on 05 01 2025 -@author: Eman Alfalouji. - -""" - - -def check_number_type(user_input: str) -> str: - """ - The function asks the user to enter a number and determines if it is type (even or odd.) - - - Parameters: - user_input (str): str - A string that represents an integer. - Floats or non-integer formats are not allowed. - Raises: - ValueError: If the input is empty. - ValueError: If the input is not a valid integer. - - Returns: - results will be a text whether "The number is even", "The number is odd" - or raises an appropriate error. - Examples : - >>> check_number_type("20") - "The number is even" - >>> check_number_type("11") - "The number is odd" - >>> check_number_type("-11") - "The number is odd" - >>> check_number_type("") - Traceback (most recent call last): - ... - ValueError:"Input cannot be empty. Enter a valid number." - >>> check_number_type("Eman") - Traceback (most recent call last): - ... - ValueError:"Please enter a valid number" - - - - - """ - user_input = user_input.strip() - # Check if it is empty - if not user_input: - raise ValueError("Input cannot be empty. Enter a valid number.") - # check if it is a number - if not user_input.lstrip("-").isdigit(): - raise ValueError("Please enter a valid number") - number = int(user_input) - # Check if the number is even or odd - if number % 2 == 0: - return "The number is even" - else: - return "The number is odd" From b8e7d651708733174b8623df1fecc008388b94d4 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:33:53 +0300 Subject: [PATCH 15/38] Delete solutions/convert_hours_to_minutes.py --- solutions/convert_hours_to_minutes.py | 47 --------------------------- 1 file changed, 47 deletions(-) delete mode 100644 solutions/convert_hours_to_minutes.py diff --git a/solutions/convert_hours_to_minutes.py b/solutions/convert_hours_to_minutes.py deleted file mode 100644 index 0aa0ff896..000000000 --- a/solutions/convert_hours_to_minutes.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -A module for converting hours to minutes. - -Module contents: - - convert_hours_to_minutes: calculates the time in minutes based on hours. - -Created on 31-12-2024 -@author: Azza Omer -""" - - -def convert_hours_to_minutes(hour_wasted: int) -> int: - """ - Convert hours to minutes. - - Parameters: - hour_wasted (int): The number of hours wasted. Must be a positive integer. - - Returns: - int: The equivalent time in minutes. - - Examples: - >>> convert_hours_to_minutes(1) - 60 - >>> convert_hours_to_minutes(5) - 300 - >>> convert_hours_to_minutes(12) - 720 - >>> convert_hours_to_minutes(0) - 0 - >>> convert_hours_to_minutes(3) - 180 - >>> convert_hours_to_minutes("2") # Raises AssertionError - Traceback (most recent call last): - ... - AssertionError: hour_wasted must be an integer. - >>> convert_hours_to_minutes(-5) # Raises AssertionError - Traceback (most recent call last): - ... - AssertionError: hour_wasted must be greater than or equal to 0. - """ - assert isinstance(hour_wasted, int), "hour_wasted must be an integer." - assert hour_wasted >= 0, "hour_wasted must be greater than or equal to 0." - minutes = hour_wasted * 60 - return minutes From ff41e7655cd2612e9dfd24449620d27b7036db4a Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:34:03 +0300 Subject: [PATCH 16/38] Delete solutions/convert_to_capital.py --- solutions/convert_to_capital.py | 39 --------------------------------- 1 file changed, 39 deletions(-) delete mode 100644 solutions/convert_to_capital.py diff --git a/solutions/convert_to_capital.py b/solutions/convert_to_capital.py deleted file mode 100644 index 197f516ed..000000000 --- a/solutions/convert_to_capital.py +++ /dev/null @@ -1,39 +0,0 @@ -# !/usr/bin/env python3 -# -*- coding: utf-8 -*- - -""" -A module that converts letters to uppercase - -Created on 31 12 2024 - -@author: Kareiman Altayeb -""" - - -def convert_to_capital(user_text: str) -> str: - """Asks the user to enter a text and returns the text in capital - - Parameters: - user_text (str): The user input text to be converted to uppercase. - - Returns: - str : user_text in capital letters - - Raises: - AssertionError: If the input is empty or contains only spaces. - - Examples: - >>> convert_to_capital('hello') - 'HELLO' - >>> convert_to_capital('HelLo') - 'HELLO' - >>> convert_to_capital('123hello') - '123HELLO' - """ - - user_text = user_text.strip() - - if not user_text: - raise AssertionError("Entry cannot be empty or just spaces") - - return user_text.upper() From 8d92e7111a10f95784fa243c153450efd0d98210 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:34:15 +0300 Subject: [PATCH 17/38] Delete solutions/convert_to_uppercase.py --- solutions/convert_to_uppercase.py | 40 ------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 solutions/convert_to_uppercase.py diff --git a/solutions/convert_to_uppercase.py b/solutions/convert_to_uppercase.py deleted file mode 100644 index cc462976c..000000000 --- a/solutions/convert_to_uppercase.py +++ /dev/null @@ -1,40 +0,0 @@ -# !/usr/bin/env python3 -# -*- coding: utf-8 -*- - -""" -A module that converts letters to uppercase - -Created on 31 12 2024 - -@author: Kareiman Altayeb -""" - - -def convert_to_uppercase(user_text: str) -> str: - """Asks the user to enter a text and returns the text in capital - with all characters in uppercase - - Parameters: - user_text (str): The user input text to be converted to uppercase. - - Returns: - str : user_text in upper case - - Raises: - AssertionError: If the input is empty or contains only spaces. - - Examples: - >>> convert_to_uppercase('hello') - 'HELLO' - >>> convert_to_uppercase('HelLo') - 'HELLO' - >>> convert_to_uppercase('123hello') - '123HELLO' - """ - - user_text = user_text.strip() - - if not user_text: - raise AssertionError("Entry cannot be empty or just spaces") - - return user_text.upper() From de406f7a656d7f47e982f54623be82c006441881 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:34:25 +0300 Subject: [PATCH 18/38] Delete solutions/is_palindrome.py --- solutions/is_palindrome.py | 42 -------------------------------------- 1 file changed, 42 deletions(-) delete mode 100644 solutions/is_palindrome.py diff --git a/solutions/is_palindrome.py b/solutions/is_palindrome.py deleted file mode 100644 index ab275c185..000000000 --- a/solutions/is_palindrome.py +++ /dev/null @@ -1,42 +0,0 @@ -""" -Created on 04/01/2025 - -@author: Tibyan Khalid -""" - - -def is_palindrome(string): - """is_palindrome fuction will return whether the entry given is a palindrome or not. - Palindrome: a word whose reverse is the same as the original word. - - Parameters: - string(str): the string to be checked. - - Returns: - string (str): "Palindrome" if the word is a palindrome, otherwise "Not Palindrome". - - Raises: - AssertionError: If the argument is not a string or if it's too long. - - >>> is_palindrome("RADAR") - 'Palindrome' - - >>> is_palindrome("radar") - 'Palindrome' - - >>> is_palindrome("Radar") - 'Not Palindrome' - - >>> is_palindrome("hello") - 'Not Palindrome' - """ - # Defensive assertions - assert isinstance(string, str), "Argument(Input) must be a string" - assert len(string) <= 100, ( - "Argument (Input) is too long, max allowed length is 100 characters" - ) - - if string == string[::-1]: - return "Palindrome" - else: - return "Not Palindrome" From 23ceae8323f624c67dba833cae822112bd7c7686 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:34:40 +0300 Subject: [PATCH 19/38] Delete solutions/sum_of_list.py --- solutions/sum_of_list.py | 42 ---------------------------------------- 1 file changed, 42 deletions(-) delete mode 100644 solutions/sum_of_list.py diff --git a/solutions/sum_of_list.py b/solutions/sum_of_list.py deleted file mode 100644 index 1e722050c..000000000 --- a/solutions/sum_of_list.py +++ /dev/null @@ -1,42 +0,0 @@ -""" -This function asks the user to enter numbers and return the sum of the numbers . - -Created on 05 01 2025 -@author: Eman Alfalouji. - -""" - -from typing import List, Union - - -def sum_of_list(numbers: List[Union[int, float]]) -> Union[int, float]: - """ - Calculate the sum of a list of numbers. - - Args: - numbers (list): A list of numbers (int or float). - - Returns: - int/float: The sum of the numbers in the list. - - Raises: - TypeError: If the input is not a list. - ValueError: If any element in the list is not an int or float. - - Examples : - >>> sum_of_list([1,2,5]) - The sum of the list is:8 - >>> sum_of_list([-1,-2,-5]) - The sum of the list is:-8 - >>> sum_of_list([-1,-2,"l"]) - Please enter valid numbers separated by spaces. - >>> sum_of_list(["l"]) - Please enter valid numbers separated by spaces. - >>> sum_of_list([]) - Please enter valid numbers separated by spaces. - """ - if not isinstance(numbers, list): - raise TypeError("Input must be a list of numbers.") - if not all(isinstance(num, (int, float)) for num in numbers): - raise ValueError("All elements in the list must be int or float.") - return sum(numbers) From 87cc3be0887d0c83d005d5225670a00015509534 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:34:50 +0300 Subject: [PATCH 20/38] Delete solutions/merge_dictionaries.py --- solutions/merge_dictionaries.py | 59 --------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 solutions/merge_dictionaries.py diff --git a/solutions/merge_dictionaries.py b/solutions/merge_dictionaries.py deleted file mode 100644 index 7b07cd3db..000000000 --- a/solutions/merge_dictionaries.py +++ /dev/null @@ -1,59 +0,0 @@ -""" -This module contains the implementation of the `merge_dictionaries` function. - -The `merge_dictionaries` function allows merging two dictionaries into one, -with support for resolving key conflicts through a custom resolution function. - -Created on 03 01 2025 -@author: Frankline Ambetsa -""" - - -def merge_dictionaries(dict1, dict2, conflict_resolution=None): - """ - Merge two dictionaries into one. - - If keys conflict, a conflict resolution function can be provided - to decide which value to keep. If no function is provided, the value - from `dict2` will overwrite the value from `dict1`. - - Parameters: - dict1 (dict): The first dictionary. - dict2 (dict): The second dictionary. - conflict_resolution (function, optional): A function that takes - two arguments (value1, value2) and returns the resolved value. - - Returns: - dict: A merged dictionary. - - Raises: - AssertionError: If `dict1` or `dict2` is not a dictionary. - AssertionError: If `conflict_resolution` is not callable when provided. - - Examples: - >>> merge_dictionaries({'a': 1}, {'a': 2, 'b': 3}) - {'a': 2, 'b': 3} - >>> merge_dictionaries({'a': 1}, {'a': 2, 'b': 3}, max) - {'a': 2, 'b': 3} - >>> merge_dictionaries({'x': 1}, {'y': 2}) - {'x': 1, 'y': 2} - """ - # Defensive assertions - assert isinstance(dict1, dict), "dict1 must be a dictionary." - assert isinstance(dict2, dict), "dict2 must be a dictionary." - if conflict_resolution is not None: - assert callable(conflict_resolution), ( - "conflict_resolution must be a callable function." - ) - - merged = dict1.copy() # Start with a copy of the first dictionary - - for key, value in dict2.items(): - if key in merged and conflict_resolution: - # Resolve conflict using the provided function - merged[key] = conflict_resolution(merged[key], value) - else: - # Add or overwrite key with dict2's value - merged[key] = value - - return merged From 07f01e1f6d29babd05503ba17500665b3a679f3b Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:35:01 +0300 Subject: [PATCH 21/38] Delete solutions/word_frequency.py --- solutions/word_frequency.py | 38 ------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 solutions/word_frequency.py diff --git a/solutions/word_frequency.py b/solutions/word_frequency.py deleted file mode 100644 index bb0f3e1fc..000000000 --- a/solutions/word_frequency.py +++ /dev/null @@ -1,38 +0,0 @@ -def count_word_frequency(text): - """ - Counts the frequency of each word in a given string. - - Args: - text (str): The input text to analyze. - - Returns: - dict: A dictionary where keys are words and values are their frequencies. - - Raises: - ValueError: If the input text is not a string. - - Examples: - >>> count_word_frequency("hello hello world") - {'hello': 2, 'world': 1} - - >>> count_word_frequency("apple banana apple") - {'apple': 2, 'banana': 1} - - >>> count_word_frequency("The quick brown fox jumps over the lazy dog") - {'the': 2, 'quick': 1, 'brown': 1, 'fox': 1, 'jumps': 1, 'over': 1, 'lazy': 1, 'dog': 1} - """ - if not isinstance(text, str): - raise ValueError("Input must be a string.") - - # Normalize case and split text into words - words = text.lower().split() - - # Remove punctuation from each word - cleaned_words = [word.strip('.,!?;:"()') for word in words] - - # Count word frequencies - word_counts = {} - for word in cleaned_words: - word_counts[word] = word_counts.get(word, 0) + 1 - - return word_counts From 430718904652da9b32fd9bf33f8a925002e81463 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:35:19 +0300 Subject: [PATCH 22/38] Delete solutions/largest_number.py --- solutions/largest_number.py | 62 ------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 solutions/largest_number.py diff --git a/solutions/largest_number.py b/solutions/largest_number.py deleted file mode 100644 index 2e45b6dc3..000000000 --- a/solutions/largest_number.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -A module for finding the largest number. - -Module contents: - - largest_number: Extracts the largest number from a list of integers. - -Created on 11-01-2025 -@author: Azza -""" - - -def largest_number(list_numbers: list) -> int: - """Extract the largest number from the given list of integers. - - Args: - list_numbers (list): A list of integers. - - Returns: - int: The largest number in the list. - - Raises: - TypeError: If the input is not a list or contains non-integer elements. - ValueError: If the input list is empty. - - Examples: - >>> largest_number([0, 1, 9, 2, 6, 4]) - 9 - >>> largest_number([12]) - 12 - >>> largest_number([8, -1, -8, 5]) - 8 - >>> largest_number([-9, -1, -6, -5]) - -1 - >>> largest_number([0, 0]) - 0 - >>> largest_number([]) # Raises ValueError - Traceback (most recent call last): - ... - ValueError: The list must not be empty. - >>> largest_number(["-5", 5, "0"]) # Raises TypeError - Traceback (most recent call last): - ... - TypeError: All elements in the list must be integers. - >>> largest_number(42) # Raises TypeError - Traceback (most recent call last): - ... - TypeError: The input must be a list. - >>> largest_number([2**32, 2**16, 2**8, 1]) - 4294967296 - """ - - # Ensure the input is a list of integers - if not isinstance(list_numbers, list): - raise TypeError("The input must be a list.") - if not list_numbers: - raise ValueError("The list must not be empty.") - if not all(isinstance(i, int) for i in list_numbers): - raise TypeError("All elements in the list must be integers.") - - return max(list_numbers) From 99b9c125ae8c0989baeabcb6bdf093a6b6d95249 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:35:45 +0300 Subject: [PATCH 23/38] Delete solutions/tests/test_Remove_Duplicate.py --- solutions/tests/test_Remove_Duplicate.py | 43 ------------------------ 1 file changed, 43 deletions(-) delete mode 100644 solutions/tests/test_Remove_Duplicate.py diff --git a/solutions/tests/test_Remove_Duplicate.py b/solutions/tests/test_Remove_Duplicate.py deleted file mode 100644 index e10ae1267..000000000 --- a/solutions/tests/test_Remove_Duplicate.py +++ /dev/null @@ -1,43 +0,0 @@ -""" -Test module for Remove Duplicate function. - -Created on 2024-01-10 -Author: Safaa Osman - -""" - -import unittest - -from ..Remove_Duplicates import Remove_Duplicates - - -class TestRemoveDuplicates(unittest.TestCase): - """Test the Remove_Duplicates function - some tests are buggy!""" - - def test_empty_list(self): - """It should return [] for an empty list""" - self.assertEqual(Remove_Duplicates([]), []) - - def test_no_duplicates(self): - """It should return the same list for list without duplicates""" - self.assertEqual(Remove_Duplicates([1, 2, 3]), [1, 2, 3]) - - def test_not_list(self): - """It should raise AssertionError for non-list input""" - with self.assertRaises(AssertionError): - Remove_Duplicates("123") - - def test_All_duplicates(self): - """It should return the list of one item that duplicates""" - self.assertEqual(Remove_Duplicates([1, 1, 1, 1, 1, 1]), [1]) - - def test_list_with_duplicates(self): - """It should return the list without duplicates""" - self.assertEqual(Remove_Duplicates([1, 1, 2, 2, 3, 4]), [1, 2, 3, 4]) - - def test_Mix_types_of_elements(self): - """It should return the list of elements without duplicates""" - self.assertEqual( - Remove_Duplicates([1, "Safaa", 3.5, "Safaa", "safaa", 3.5]), - [1, "Safaa", 3.5, "safaa"], - ) From d3d477c50c6568450118b143398eeded975109ff Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:36:07 +0300 Subject: [PATCH 24/38] Delete solutions/tests/test_Swap_letters.py --- solutions/tests/test_Swap_letters.py | 49 ---------------------------- 1 file changed, 49 deletions(-) delete mode 100644 solutions/tests/test_Swap_letters.py diff --git a/solutions/tests/test_Swap_letters.py b/solutions/tests/test_Swap_letters.py deleted file mode 100644 index f4cb40d90..000000000 --- a/solutions/tests/test_Swap_letters.py +++ /dev/null @@ -1,49 +0,0 @@ -""" -Created on 08/01/2024 - -@author: Tibyan Khalid - -This file contains boundary cases and defensive assertion tests for the function Swap_letters. -""" - -import unittest - -from ..Swap_letters import Swap_letters - - -class TestSwapLettersFunctionality(unittest.TestCase): - """Test cases for validating the behavior of the Swap_letters function, - including edge cases and defensive assertions.""" - - def test_lowercase_all(self): - "Testing from lowercase to uppercase" - self.assertEqual(Swap_letters("tibyan"), "TIBYAN") - - def test_uppercase_all(self): - "Testing from uppercase to lowercase" - self.assertEqual(Swap_letters("TIBYAN"), "tibyan") - - def test_mixed_cases(self): - "Testing mixed spaces" - self.assertEqual(Swap_letters("TiByAn"), "tIbYaN") - - def test_non_string_entry(self): - "Raise an error if entry is not a string" - with self.assertRaises(AssertionError): - Swap_letters(57) - - def test_spaces(self): - "Handle spaces correctly" - self.assertEqual(Swap_letters("Hello World"), "hELLO wORLD") - - def test_empty_string(self): - "Test for an empty string input" - self.assertEqual(Swap_letters(""), "") - - def test_special_characters(self): - "Test for special characters input" - self.assertEqual(Swap_letters("1234!@#$"), "1234!@#$") - - -if __name__ == "__main__": - unittest.main() From 3eb17099d04c3fafc22fbb46e2c25e26f6fbfca3 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:36:26 +0300 Subject: [PATCH 25/38] Delete solutions/tests/test_Time_Conversion.py --- solutions/tests/test_Time_Conversion.py | 69 ------------------------- 1 file changed, 69 deletions(-) delete mode 100644 solutions/tests/test_Time_Conversion.py diff --git a/solutions/tests/test_Time_Conversion.py b/solutions/tests/test_Time_Conversion.py deleted file mode 100644 index d8078193d..000000000 --- a/solutions/tests/test_Time_Conversion.py +++ /dev/null @@ -1,69 +0,0 @@ -""" -Test module for Time Conversion function. -Contains intentionally buggy tests for debugging practice. - -Created on 2024-01-09 -Author: Safaa Osman -""" - -import unittest -from ..Time_Conversion import Time_Conversion - - -class TestTimeConversion(unittest.TestCase): - """Test suite for the Time Conversion function""" - - def test_equal_minutes_hours(self): - """It should return the time conversion properly""" - self.assertEqual(Time_Conversion("12:12"), "20:12") - - def test_regular_time(self): - """It should return the time conversion properly""" - self.assertEqual(Time_Conversion("08:00"), "16:00") - - # Boundary cases - - def test_minimum_time(self): - """It should return the time conversion properly""" - self.assertEqual(Time_Conversion("00:00"), "08:00") - - def test_maximum_time(self): - """It should return the time conversion properly""" - self.assertEqual(Time_Conversion("23:59"), "07:59") - - # Defensive cases - - def test_not_string(self): - """It should raise AssertionError for input not string""" - with self.assertRaises(AssertionError): - Time_Conversion(1230) - - def test_hours_out_of_range(self): - """It should raise ValueError for hours are out of range""" - with self.assertRaises(ValueError): - Time_Conversion("25:30") - - def test_minutes_out_of_range(self): - """It should raise ValueError for minutes are out of range""" - with self.assertRaises(ValueError): - Time_Conversion("12:69") - - def test_empty_string(self): - """It should raise AssertionError for string is empty""" - with self.assertRaises(AssertionError): - Time_Conversion("") - - def test_mix_types(self): - """It should raise AssertionError for string is mix types""" - with self.assertRaises(AssertionError): - Time_Conversion("hg:45") - - def test_invalid_minutes(self): - """It should raise ValueError for minutes are out of range""" - with self.assertRaises(ValueError): - Time_Conversion("00:60") - - def test_invalid_hours(self): - """It should raise ValueError for minutes are out of range""" - with self.assertRaises(ValueError): - Time_Conversion("24:00") From 2891407fa27d0cddaf77d97e2ed3a6ffc59db809 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:36:37 +0300 Subject: [PATCH 26/38] Delete solutions/tests/test_calculate_square_area.py --- solutions/tests/test_calculate_square_area.py | 59 ------------------- 1 file changed, 59 deletions(-) delete mode 100644 solutions/tests/test_calculate_square_area.py diff --git a/solutions/tests/test_calculate_square_area.py b/solutions/tests/test_calculate_square_area.py deleted file mode 100644 index ebfbf5ee7..000000000 --- a/solutions/tests/test_calculate_square_area.py +++ /dev/null @@ -1,59 +0,0 @@ -# !/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Test module for square_area function. - -Test categories: -- Standard cases: positive numbers -- Edge cases: numbers that are positive but less than 1 -- Defensive cases: wrong input types, value that is zero, and less than zero - -Created on 07 01 2024 -Author: Kareiman Altayeb -""" - -import unittest - -from solutions.calculate_square_area import calculate_square_area - - -class CalculateSquareArea(unittest.TestCase): - """Tests the calculate_square_area function""" - - def test_positive_integers(self): - """It should return value ^ 2""" - self.assertEqual(calculate_square_area(7), 49) - - def test_positive_float(self): - """It should return value ^ 2""" - self.assertEqual(calculate_square_area(5.5), 30.25) - - def test_bigger_values(self): - """It should return the value ^ 2""" - self.assertEqual(calculate_square_area(2222), 4937284) - - # Edge cases - - def test_small_values(self): - """It should return the value ^ 2""" - self.assertEqual(calculate_square_area(0.75), 0.5625) - - # Defensive cases - - def test_string_entry(self): - """It should raise AssertionError if entry was text or letters""" - with self.assertRaises(AssertionError): - calculate_square_area("a") - - def test_value_zero(self): - """It should raise AssertionError if entry was zero""" - with self.assertRaises(AssertionError): - calculate_square_area(0) - - def test_value_negative(self): - """It should raise AssertionError if value was less than zero""" - with self.assertRaises(AssertionError): - calculate_square_area(-3) - - if __name__ == "__main__": - unittest.main() From 596938d73b8af9fb1f2fa49e69004102916733d8 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:37:13 +0300 Subject: [PATCH 27/38] Delete solutions/tests/test_check_number_type.py --- solutions/tests/test_check_number_type.py | 58 ----------------------- 1 file changed, 58 deletions(-) delete mode 100644 solutions/tests/test_check_number_type.py diff --git a/solutions/tests/test_check_number_type.py b/solutions/tests/test_check_number_type.py deleted file mode 100644 index ee39a41a1..000000000 --- a/solutions/tests/test_check_number_type.py +++ /dev/null @@ -1,58 +0,0 @@ -""" -Unit tests for the check_number_type function. - -Test categories: - - Standard cases: typical lists with different lengths - - Edge cases: empty lists, single element - - Defensive tests: wrong input types, assertions - - -Created on 05 01 2025 -@author: Eman Alfalouji -""" - -import unittest - -from solutions.check_number_type import check_number_type - - -class TestCheckNumberType(unittest.TestCase): - """Tests the check_number_type function.""" - - def test_even_number(self): - """It should identify even numbers.""" - self.assertEqual(check_number_type("22"), "The number is even") - - def test_odd_number(self): - """It should identify odd numbers.""" - self.assertEqual(check_number_type("15"), "The number is odd") - - def test_zero(self): - """It should identify zero as even.""" - self.assertEqual(check_number_type("0"), "The number is even") - - def test_negative_even_number(self): - """It should identify negative even numbers.""" - self.assertEqual(check_number_type("-4"), "The number is even") - - def test_negative_odd_number(self): - """It should identify negative odd numbers.""" - self.assertEqual(check_number_type("-7"), "The number is odd") - - def test_input_with_whitespace(self): - """It should handle inputs with leading/trailing whitespace.""" - self.assertEqual(check_number_type(" 8 "), "The number is even") - - def test_invalid_input(self): - """It should raise ValueError for invalid inputs.""" - with self.assertRaises(ValueError): - check_number_type("abc") - - def test_empty_input(self): - """It should raise ValueError for empty inputs.""" - with self.assertRaises(ValueError): - check_number_type("") - - -if __name__ == "__main__": - unittest.main() From 9f42d3c29579797634f0d9f5b299f0479598d944 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:37:24 +0300 Subject: [PATCH 28/38] Delete solutions/tests/test_convert_hours_to_minutes.py --- .../tests/test_convert_hours_to_minutes.py | 66 ------------------- 1 file changed, 66 deletions(-) delete mode 100644 solutions/tests/test_convert_hours_to_minutes.py diff --git a/solutions/tests/test_convert_hours_to_minutes.py b/solutions/tests/test_convert_hours_to_minutes.py deleted file mode 100644 index ee34d7c6b..000000000 --- a/solutions/tests/test_convert_hours_to_minutes.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Unit tests for the convert_hours_to_minutes function. - -Test cases include: - - Valid inputs for standard calculations - - Boundary cases - - Defensive tests for invalid inputs - -Created on 2024-12-31 -Author: Azza -""" - -import unittest - -from solutions.convert_hours_to_minutes import convert_hours_to_minutes - - -class TestConvertHoursToMinutes(unittest.TestCase): - """Unit tests for the convert_hours_to_minutes function.""" - - def test_one_hour(self): - """It should return 60 minutes for 1 hour.""" - self.assertEqual(convert_hours_to_minutes(1), 60) - - def test_multiple_hours(self): - """It should return 300 minutes for 5 hours.""" - self.assertEqual(convert_hours_to_minutes(5), 300) - - def test_zero_hours(self): - """It should return 0 minutes for 0 hours.""" - self.assertEqual(convert_hours_to_minutes(0), 0) - - def test_large_number_of_hours(self): - """It should return 60000 minutes for 1000 hours.""" - self.assertEqual(convert_hours_to_minutes(1000), 60000) - - def test_negative_hours(self): - """It should raise an AssertionError for negative hours.""" - with self.assertRaises(AssertionError): - convert_hours_to_minutes(-5) - - def test_string_input(self): - """It should raise an AssertionError for string input.""" - with self.assertRaises(AssertionError): - convert_hours_to_minutes("3") - - def test_float_input(self): - """It should raise an AssertionError for float input.""" - with self.assertRaises(AssertionError): - convert_hours_to_minutes(2.5) - - def test_none_input(self): - """It should raise an AssertionError for None input.""" - with self.assertRaises(AssertionError): - convert_hours_to_minutes(None) - - def test_list_input(self): - """It should raise an AssertionError for list input.""" - with self.assertRaises(AssertionError): - convert_hours_to_minutes([1, 2]) - - -if __name__ == "__main__": - unittest.main() From b20605067cf026fe799e8e514e5719df75ac2dc6 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:37:32 +0300 Subject: [PATCH 29/38] Delete solutions/tests/test_convert_to_capital.py --- solutions/tests/test_convert_to_capital.py | 55 ---------------------- 1 file changed, 55 deletions(-) delete mode 100644 solutions/tests/test_convert_to_capital.py diff --git a/solutions/tests/test_convert_to_capital.py b/solutions/tests/test_convert_to_capital.py deleted file mode 100644 index 2fc8a8a83..000000000 --- a/solutions/tests/test_convert_to_capital.py +++ /dev/null @@ -1,55 +0,0 @@ -# !/usr/bin/env python3 -# -*- coding: utf-8 -*- - -""" -A module to test convert_to_capital function - -Test categories: - - Standard cases: Regular text with different length - - Edge cases: Mix of different data types - - Defensive tests: Empty input - -Created on 03 01 2025 - -@author: Kareiman Altayeb -""" - -import unittest - -# To test convert_to_capital -from solutions.convert_to_capital import convert_to_capital - - -class TestConvertCapitalLetters(unittest.TestCase): - "Tests convert_to_capital function" - - # Standard test cases - - def test_all_small_letters(self): - """It should convert all letters to capital""" - self.assertEqual(convert_to_capital("kareiman"), "KAREIMAN") - - def test_some_are_capital_letters(self): - """It should convert all letters to capital""" - self.assertEqual(convert_to_capital("kAREiMan"), "KAREIMAN") - - def test_full_sentence(self): - """It should convert all words to capital""" - self.assertEqual(convert_to_capital("happy new year"), "HAPPY NEW YEAR") - - # Edge cases - - def test_mixed_with_numbers(self): - """It should return the numbers the same""" - self.assertEqual(convert_to_capital("12345kareiman"), "12345KAREIMAN") - - def test_special_characters(self): - """It should return special characters the same""" - self.assertEqual(convert_to_capital("?!!!"), "?!!!") - - # Defensive tests - - def test_empty_entry(self): - """It should raise an error for space or empty entry""" - with self.assertRaises(AssertionError): - convert_to_capital("") From d63ba20f1eac2e933b5653dfe7b6c7cf89fa1ce6 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:37:42 +0300 Subject: [PATCH 30/38] Delete solutions/tests/test_convert_to_uppercase.py --- solutions/tests/test_convert_to_uppercase.py | 55 -------------------- 1 file changed, 55 deletions(-) delete mode 100644 solutions/tests/test_convert_to_uppercase.py diff --git a/solutions/tests/test_convert_to_uppercase.py b/solutions/tests/test_convert_to_uppercase.py deleted file mode 100644 index 682450133..000000000 --- a/solutions/tests/test_convert_to_uppercase.py +++ /dev/null @@ -1,55 +0,0 @@ -# !/usr/bin/env python3 -# -*- coding: utf-8 -*- - -""" -A module to test convert_to_uppercase function - -Test categories: - - Standard cases: Regular text with different length - - Edge cases: Mix of different data types - - Defensive tests: Empty input - -Created on 03 01 2025 - -@author: Kareiman Altayeb -""" - -import unittest - -# To test convert_to_uppercase -from solutions.convert_to_uppercase import convert_to_uppercase - - -class TestConvertToCapitalLetters(unittest.TestCase): - "Tests convert_to_capital function" - - # Standard test cases - - def test_all_small_letters(self): - """It should convert all letters to capital letter""" - self.assertEqual(convert_to_uppercase("kareiman"), "KAREIMAN") - - def test_some_are_capital_letters(self): - """It should convert all letters to capital letters""" - self.assertEqual(convert_to_uppercase("kAREiMan"), "KAREIMAN") - - def test_full_sentence(self): - """It should convert all words to capital letters""" - self.assertEqual(convert_to_uppercase("happy new year"), "HAPPY NEW YEAR") - - # Edge cases - - def test_mixed_with_numbers(self): - """It should return the numbers the same""" - self.assertEqual(convert_to_uppercase("12345kareiman"), "12345KAREIMAN") - - def test_special_characters(self): - """It should return special characters the same""" - self.assertEqual(convert_to_uppercase("?!!!"), "?!!!") - - # Defensive tests - - def test_empty_entry(self): - """It should raise an error for space or empty entry""" - with self.assertRaises(AssertionError): - convert_to_uppercase("") From 6435bd171bb5f36017e9ed4a95d9a2454a8b6f08 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:37:55 +0300 Subject: [PATCH 31/38] Delete solutions/tests/test_is_palindrome.py --- solutions/tests/test_is_palindrome.py | 43 --------------------------- 1 file changed, 43 deletions(-) delete mode 100644 solutions/tests/test_is_palindrome.py diff --git a/solutions/tests/test_is_palindrome.py b/solutions/tests/test_is_palindrome.py deleted file mode 100644 index 2713bdf41..000000000 --- a/solutions/tests/test_is_palindrome.py +++ /dev/null @@ -1,43 +0,0 @@ -""" -Created on 04/01/2025 - -@author: Tibyan Khalid -""" - -import unittest - -from ..is_palindrome import is_palindrome - - -class TestIsPalindrome(unittest.TestCase): - """Unittests for the is_palindrome function""" - - def test_palindrome(self): - self.assertEqual(is_palindrome("level"), "Palindrome") - - def test_not_palindrome(self): - self.assertEqual(is_palindrome("world"), "Not Palindrome") - - # Boundary Cases Tests - def test_empty_string(self): - "Empty string is considered a Palindrome" - self.assertEqual(is_palindrome(""), "Palindrome") - - def test_single_character(self): - "Any single character is a palindrome as it reads the same backward" - self.assertEqual(is_palindrome("t"), "Palindrome") - - def test_non_string_entry(self): - "Raise an error if entry is not a string" - with self.assertRaises(AssertionError): - is_palindrome(34) - - def test_upper_lower_cases(self): - "Case matters here, radar is a Palindrome but Radar is not" - self.assertEqual(is_palindrome("Radar"), "Not Palindrome") - self.assertEqual(is_palindrome("Radar".lower()), "Palindrome") - - def test_special_characters(self): - "Handles special characters correctly" - self.assertEqual(is_palindrome("t@a@t"), "Palindrome") - self.assertEqual(is_palindrome("a@b@c"), "Not Palindrome") From 138c90add23f8ca4347fc08f776442239635fcf7 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:38:03 +0300 Subject: [PATCH 32/38] Delete solutions/tests/test_largest_number.py --- solutions/tests/test_largest_number.py | 65 -------------------------- 1 file changed, 65 deletions(-) delete mode 100644 solutions/tests/test_largest_number.py diff --git a/solutions/tests/test_largest_number.py b/solutions/tests/test_largest_number.py deleted file mode 100644 index d855b6241..000000000 --- a/solutions/tests/test_largest_number.py +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -""" -Unit tests for the largest_number function. - -Test categories: -Standard cases: Typical lists with positive, negative, and mixed integers. -Edge cases: Empty lists, lists with a single element, lists with duplicate values. -Defensive tests: Non-list inputs (e.g., integers, strings), lists with non-integer elements, -assertions for invalid inputs. - -Created on 2025-01-11 -Author: Azza -""" - -import unittest - -from ..largest_number import largest_number - - -class TestLargestNumber(unittest.TestCase): - """Unit tests for the largest_number function.""" - - def test_standard_list(self): - """It should return 9 for [0, 1, 9, 2, 6, 4].""" - self.assertEqual(largest_number([0, 1, 9, 2, 6, 4]), 9) - - def test_single_element(self): - """It should return 12 for [12].""" - self.assertEqual(largest_number([12]), 12) - - def test_mixed_positive_and_negative(self): - """It should return 8 for [8, -1, -8, 5].""" - self.assertEqual(largest_number([8, -1, -8, 5]), 8) - - def test_all_negative_numbers(self): - """It should return -1 for [-9, -1, -6, -5].""" - self.assertEqual(largest_number([-9, -1, -6, -5]), -1) - - def test_all_zeros(self): - """It should return 0 for [0, 0].""" - self.assertEqual(largest_number([0, 0]), 0) - - def test_large_numbers(self): - """It should return 4294967296 for [2**32, 2**16, 2**8, 1].""" - self.assertEqual(largest_number([2**32, 2**16, 2**8, 1]), 2**32) - - def test_empty_list(self): - """It should raise ValueError for an empty list.""" - with self.assertRaises(ValueError): - largest_number([]) - - def test_non_list_input(self): - """It should raise TypeError for non-list input, e.g., 42.""" - with self.assertRaises(TypeError): - largest_number(42) - - def test_list_with_non_integer(self): - """It should raise TypeError for a list with non-integer elements.""" - with self.assertRaises(TypeError): - largest_number(["-5", 5, "0"]) - - -if __name__ == "__main__": - unittest.main() From bf19fc9a67afe480071b4b4c214454b84afa6f06 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:38:15 +0300 Subject: [PATCH 33/38] Delete solutions/tests/test_merge_dictionaries.py --- solutions/tests/test_merge_dictionaries.py | 83 ---------------------- 1 file changed, 83 deletions(-) delete mode 100644 solutions/tests/test_merge_dictionaries.py diff --git a/solutions/tests/test_merge_dictionaries.py b/solutions/tests/test_merge_dictionaries.py deleted file mode 100644 index e26e106b0..000000000 --- a/solutions/tests/test_merge_dictionaries.py +++ /dev/null @@ -1,83 +0,0 @@ -# solutions/tests/test_merge_dictionaries.py - -""" -Unit tests for the `merge_dictionaries` function. - -These tests ensure correct behavior of the `merge_dictionaries` function, -including standard merging, conflict resolution, edge cases, and input validation. - -Created on 03 01 2025 -@author: Frankline Ambetsa -""" - -import unittest -from solutions.merge_dictionaries import merge_dictionaries - - -class TestMergeDictionaries(unittest.TestCase): - """Unit tests for the `merge_dictionaries` function.""" - - def test_no_conflicts(self): - """It should merge dictionaries with no conflicting keys.""" - dict1 = {"a": 1, "b": 2} - dict2 = {"c": 3, "d": 4} - expected = {"a": 1, "b": 2, "c": 3, "d": 4} - self.assertEqual(merge_dictionaries(dict1, dict2), expected) - - def test_overwrite_conflicts(self): - """It should overwrite conflicting keys with values from dict2.""" - dict1 = {"a": 1, "b": 2} - dict2 = {"b": 3, "c": 4} - expected = {"a": 1, "b": 3, "c": 4} - self.assertEqual(merge_dictionaries(dict1, dict2), expected) - - def test_conflict_resolution_max(self): - """It should resolve conflicts using the max function.""" - dict1 = {"a": 1, "b": 5} - dict2 = {"b": 3, "c": 4} - expected = {"a": 1, "b": 5, "c": 4} - self.assertEqual(merge_dictionaries(dict1, dict2, max), expected) - - def test_conflict_resolution_min(self): - """It should resolve conflicts using the min function.""" - dict1 = {"a": 1, "b": 5} - dict2 = {"b": 3, "c": 4} - expected = {"a": 1, "b": 3, "c": 4} - self.assertEqual(merge_dictionaries(dict1, dict2, min), expected) - - def test_empty_dicts(self): - """It should return an empty dictionary when both inputs are empty.""" - dict1 = {} - dict2 = {} - expected = {} - self.assertEqual(merge_dictionaries(dict1, dict2), expected) - - def test_one_empty_dict(self): - """It should return the non-empty dictionary when one input is empty.""" - dict1 = {"a": 1, "b": 2} - dict2 = {} - expected = {"a": 1, "b": 2} - self.assertEqual(merge_dictionaries(dict1, dict2), expected) - - def test_only_conflicts(self): - """It should overwrite keys with values from dict2 for conflicting keys.""" - dict1 = {"a": 1} - dict2 = {"a": 2} - expected = {"a": 2} - self.assertEqual(merge_dictionaries(dict1, dict2), expected) - - def test_non_dict_inputs(self): - """It should raise a TypeError for non-dictionary inputs.""" - with self.assertRaises(AssertionError): - merge_dictionaries([], {"a": 1}) - with self.assertRaises(AssertionError): - merge_dictionaries({"a": 1}, 42) - - def test_invalid_conflict_resolution(self): - """It should raise a ValueError for non-callable conflict resolution.""" - with self.assertRaises(AssertionError): - merge_dictionaries({"a": 1}, {"a": 2}, conflict_resolution=42) - - -if __name__ == "__main__": - unittest.main() From f0f54b71426ab7d5a7b2558899604aaa72650363 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:38:23 +0300 Subject: [PATCH 34/38] Delete solutions/tests/test_sum_of_list.py --- solutions/tests/test_sum_of_list.py | 59 ----------------------------- 1 file changed, 59 deletions(-) delete mode 100644 solutions/tests/test_sum_of_list.py diff --git a/solutions/tests/test_sum_of_list.py b/solutions/tests/test_sum_of_list.py deleted file mode 100644 index 3c8efac3f..000000000 --- a/solutions/tests/test_sum_of_list.py +++ /dev/null @@ -1,59 +0,0 @@ -""" -Unit tests for the sum_of_list function. - -Test categories: - - Standard cases: typical lists with positive, negative, and mixed numbers - - Edge cases: empty lists, single elements - - Defensive tests: wrong input types, invalid elements - -Created on 05 01 2025 -@author: Eman Alfalouji -""" - -import unittest - -from solutions.sum_of_list import sum_of_list - - -class TestSumOfList(unittest.TestCase): - """Tests the sum_of_list function.""" - - # Standard test cases - def test_positive_numbers(self): - """Test that the function correctly sums a list of positive integers.""" - self.assertEqual(sum_of_list([8, 7, 3, 4, 5]), 27) - - def test_negative_numbers(self): - """Test that the function correctly sums a list of negative integers.""" - self.assertEqual(sum_of_list([-1, -4, -7]), -12) - - def test_mixed_numbers(self): - """ - Test that the function correctly sums a list with both positive and negative numbers, - including floats. - """ - self.assertEqual(sum_of_list([1, -2, 3.5]), 2.5) - - # Edge cases - def test_empty_list(self): - """Test that the function returns 0 for an empty list.""" - self.assertEqual(sum_of_list([]), 0) - - def test_single_element(self): - """Test that the function returns the single element value when the list has only one number.""" - self.assertEqual(sum_of_list([10]), 10) - - # Defensive cases - def test_invalid_input_type(self): - """Test that the function raises a TypeError when the input is not a list.""" - with self.assertRaises(TypeError): - sum_of_list("not a list") - - def test_invalid_element_type(self): - """Test that the function raises a ValueError when the list contains non-numeric elements.""" - with self.assertRaises(ValueError): - sum_of_list([1, "two", 3]) - - -if __name__ == "__main__": - unittest.main() From 8512058a844b143037b9a6b11be589e6ef868db0 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:38:32 +0300 Subject: [PATCH 35/38] Delete solutions/tests/test_word_frequency.py --- solutions/tests/test_word_frequency.py | 37 -------------------------- 1 file changed, 37 deletions(-) delete mode 100644 solutions/tests/test_word_frequency.py diff --git a/solutions/tests/test_word_frequency.py b/solutions/tests/test_word_frequency.py deleted file mode 100644 index 5381b5000..000000000 --- a/solutions/tests/test_word_frequency.py +++ /dev/null @@ -1,37 +0,0 @@ -# test_word_frequency.py -""" -This module contains unit tests for the word_frequency module. - -The tests verify the functionality of the count_word_frequency function, -which counts the frequency of words in a given text. -""" - -import unittest - -from ..word_frequency import count_word_frequency - - -class TestWordFrequency(unittest.TestCase): - """Test cases for the count_word_frequency function.""" - - def test_count_word_frequency(self): - """Test counting word frequency in a simple text.""" - text = "hello world hello" - expected_output = {"hello": 2, "world": 1} - self.assertEqual(count_word_frequency(text), expected_output) - - def test_empty_text(self): - """Test counting word frequency in an empty string.""" - text = "" - expected_output = {} - self.assertEqual(count_word_frequency(text), expected_output) - - def test_case_insensitive(self): - """Test counting word frequency with case-insensitive matching.""" - text = "Hello hello HeLLo" - expected_output = {"hello": 3} - self.assertEqual(count_word_frequency(text), expected_output) - - -if __name__ == "__main__": - unittest.main() From 2beadd65d5b560b9786b6eb035eac92855298949 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:40:52 +0300 Subject: [PATCH 36/38] Update README.md --- solutions/README.md | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/solutions/README.md b/solutions/README.md index 5e8bb0bd5..bd3e4395e 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -6,23 +6,32 @@ This folder contains implementations for the challenges. 1. **Merge Dictionaries**: - A utility to merge two dictionaries with conflict resolution. - - Resolves conflicts with a custom function, or by default, `dict2` overwrites `dict1`. - See `merge_dictionaries.py` for the implementation. - ### How to Run +2. **Anagram Finder**: + - A function to check if two strings are anagrams. + - See `anagram_finder.py` for the implementation. - 1. Clone the repository. - 2. Install dependencies (if any). - 3. Run the tests: +## Usage - ```bash - python -m unittest solutions/tests/test_merge_dictionaries.py - ``` +To use any solution, simply import the +required function and pass the appropriate arguments. - ### Example +### How to Run - ```python - dict1 = {"a": 1, "b": 2} - dict2 = {"b": 3, "c": 4} - merged = merge_dictionaries(dict1, dict2) - print(merged) # Output: {'a': 1, 'b': 3, 'c': 4} +1. Clone the repository. +2. Navigate to the folder containing the solution. +3. Run the desired script: + + ```bash + python .py + ``` + +### Example + +```python +# Example for Anagram Finder +from anagram_finder import are_anagrams + +result = are_anagrams("listen", "silent") +print(result) # Output: True From e7c7486ef0d4208ac541dccd9c7bb61b52bae623 Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:41:29 +0300 Subject: [PATCH 37/38] Update README.md --- solutions/tests/README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/solutions/tests/README.md b/solutions/tests/README.md index aaf6675d3..3fd7244cf 100644 --- a/solutions/tests/README.md +++ b/solutions/tests/README.md @@ -4,7 +4,8 @@ This folder contains unit tests for the challenges in the `solutions` module. ## Purpose -The purpose of these tests is to ensure the functionality of the implemented solutions, including handling edge cases and verifying correct behavior. +The purpose of these tests is to ensure the functionality of +the implemented solutions, including handling edge cases and verifying correct behavior. ## Test Files @@ -17,7 +18,8 @@ The purpose of these tests is to ensure the functionality of the implemented sol - **`test_anagram_finder.py`**: - Tests for the Anagram Finder challenge. - - Ensures the function correctly identifies whether two strings are anagrams, handling both typical and edge cases. + - Ensures the function correctly identifies whether two strings are anagrams, + - handling both typical and edge cases. ## Running Tests @@ -25,3 +27,4 @@ Run the following command to execute all tests: ```bash python -m unittest discover -s solutions/tests -p "test_*.py" + From 5908452e10926beaf130e525db072626f26cb30d Mon Sep 17 00:00:00 2001 From: FRANKLINE ALELE AMBETSA <150971995+Frank2446-dotcom@users.noreply.github.com> Date: Sun, 12 Jan 2025 13:45:52 +0300 Subject: [PATCH 38/38] Update README.md --- solutions/tests/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/solutions/tests/README.md b/solutions/tests/README.md index 3fd7244cf..72a49f6c2 100644 --- a/solutions/tests/README.md +++ b/solutions/tests/README.md @@ -27,4 +27,3 @@ Run the following command to execute all tests: ```bash python -m unittest discover -s solutions/tests -p "test_*.py" -