From b2fc09950b0acf65c63f39b0e575fecfb1f71e97 Mon Sep 17 00:00:00 2001 From: Muhammad Muqaddas Rehman <167186162+muqaddas96@users.noreply.github.com> Date: Sat, 21 Dec 2024 22:05:12 +0500 Subject: [PATCH 01/74] Added Norms --- collaboration/README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/collaboration/README.md b/collaboration/README.md index 20889b951..019bb2500 100644 --- a/collaboration/README.md +++ b/collaboration/README.md @@ -2,4 +2,39 @@ +## Summary + +Our group values respect, collaboration, and inclusivity by fostering a safe space, valuing diverse perspectives, and being punctual and prepared. We follow standardized coding practices, ensure thorough testing, and use pull requests for repository management. Committed to learning and growth, we support each other, respond promptly to queries, and resolve conflicts fairly through voting. + + +## Finalized Norms + +### Respect + +* Be respectful and considerate when providing feedback or suggestions. +* We must communicate respectfully to build trust. +* We will value each other's time by being prepared and punctual. (Waiting time for every meeting will be 5 minutes). +* Respecting everyone’s cultural/emotional background. +* We will value each other’s diverse perspectives and create a safe, collaborative space. + +### Standardization + +* Follow the agreed upon coding standards and guidelines (e.g., naming conventions, indentations, comments). +* Provide descriptive commit messages summarizing the changes. +* Perform testing when applicable and document any test cases; ensure all tests pass before creating or merging a pull request. +* Never push directly to the main branch; always create a pull request. + +### Team’s Learning + +* Group members must think about the whole team’s improvement and practice good leadership. +* We will actively assist and support each other to overcome challenges and achieve success together. + +### Availability + +* Respond to queries or comments within 24-48 hours whenever possible. +* Every member should answer questions of the member asked on Slack or WhatsApp if they have the answer and do not leave it for others. + +### Conflict resolution + +* Every member will have equal rights. If there is any conflict, it should be resolved within the group through voting. From 8348b6bbcf65e7e5a86d435a93a1a9b9ebe2fc5f Mon Sep 17 00:00:00 2001 From: muqaddas96 Date: Fri, 27 Dec 2024 16:23:06 +0500 Subject: [PATCH 02/74] added first solution and test cases --- solutions/is_palindrome.py | 35 ++++++++++++++++++++++++++ solutions/tests/palindrome_tests.py | 38 +++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 solutions/is_palindrome.py create mode 100644 solutions/tests/palindrome_tests.py diff --git a/solutions/is_palindrome.py b/solutions/is_palindrome.py new file mode 100644 index 000000000..e50f7796b --- /dev/null +++ b/solutions/is_palindrome.py @@ -0,0 +1,35 @@ +""" +A module for checking if a string is a palindrome. + +Module contents: + - is_palindrome: checks whether a string is a palindrome. + +Created on 27 12 2024 +@author: muqaddas96 +""" + +def is_palindrome(text: str) -> bool: + """Check if a string is a palindrome. + + Parameters: + text: str, the input string to check + + Returns -> bool: True if the text is a palindrome, False otherwise + + Raises: + AssertionError: if the argument is not a string + + >>> is_palindrome("racecar") + True + >>> is_palindrome("hello") + False + >>> is_palindrome("A man a plan a canal Panama") + True + """ + assert isinstance(text, str), "input must be a string" + + # Remove spaces and convert to lowercase + normalized_text = "".join(text.split()).lower() + + # Check if it reads the same forward and backward + return normalized_text == normalized_text[::-1] diff --git a/solutions/tests/palindrome_tests.py b/solutions/tests/palindrome_tests.py new file mode 100644 index 000000000..fc4689099 --- /dev/null +++ b/solutions/tests/palindrome_tests.py @@ -0,0 +1,38 @@ +import unittest + +from ..is_palindrome import is_palindrome + +class TestIsPalindrome(unittest.TestCase): + """Test the is_palindrome function""" + + def test_empty_string(self): + """It should return True for an empty string""" + self.assertTrue(is_palindrome("")) + + def test_single_character(self): + """It should return True for a single character""" + self.assertTrue(is_palindrome("a")) + + def test_palindrome(self): + """It should return True for a valid palindrome""" + self.assertTrue(is_palindrome("racecar")) + + def test_non_palindrome(self): + """It should return False for a non-palindrome""" + self.assertFalse(is_palindrome("hello")) + + def test_palindrome_with_spaces(self): + """It should ignore spaces and check for palindrome""" + self.assertTrue(is_palindrome("A man a plan a canal Panama")) + + def test_palindrome_with_mixed_case(self): + """It should ignore case and check for palindrome""" + self.assertTrue(is_palindrome("RaceCar")) + + def test_not_string(self): + """It should raise AssertionError for non-string input""" + with self.assertRaises(AssertionError): + is_palindrome(123) + +if __name__ == "__main__": + unittest.main() From 1da94754ae9a326151cffb14f10e70f29ffd4915 Mon Sep 17 00:00:00 2001 From: muqaddas96 Date: Fri, 27 Dec 2024 16:25:43 +0500 Subject: [PATCH 03/74] Changed test names to Pascal notation --- solutions/tests/palindrome_tests.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/solutions/tests/palindrome_tests.py b/solutions/tests/palindrome_tests.py index fc4689099..7d0be46f4 100644 --- a/solutions/tests/palindrome_tests.py +++ b/solutions/tests/palindrome_tests.py @@ -5,31 +5,31 @@ class TestIsPalindrome(unittest.TestCase): """Test the is_palindrome function""" - def test_empty_string(self): + def TestEmptyString(self): """It should return True for an empty string""" self.assertTrue(is_palindrome("")) - def test_single_character(self): + def TestSingleCharacter(self): """It should return True for a single character""" self.assertTrue(is_palindrome("a")) - def test_palindrome(self): + def TestPalindrome(self): """It should return True for a valid palindrome""" self.assertTrue(is_palindrome("racecar")) - def test_non_palindrome(self): + def TestNonPalindrome(self): """It should return False for a non-palindrome""" self.assertFalse(is_palindrome("hello")) - def test_palindrome_with_spaces(self): + def TestPalindromeWithSpaces(self): """It should ignore spaces and check for palindrome""" self.assertTrue(is_palindrome("A man a plan a canal Panama")) - def test_palindrome_with_mixed_case(self): + def TestPalindromeWithMixedCase(self): """It should ignore case and check for palindrome""" self.assertTrue(is_palindrome("RaceCar")) - def test_not_string(self): + def TestNotString(self): """It should raise AssertionError for non-string input""" with self.assertRaises(AssertionError): is_palindrome(123) From f2b8afbdd1927a6ed0a7e92c37bb9b5fb3b48157 Mon Sep 17 00:00:00 2001 From: muqaddas96 Date: Fri, 27 Dec 2024 16:27:23 +0500 Subject: [PATCH 04/74] renamed test case --- solutions/tests/{palindrome_tests.py => test_is_palindrome.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename solutions/tests/{palindrome_tests.py => test_is_palindrome.py} (100%) diff --git a/solutions/tests/palindrome_tests.py b/solutions/tests/test_is_palindrome.py similarity index 100% rename from solutions/tests/palindrome_tests.py rename to solutions/tests/test_is_palindrome.py From 0189677bd37250187f9affcbbe0da1962a830ffe Mon Sep 17 00:00:00 2001 From: muqaddas96 Date: Fri, 27 Dec 2024 17:08:50 +0500 Subject: [PATCH 05/74] fix function location in test file --- solutions/tests/test_is_palindrome.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/tests/test_is_palindrome.py b/solutions/tests/test_is_palindrome.py index 7d0be46f4..8056cec41 100644 --- a/solutions/tests/test_is_palindrome.py +++ b/solutions/tests/test_is_palindrome.py @@ -1,6 +1,6 @@ import unittest -from ..is_palindrome import is_palindrome +from solutions.is_palindrome import is_palindrome class TestIsPalindrome(unittest.TestCase): """Test the is_palindrome function""" From cee681285516a32fb8d529139c009ac80ad5704d Mon Sep 17 00:00:00 2001 From: muqaddas96 Date: Fri, 27 Dec 2024 17:13:23 +0500 Subject: [PATCH 06/74] added __init__.py 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 08153320a98bdba0f2c1ffda103fa1d754c70c58 Mon Sep 17 00:00:00 2001 From: Muhammad Muqaddas Rehman <167186162+muqaddas96@users.noreply.github.com> Date: Sat, 28 Dec 2024 00:50:11 +0500 Subject: [PATCH 07/74] Update README.md --- collaboration/README.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/collaboration/README.md b/collaboration/README.md index 019bb2500..bcea17e18 100644 --- a/collaboration/README.md +++ b/collaboration/README.md @@ -4,7 +4,10 @@ ## Summary -Our group values respect, collaboration, and inclusivity by fostering a safe space, valuing diverse perspectives, and being punctual and prepared. We follow standardized coding practices, ensure thorough testing, and use pull requests for repository management. Committed to learning and growth, we support each other, respond promptly to queries, and resolve conflicts fairly through voting. +Our group values respect, collaboration, and inclusivity by fostering a safe space, valuing diverse +perspectives, and being punctual and prepared. We follow standardized coding practices, ensure thorough +testing, and use pull requests for repository management. Committed to learning and growth, we support +each other, respond promptly to queries, and resolve conflicts fairly through voting. @@ -14,13 +17,15 @@ Our group values respect, collaboration, and inclusivity by fostering a safe spa * Be respectful and considerate when providing feedback or suggestions. * We must communicate respectfully to build trust. -* We will value each other's time by being prepared and punctual. (Waiting time for every meeting will be 5 minutes). +* We will value each other's time by being prepared and punctual. (Waiting time for every meeting + will be 5 minutes). * Respecting everyone’s cultural/emotional background. * We will value each other’s diverse perspectives and create a safe, collaborative space. ### Standardization -* Follow the agreed upon coding standards and guidelines (e.g., naming conventions, indentations, comments). +* Follow the agreed upon coding standards and guidelines (e.g., naming conventions, indentations, + comments). * Provide descriptive commit messages summarizing the changes. * Perform testing when applicable and document any test cases; ensure all tests pass before creating or merging a pull request. * Never push directly to the main branch; always create a pull request. @@ -33,8 +38,10 @@ Our group values respect, collaboration, and inclusivity by fostering a safe spa ### Availability * Respond to queries or comments within 24-48 hours whenever possible. -* Every member should answer questions of the member asked on Slack or WhatsApp if they have the answer and do not leave it for others. +* Every member should answer questions of the member asked on Slack or WhatsApp + if they have the answer and do not leave it for others. ### Conflict resolution -* Every member will have equal rights. If there is any conflict, it should be resolved within the group through voting. +* Every member will have equal rights. If there is any conflict, it should be resolved within the group + through voting. From 2956739247f65b69b763e6b660457866582c8666 Mon Sep 17 00:00:00 2001 From: Muhammad Muqaddas Rehman <167186162+muqaddas96@users.noreply.github.com> Date: Sat, 28 Dec 2024 01:10:54 +0500 Subject: [PATCH 08/74] Update README.md --- collaboration/README.md | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/collaboration/README.md b/collaboration/README.md index bcea17e18..68e501299 100644 --- a/collaboration/README.md +++ b/collaboration/README.md @@ -4,10 +4,11 @@ ## Summary -Our group values respect, collaboration, and inclusivity by fostering a safe space, valuing diverse -perspectives, and being punctual and prepared. We follow standardized coding practices, ensure thorough -testing, and use pull requests for repository management. Committed to learning and growth, we support -each other, respond promptly to queries, and resolve conflicts fairly through voting. +Our group values respect, collaboration, and inclusivity by fostering a safe space, +valuing diverse perspectives, +and being punctual and prepared. We follow standardized coding practices, ensure thorough testing, +and use pull requests for repository management. Committed to learning and growth, +we support each other, respond promptly to queries, and resolve conflicts fairly through voting. @@ -15,33 +16,33 @@ each other, respond promptly to queries, and resolve conflicts fairly through vo ### Respect -* Be respectful and considerate when providing feedback or suggestions. -* We must communicate respectfully to build trust. -* We will value each other's time by being prepared and punctual. (Waiting time for every meeting - will be 5 minutes). -* Respecting everyone’s cultural/emotional background. +* Be respectful and considerate when providing feedback or suggestions. +* We must communicate respectfully to build trust. +* We will value each other's time by being prepared and punctual. (Waiting time for +every meeting will be 5 minutes). +* Respecting everyone’s cultural/emotional background. * We will value each other’s diverse perspectives and create a safe, collaborative space. ### Standardization -* Follow the agreed upon coding standards and guidelines (e.g., naming conventions, indentations, - comments). -* Provide descriptive commit messages summarizing the changes. -* Perform testing when applicable and document any test cases; ensure all tests pass before creating or merging a pull request. +* Follow the agreed upon coding standards and guidelines (e.g., naming conventions, indentations, comments). +* Provide descriptive commit messages summarizing the changes. +* Perform testing when applicable and document any test cases; ensure all tests pass +before creating or merging a pull request. * Never push directly to the main branch; always create a pull request. ### Team’s Learning -* Group members must think about the whole team’s improvement and practice good leadership. +* Group members must think about the whole team’s improvement and practice good leadership. * We will actively assist and support each other to overcome challenges and achieve success together. ### Availability -* Respond to queries or comments within 24-48 hours whenever possible. -* Every member should answer questions of the member asked on Slack or WhatsApp - if they have the answer and do not leave it for others. +* Respond to queries or comments within 24-48 hours whenever possible. +* Every member should answer questions of the member asked on Slack or WhatsApp if they +have the answer and do not leave it for others. ### Conflict resolution -* Every member will have equal rights. If there is any conflict, it should be resolved within the group - through voting. +* Every member will have equal rights. If there is any conflict, it should be +resolved within the group through voting. From 5bf0fdf0819d96c2d536fc19e4fcf7be50ec3a3c Mon Sep 17 00:00:00 2001 From: Muhammad Muqaddas Rehman <167186162+muqaddas96@users.noreply.github.com> Date: Sat, 28 Dec 2024 01:17:18 +0500 Subject: [PATCH 09/74] Update README.md --- collaboration/README.md | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/collaboration/README.md b/collaboration/README.md index 68e501299..3cf130140 100644 --- a/collaboration/README.md +++ b/collaboration/README.md @@ -6,9 +6,11 @@ Our group values respect, collaboration, and inclusivity by fostering a safe space, valuing diverse perspectives, -and being punctual and prepared. We follow standardized coding practices, ensure thorough testing, +and being punctual and prepared. We follow standardized coding practices, ensure +thorough testing, and use pull requests for repository management. Committed to learning and growth, -we support each other, respond promptly to queries, and resolve conflicts fairly through voting. +we support each other, respond promptly to queries, and resolve conflicts fairly +through voting. @@ -18,14 +20,16 @@ we support each other, respond promptly to queries, and resolve conflicts fairly * Be respectful and considerate when providing feedback or suggestions. * We must communicate respectfully to build trust. -* We will value each other's time by being prepared and punctual. (Waiting time for -every meeting will be 5 minutes). +* We will value each other's time by being prepared and punctual. (Waiting time +for every meeting will be 5 minutes). * Respecting everyone’s cultural/emotional background. -* We will value each other’s diverse perspectives and create a safe, collaborative space. +* We will value each other’s diverse perspectives and create a safe, collaborative +space. ### Standardization -* Follow the agreed upon coding standards and guidelines (e.g., naming conventions, indentations, comments). +* Follow the agreed upon coding standards and guidelines (e.g., naming conventions, +indentations, comments). * Provide descriptive commit messages summarizing the changes. * Perform testing when applicable and document any test cases; ensure all tests pass before creating or merging a pull request. @@ -33,14 +37,16 @@ before creating or merging a pull request. ### Team’s Learning -* Group members must think about the whole team’s improvement and practice good leadership. -* We will actively assist and support each other to overcome challenges and achieve success together. +* Group members must think about the whole team’s improvement and practice good +leadership. +* We will actively assist and support each other to overcome challenges and +achieve success together. ### Availability * Respond to queries or comments within 24-48 hours whenever possible. -* Every member should answer questions of the member asked on Slack or WhatsApp if they -have the answer and do not leave it for others. +* Every member should answer questions of the member asked on Slack or +WhatsApp if they have the answer and do not leave it for others. ### Conflict resolution From 0b6054e73cef27d15c9cb182a87a42c7daece795 Mon Sep 17 00:00:00 2001 From: muqaddas96 Date: Sat, 28 Dec 2024 01:22:59 +0500 Subject: [PATCH 10/74] ruff format applied --- solutions/is_palindrome.py | 5 +++-- solutions/tests/test_is_palindrome.py | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/solutions/is_palindrome.py b/solutions/is_palindrome.py index e50f7796b..3e103910a 100644 --- a/solutions/is_palindrome.py +++ b/solutions/is_palindrome.py @@ -8,6 +8,7 @@ @author: muqaddas96 """ + def is_palindrome(text: str) -> bool: """Check if a string is a palindrome. @@ -27,9 +28,9 @@ def is_palindrome(text: str) -> bool: True """ assert isinstance(text, str), "input must be a string" - + # Remove spaces and convert to lowercase normalized_text = "".join(text.split()).lower() - + # Check if it reads the same forward and backward return normalized_text == normalized_text[::-1] diff --git a/solutions/tests/test_is_palindrome.py b/solutions/tests/test_is_palindrome.py index 8056cec41..c23ff2b70 100644 --- a/solutions/tests/test_is_palindrome.py +++ b/solutions/tests/test_is_palindrome.py @@ -2,6 +2,7 @@ from solutions.is_palindrome import is_palindrome + class TestIsPalindrome(unittest.TestCase): """Test the is_palindrome function""" @@ -34,5 +35,6 @@ def TestNotString(self): with self.assertRaises(AssertionError): is_palindrome(123) + if __name__ == "__main__": unittest.main() From 436f2e95b6969ccb4065c637281bc0ef839d4a2c Mon Sep 17 00:00:00 2001 From: muqaddas96 Date: Sat, 28 Dec 2024 01:39:20 +0500 Subject: [PATCH 11/74] fixed names --- solutions/tests/test_is_palindrome.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/solutions/tests/test_is_palindrome.py b/solutions/tests/test_is_palindrome.py index c23ff2b70..8954398e8 100644 --- a/solutions/tests/test_is_palindrome.py +++ b/solutions/tests/test_is_palindrome.py @@ -1,36 +1,35 @@ import unittest - from solutions.is_palindrome import is_palindrome class TestIsPalindrome(unittest.TestCase): """Test the is_palindrome function""" - def TestEmptyString(self): + def test_empty_string(self): """It should return True for an empty string""" self.assertTrue(is_palindrome("")) - def TestSingleCharacter(self): + def test_single_character(self): """It should return True for a single character""" self.assertTrue(is_palindrome("a")) - def TestPalindrome(self): + def test_palindrome(self): """It should return True for a valid palindrome""" self.assertTrue(is_palindrome("racecar")) - def TestNonPalindrome(self): + def test_non_palindrome(self): """It should return False for a non-palindrome""" self.assertFalse(is_palindrome("hello")) - def TestPalindromeWithSpaces(self): + def test_palindrome_with_spaces(self): """It should ignore spaces and check for palindrome""" self.assertTrue(is_palindrome("A man a plan a canal Panama")) - def TestPalindromeWithMixedCase(self): + def test_palindrome_with_mixed_case(self): """It should ignore case and check for palindrome""" self.assertTrue(is_palindrome("RaceCar")) - def TestNotString(self): + def test_not_string(self): """It should raise AssertionError for non-string input""" with self.assertRaises(AssertionError): is_palindrome(123) From f177c8243b5b0af6b94b196de377359539932bc0 Mon Sep 17 00:00:00 2001 From: muqaddas96 Date: Sat, 28 Dec 2024 01:50:39 +0500 Subject: [PATCH 12/74] fix test link --- solutions/tests/test_is_palindrome.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/tests/test_is_palindrome.py b/solutions/tests/test_is_palindrome.py index 8954398e8..318557923 100644 --- a/solutions/tests/test_is_palindrome.py +++ b/solutions/tests/test_is_palindrome.py @@ -1,5 +1,5 @@ import unittest -from solutions.is_palindrome import is_palindrome +from is_palindrome import is_palindrome class TestIsPalindrome(unittest.TestCase): From 674a3049b76d594b157b684d47bef5eed8d16346 Mon Sep 17 00:00:00 2001 From: muqaddas96 Date: Sat, 28 Dec 2024 02:09:15 +0500 Subject: [PATCH 13/74] Fix python tests --- solutions/__init__.py | 0 solutions/tests/test_is_palindrome.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 solutions/__init__.py diff --git a/solutions/__init__.py b/solutions/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/solutions/tests/test_is_palindrome.py b/solutions/tests/test_is_palindrome.py index 318557923..8954398e8 100644 --- a/solutions/tests/test_is_palindrome.py +++ b/solutions/tests/test_is_palindrome.py @@ -1,5 +1,5 @@ import unittest -from is_palindrome import is_palindrome +from solutions.is_palindrome import is_palindrome class TestIsPalindrome(unittest.TestCase): From 9ad91f2cd3cf51950b8edee6312ef4b86250ca31 Mon Sep 17 00:00:00 2001 From: Momtaz Yaqubi Date: Sat, 28 Dec 2024 11:09:07 +0430 Subject: [PATCH 14/74] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index e69de29bb..f63e2acf2 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,3 @@ +##PyVersity + +welcome to pyversity main repository From 12d3f1312e81e10c5a4d656da87d70ac0e21e5e0 Mon Sep 17 00:00:00 2001 From: Momtaz Yaqubi Date: Sat, 28 Dec 2024 11:09:48 +0430 Subject: [PATCH 15/74] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f63e2acf2..a0bed456f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -##PyVersity +PyVersity welcome to pyversity main repository From c6b8de9aa199834abd8ec94dbe4d3ccdf6633a8a Mon Sep 17 00:00:00 2001 From: Momtaz Date: Sat, 28 Dec 2024 11:16:11 +0430 Subject: [PATCH 16/74] Changes to readme --- .vscode/settings.json | 5 ++++- README.md | 6 ++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5a90e202f..c75a6af31 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, + "cSpell.words": [ + "Versity" + ] } diff --git a/README.md b/README.md index a0bed456f..8605cf81e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ -PyVersity +# PyVersity -welcome to pyversity main repository +****** + +welcome to Pyversity main repository From 8bab4a8b8e17322be9efd441217eaaf5adab6827 Mon Sep 17 00:00:00 2001 From: Momtaz Date: Sat, 28 Dec 2024 21:05:03 +0430 Subject: [PATCH 17/74] readme changed --- .vscode/settings.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index c75a6af31..047d285fe 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -116,5 +116,8 @@ "markdown.extension.toc.updateOnSave": false, "cSpell.words": [ "Versity" + ], + "githubPullRequests.ignoredPullRequestBranches": [ + "main" ] } From d0fd34e15da33f5e439af6b25006801fe8ea7597 Mon Sep 17 00:00:00 2001 From: arvidon Date: Sun, 29 Dec 2024 00:28:00 +0530 Subject: [PATCH 18/74] bank is working --- solutions/bank.py | 40 ++++++++++++++++++++++++++++++++++++ solutions/tests/test_bank.py | 29 ++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 solutions/bank.py create mode 100644 solutions/tests/test_bank.py diff --git a/solutions/bank.py b/solutions/bank.py new file mode 100644 index 000000000..d0e51fb2f --- /dev/null +++ b/solutions/bank.py @@ -0,0 +1,40 @@ +def main() -> None: + """ + Main function to get user input and print the value based on the greeting. + + This function prompts the user for a greeting and then determines and prints the value + associated with that greeting using the `value` function. + """ + greeting: str = input("Greetings: ") # Get user input as a string + print(value(greeting)) # Call the value function and print its result + + +def value(greeting: str) -> int: + """ + Determine the value of a greeting based on certain conditions. + + This function returns an integer value based on the provided greeting. If the greeting + contains the word "hello", the value is 0. If the first character of the greeting is "h", + the value is 20. Otherwise, the value is 100. + + Parameters: + greeting (str): The greeting input by the user. + + Returns: + int: The value of the greeting based on specific conditions. + - 0 if "hello" is in the greeting. + - 20 if the first character of the greeting is "h". + - 100 for all other cases. + """ + greeting = greeting.lower() # Convert the greeting to lowercase for case-insensitivity + + if "hello" in greeting: + return 0 + elif greeting[0] == "h": # Check if the first character is 'h' + return 20 + else: + return 100 + + +if __name__ == "__main__": + main() diff --git a/solutions/tests/test_bank.py b/solutions/tests/test_bank.py new file mode 100644 index 000000000..e19a92942 --- /dev/null +++ b/solutions/tests/test_bank.py @@ -0,0 +1,29 @@ +from bank import value + +def test_hello(): + """ + Test the 'value' function with the input 'hello' and 'HELLO'. + + This test verifies that both lowercase and uppercase 'hello' return the expected value of 0. + """ + assert value("hello") == 0 # 'hello' should return 0 + assert value("HELLO") == 0 # 'HELLO' should return 0, case-insensitive + + +def test_h(): + """ + Test the 'value' function with the input 'hippy'. + + This test checks that the word 'hippy' returns the correct value of 20. + """ + assert value("hippy") == 20 # 'hippy' should return 20 + + +def test_something(): + """ + Test the 'value' function with the input 'bank' and 'jungkook'. + + This test verifies that the words 'bank' and 'jungkook' both return the expected value of 100. + """ + assert value("bank") == 100 # 'bank' should return 100 + assert value("jungkook") == 100 # 'jungkook' should return 100 From 66559dca83dcb8293881f631d529993ad20f2eb6 Mon Sep 17 00:00:00 2001 From: arvidon Date: Sun, 29 Dec 2024 00:38:34 +0530 Subject: [PATCH 19/74] import value function --- solutions/tests/test_bank.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/tests/test_bank.py b/solutions/tests/test_bank.py index e19a92942..bd3bc22e3 100644 --- a/solutions/tests/test_bank.py +++ b/solutions/tests/test_bank.py @@ -1,4 +1,4 @@ -from bank import value +from solutions.bank import value def test_hello(): """ From 8a927b5486dcbc41bc810dfebd35e04d297106fa Mon Sep 17 00:00:00 2001 From: arvidon Date: Sun, 29 Dec 2024 00:39:57 +0530 Subject: [PATCH 20/74] correct annotation --- solutions/bank.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/bank.py b/solutions/bank.py index d0e51fb2f..20c5dc957 100644 --- a/solutions/bank.py +++ b/solutions/bank.py @@ -1,4 +1,4 @@ -def main() -> None: +def main() """ Main function to get user input and print the value based on the greeting. From 6cc2df32daa0558d6652666855d2401eb143d2ce Mon Sep 17 00:00:00 2001 From: arvidon Date: Sun, 29 Dec 2024 00:46:04 +0530 Subject: [PATCH 21/74] linting --- solutions/bank.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/bank.py b/solutions/bank.py index 20c5dc957..d0e51fb2f 100644 --- a/solutions/bank.py +++ b/solutions/bank.py @@ -1,4 +1,4 @@ -def main() +def main() -> None: """ Main function to get user input and print the value based on the greeting. From 262d61763a2f33bdffd3435ccf587eac51815415 Mon Sep 17 00:00:00 2001 From: arvidon Date: Sun, 29 Dec 2024 01:05:37 +0530 Subject: [PATCH 22/74] Fix code formatting issues --- solutions/bank.py | 11 ++++++----- solutions/tests/test_bank.py | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/solutions/bank.py b/solutions/bank.py index d0e51fb2f..0feeee6df 100644 --- a/solutions/bank.py +++ b/solutions/bank.py @@ -2,8 +2,8 @@ def main() -> None: """ Main function to get user input and print the value based on the greeting. - This function prompts the user for a greeting and then determines and prints the value - associated with that greeting using the `value` function. + This function prompts the user for a greeting and then determines and prints + the value associated with that greeting using the `value` function. """ greeting: str = input("Greetings: ") # Get user input as a string print(value(greeting)) # Call the value function and print its result @@ -13,9 +13,10 @@ def value(greeting: str) -> int: """ Determine the value of a greeting based on certain conditions. - This function returns an integer value based on the provided greeting. If the greeting - contains the word "hello", the value is 0. If the first character of the greeting is "h", - the value is 20. Otherwise, the value is 100. + This function returns an integer value based on the provided greeting. If + the greeting contains the word "hello", the value is 0. If the first + character of the greeting is "h", the value is 20. Otherwise, the value + is 100. Parameters: greeting (str): The greeting input by the user. diff --git a/solutions/tests/test_bank.py b/solutions/tests/test_bank.py index bd3bc22e3..de63dbc1d 100644 --- a/solutions/tests/test_bank.py +++ b/solutions/tests/test_bank.py @@ -1,29 +1,32 @@ from solutions.bank import value -def test_hello(): + +def test_hello() -> None: """ Test the 'value' function with the input 'hello' and 'HELLO'. - - This test verifies that both lowercase and uppercase 'hello' return the expected value of 0. + + This test verifies that both lowercase and uppercase 'hello' return the expected + value of 0. """ assert value("hello") == 0 # 'hello' should return 0 assert value("HELLO") == 0 # 'HELLO' should return 0, case-insensitive -def test_h(): +def test_h() -> None: """ Test the 'value' function with the input 'hippy'. - + This test checks that the word 'hippy' returns the correct value of 20. """ assert value("hippy") == 20 # 'hippy' should return 20 -def test_something(): +def test_something() -> None: """ Test the 'value' function with the input 'bank' and 'jungkook'. - - This test verifies that the words 'bank' and 'jungkook' both return the expected value of 100. + + This test verifies that the words 'bank' and 'jungkook' both return the expected + value of 100. """ assert value("bank") == 100 # 'bank' should return 100 assert value("jungkook") == 100 # 'jungkook' should return 100 From ad3a9bbfd567e03b0ddc94aebe224554efa54baa Mon Sep 17 00:00:00 2001 From: arvidon Date: Sun, 29 Dec 2024 01:10:47 +0530 Subject: [PATCH 23/74] fix bank formatting issues --- solutions/bank.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/solutions/bank.py b/solutions/bank.py index 0feeee6df..ec175caf7 100644 --- a/solutions/bank.py +++ b/solutions/bank.py @@ -4,6 +4,9 @@ def main() -> None: This function prompts the user for a greeting and then determines and prints the value associated with that greeting using the `value` function. + + Created on 28-12-2024 + Author: @arvidon """ greeting: str = input("Greetings: ") # Get user input as a string print(value(greeting)) # Call the value function and print its result From 1c3198a5846144f23da61db08854cd21e9cb5e94 Mon Sep 17 00:00:00 2001 From: arvidon Date: Sun, 29 Dec 2024 01:20:33 +0530 Subject: [PATCH 24/74] fixing formatting issues --- solutions/bank.py | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/solutions/bank.py b/solutions/bank.py index ec175caf7..197474214 100644 --- a/solutions/bank.py +++ b/solutions/bank.py @@ -1,3 +1,14 @@ +""" +A module for checking the value of a greeting. + +Module contents: + - main: Gets user input and prints the value based on the greeting. + - value: Determines the value of the greeting based on certain conditions. + +Created on 28-12-2024 +@author: @arvidon +""" + def main() -> None: """ Main function to get user input and print the value based on the greeting. @@ -7,6 +18,17 @@ def main() -> None: Created on 28-12-2024 Author: @arvidon + + Examples: + >>> main() + Greetings: hello + 0 + >>> main() + Greetings: hi + 20 + >>> main() + Greetings: hey + 20 """ greeting: str = input("Greetings: ") # Get user input as a string print(value(greeting)) # Call the value function and print its result @@ -22,13 +44,23 @@ def value(greeting: str) -> int: is 100. Parameters: - greeting (str): The greeting input by the user. + greeting (str): The greeting input by the user. Returns: - int: The value of the greeting based on specific conditions. - - 0 if "hello" is in the greeting. - - 20 if the first character of the greeting is "h". - - 100 for all other cases. + int: The value of the greeting based on specific conditions. + - 0 if "hello" is in the greeting. + - 20 if the first character of the greeting is "h". + - 100 for all other cases. + + Examples: + >>> value("hello") + 0 + >>> value("hi") + 20 + >>> value("hey") + 20 + >>> value("goodbye") + 100 """ greeting = greeting.lower() # Convert the greeting to lowercase for case-insensitivity From b3f73bf30d8d47742e268fe30dd0ec99e04287dc Mon Sep 17 00:00:00 2001 From: arvidon Date: Sun, 29 Dec 2024 03:27:28 +0530 Subject: [PATCH 25/74] checks passed --- solutions/bank.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/bank.py b/solutions/bank.py index 197474214..5e42b60f2 100644 --- a/solutions/bank.py +++ b/solutions/bank.py @@ -6,7 +6,7 @@ - value: Determines the value of the greeting based on certain conditions. Created on 28-12-2024 -@author: @arvidon +author: @arvidon """ def main() -> None: From 3554ca9467803d0cbadf85842fac11b2d493dd69 Mon Sep 17 00:00:00 2001 From: arvidon Date: Sun, 29 Dec 2024 03:37:13 +0530 Subject: [PATCH 26/74] ruff checks --- solutions/bank.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/solutions/bank.py b/solutions/bank.py index 5e42b60f2..34019acdf 100644 --- a/solutions/bank.py +++ b/solutions/bank.py @@ -5,11 +5,9 @@ - main: Gets user input and prints the value based on the greeting. - value: Determines the value of the greeting based on certain conditions. -Created on 28-12-2024 -author: @arvidon """ -def main() -> None: +def main() : """ Main function to get user input and print the value based on the greeting. From 8b0a22b639c39c5559e04f0251e720072044918a Mon Sep 17 00:00:00 2001 From: arvidon Date: Sun, 29 Dec 2024 03:49:05 +0530 Subject: [PATCH 27/74] ruff modified --- solutions/bank.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/bank.py b/solutions/bank.py index 34019acdf..66a9acdb4 100644 --- a/solutions/bank.py +++ b/solutions/bank.py @@ -15,7 +15,7 @@ def main() : the value associated with that greeting using the `value` function. Created on 28-12-2024 - Author: @arvidon + Author: arvidon Examples: >>> main() From 7fa7539b35bd79bb99b9103b2463e339da045fd3 Mon Sep 17 00:00:00 2001 From: arvidon Date: Sun, 29 Dec 2024 03:58:32 +0530 Subject: [PATCH 28/74] another try --- solutions/bank.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/solutions/bank.py b/solutions/bank.py index 66a9acdb4..960606a85 100644 --- a/solutions/bank.py +++ b/solutions/bank.py @@ -7,7 +7,8 @@ """ -def main() : + +def main(): """ Main function to get user input and print the value based on the greeting. @@ -15,7 +16,7 @@ def main() : the value associated with that greeting using the `value` function. Created on 28-12-2024 - Author: arvidon + Author: Arvidon Examples: >>> main() @@ -60,7 +61,9 @@ def value(greeting: str) -> int: >>> value("goodbye") 100 """ - greeting = greeting.lower() # Convert the greeting to lowercase for case-insensitivity + greeting = ( + greeting.lower() + ) # Convert the greeting to lowercase for case-insensitivity if "hello" in greeting: return 0 From 69862e1335b03b1a9d775a31dc0b18f657036a04 Mon Sep 17 00:00:00 2001 From: Anik Kumar Adhikary Date: Sun, 29 Dec 2024 09:21:52 +0530 Subject: [PATCH 29/74] new branch changes --- .markdownlint.yml | 4 +++ solutions/arith_prog.py | 53 ++++++++++++++++++++++++++++++ solutions/tests/test_arith_prog.py | 38 +++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 solutions/arith_prog.py create mode 100644 solutions/tests/test_arith_prog.py diff --git a/.markdownlint.yml b/.markdownlint.yml index ee6205f5c..b637e5b1d 100644 --- a/.markdownlint.yml +++ b/.markdownlint.yml @@ -1,3 +1,7 @@ ignore: - venv - .github + +MD013: + line_length: 500 + ignore_urls: true diff --git a/solutions/arith_prog.py b/solutions/arith_prog.py new file mode 100644 index 000000000..a75602ab7 --- /dev/null +++ b/solutions/arith_prog.py @@ -0,0 +1,53 @@ +""" +A module that that generates an arithmetic progression (AP). + +Module contents: + - generate_arithmetic_progression generates an arithmetic progression + +Created on 11/25/2024 +@author: Anik Kumar Adhikary +""" + + +def generate_arithmetic_progression(start, difference, terms): + """ + It generates an arithmetic progression given a start value, + a difference, and the number of terms. + + Parameters: + - start (int/float): The first term of the AP. + - difference (int/float): The common difference between terms. + - terms (int): The number of terms to generate. + + Returns: + - list: A list containing the arithmetic progression + + Example: + >>> generate_arithmetic_progression(2, 3, 5) + [2,5,8,11,14] + + Explanation: + start = 2 + + difference = 3 + + terms = 5 + + The range generates the sequence 0, 1, 2, 3, 4. + + For each value of i, we calculate start + i * difference: + + For i = 0: 2 + 0 * 3 = 2 + For i = 1: 2 + 1 * 3 = 5 + For i = 2: 2 + 2 * 3 = 8 + For i = 3: 2 + 3 * 3 = 11 + For i = 4: 2 + 4 * 3 = 14 + + The result is [2, 5, 8, 11, 14], and this is returned by the function + """ + # A concise way to create a list in Python + return [start + i * difference for i in range(terms)] + + +# Expression: start + i * difference; gives the value of the nth term, starting from the first term +# Iteration: for i in range(terms); generates a sequence of numbers from 0 to terms-1 diff --git a/solutions/tests/test_arith_prog.py b/solutions/tests/test_arith_prog.py new file mode 100644 index 000000000..a62acb82a --- /dev/null +++ b/solutions/tests/test_arith_prog.py @@ -0,0 +1,38 @@ +"""unittest code verifies the behavior of the function generate_arithmetic_progression""" + +import unittest + +from solutions.arith_prog import generate_arithmetic_progression + + +class TestArithmeticProgression(unittest.TestCase): + """To test the function generate_arithmetic_progression""" + + def test_positive_difference(self): + """Tests a common positive difference with multiple terms""" + result = generate_arithmetic_progression(2, 3, 5) + self.assertEqual(result, [2, 5, 8, 11, 14]) + + def test_negative_difference(self): + """Tests a negative common difference""" + result = generate_arithmetic_progression(10, -2, 5) + self.assertEqual(result, [10, 8, 6, 4, 2]) + + def test_zero_difference(self): + """Checks if the function handles a zero difference correctly""" + result = generate_arithmetic_progression(7, 0, 4) + self.assertEqual(result, [7, 7, 7, 7]) + + def test_float_values(self): + """Ensures the function works with floating-point values""" + result = generate_arithmetic_progression(1.5, 0.5, 4) + self.assertEqual(result, [1.5, 2.0, 2.5, 3.0]) + + def test_no_terms(self): + """Checks the behavior when the number of terms is zero""" + result = generate_arithmetic_progression(3, 2, 0) + self.assertEqual(result, []) + + +if __name__ == "__main__": + unittest.main() From 41e486b7d1ebb08c5c8b4d387b2045671015f38d Mon Sep 17 00:00:00 2001 From: Shagun <133004326+arvidon@users.noreply.github.com> Date: Mon, 30 Dec 2024 16:54:14 +0530 Subject: [PATCH 30/74] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8605cf81e..62683017b 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,5 @@ ****** -welcome to Pyversity main repository +welcome to Pyversity +main repository From 76c1378e988054d387f20dd361d79baf65ab2e96 Mon Sep 17 00:00:00 2001 From: Shagun <133004326+arvidon@users.noreply.github.com> Date: Mon, 30 Dec 2024 16:54:59 +0530 Subject: [PATCH 31/74] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 62683017b..312ebe261 100644 --- a/README.md +++ b/README.md @@ -2,5 +2,5 @@ ****** -welcome to Pyversity +welcome to Pyversity
main repository From 607ecc3461e42472c63a76e2b49afa122bd8fe4d Mon Sep 17 00:00:00 2001 From: arvidon Date: Wed, 1 Jan 2025 21:15:08 +0530 Subject: [PATCH 32/74] jar --- solutions/jar.py | 100 ++++++++++++++++++++++++++++++++++++ solutions/tests/test_jar.py | 47 +++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 solutions/jar.py create mode 100644 solutions/tests/test_jar.py diff --git a/solutions/jar.py b/solutions/jar.py new file mode 100644 index 000000000..b355dd53e --- /dev/null +++ b/solutions/jar.py @@ -0,0 +1,100 @@ +class Jar: + """ + A class representing a cookie jar with a limited capacity. + + The Jar class allows you to deposit and withdraw cookies, and provides methods + to check the current number of cookies and the jar's capacity. + + Attributes: + capacity (int): The maximum number of cookies the jar can hold. + size (int): The current number of cookies in the jar. + + Methods: + __str__(): Returns a string representation of the jar, showing the current + number of cookies using the "🍪" emoji. + deposit(n): Deposits `n` cookies into the jar, if it does not exceed the capacity. + withdraw(n): Withdraws `n` cookies from the jar, if there are enough cookies available. + + Created On: 01-01-2005 + Author :@arvidon + """ + + def __init__(self, capacity=12): + """ + Initializes a new jar with a specified capacity and zero cookies. + + Args: + capacity (int): The maximum number of cookies the jar can hold. Default is 12. + + Raises: + ValueError: If `capacity` is a negative number. + """ + if capacity < 0: + raise ValueError("Capacity must be a non-negative integer") + self._capacity = capacity + self._cookies = 0 + + def __str__(self): + """ + Returns a string representation of the jar. + + The string consists of "🍪" emojis that represent the current number of cookies. + + Returns: + str: A string showing the current number of cookies in the jar. + """ + return "🍪" * self._cookies + + def deposit(self, n): + """ + Deposits a specified number of cookies into the jar. + + Args: + n (int): The number of cookies to deposit. Must be a positive integer. + + Raises: + ValueError: If `n` is less than or equal to 0. + ValueError: If depositing `n` cookies exceeds the jar's capacity. + """ + if n <= 0: + raise ValueError("Number of cookies to deposit must be positive") + if self._cookies + n > self._capacity: + raise ValueError("Exceeds jar's capacity") + self._cookies += n + + def withdraw(self, n): + """ + Withdraws a specified number of cookies from the jar. + + Args: + n (int): The number of cookies to withdraw. Must be a positive integer. + + Raises: + ValueError: If `n` is less than or equal to 0. + ValueError: If there are not enough cookies in the jar to withdraw the specified number. + """ + if n <= 0: + raise ValueError("Number of cookies to withdraw must be positive") + if self._cookies < n: + raise ValueError("Not enough cookies in the jar") + self._cookies -= n + + @property + def capacity(self): + """ + Returns the maximum capacity of the jar. + + Returns: + int: The capacity of the jar. + """ + return self._capacity + + @property + def size(self): + """ + Returns the current number of cookies in the jar. + + Returns: + int: The current number of cookies. + """ + return self._cookies diff --git a/solutions/tests/test_jar.py b/solutions/tests/test_jar.py new file mode 100644 index 000000000..367c976d0 --- /dev/null +++ b/solutions/tests/test_jar.py @@ -0,0 +1,47 @@ +import pytest +from solutions.jar import Jar + +def test_initialization(): + """Test that the jar is initialized with the correct capacity and zero cookies.""" + jar = Jar(10) + assert jar.capacity == 10 # Ensure capacity is set correctly + assert jar.size == 0 # Ensure size starts at zero + +def test_deposit(): + """Test depositing cookies into the jar.""" + jar = Jar(10) + jar.deposit(5) + assert jar.size == 5 # Ensure size is updated correctly after deposit + jar.deposit(3) + assert jar.size == 8 # Ensure size is updated correctly after another deposit + +def test_capacity_exceeded(): + """Test that depositing more cookies than the jar's capacity raises a ValueError.""" + jar = Jar(3) + with pytest.raises(ValueError): + jar.deposit(4) # Should raise ValueError as the capacity is exceeded + +def test_withdraw(): + """Test withdrawing cookies from the jar.""" + jar = Jar(10) + jar.deposit(5) + jar.withdraw(2) + assert jar.size == 3 # Ensure size is updated correctly after withdrawal + +def test_not_enough_cookies(): + """Test that withdrawing more cookies than available raises a ValueError.""" + jar = Jar(2) + jar.deposit(1) + with pytest.raises(ValueError): + jar.withdraw(3) # Should raise ValueError as not enough cookies are available + +def test_str_representation(): + """Test that the string representation of the jar is correct.""" + jar = Jar(5) + jar.deposit(3) + assert str(jar) == "🍪🍪🍪" # Ensure the string output correctly shows the number of cookies + +def test_invalid_capacity(): + """Test that initializing the jar with a negative capacity raises a ValueError.""" + with pytest.raises(ValueError): + Jar(-2) # Should raise ValueError as the capacity is negative From c0392c8b53909e74a5a23ad37d5721f61a0e9c80 Mon Sep 17 00:00:00 2001 From: arvidon Date: Wed, 1 Jan 2025 21:18:00 +0530 Subject: [PATCH 33/74] reformat test_jar --- solutions/tests/test_jar.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/solutions/tests/test_jar.py b/solutions/tests/test_jar.py index 367c976d0..4f99387f1 100644 --- a/solutions/tests/test_jar.py +++ b/solutions/tests/test_jar.py @@ -1,19 +1,22 @@ import pytest from solutions.jar import Jar + def test_initialization(): """Test that the jar is initialized with the correct capacity and zero cookies.""" jar = Jar(10) - assert jar.capacity == 10 # Ensure capacity is set correctly - assert jar.size == 0 # Ensure size starts at zero + assert jar.capacity == 10 # Ensure capacity is set correctly + assert jar.size == 0 # Ensure size starts at zero + def test_deposit(): """Test depositing cookies into the jar.""" jar = Jar(10) jar.deposit(5) - assert jar.size == 5 # Ensure size is updated correctly after deposit + assert jar.size == 5 # Ensure size is updated correctly after deposit jar.deposit(3) - assert jar.size == 8 # Ensure size is updated correctly after another deposit + assert jar.size == 8 # Ensure size is updated correctly after another deposit + def test_capacity_exceeded(): """Test that depositing more cookies than the jar's capacity raises a ValueError.""" @@ -21,12 +24,14 @@ def test_capacity_exceeded(): with pytest.raises(ValueError): jar.deposit(4) # Should raise ValueError as the capacity is exceeded + def test_withdraw(): """Test withdrawing cookies from the jar.""" jar = Jar(10) jar.deposit(5) jar.withdraw(2) - assert jar.size == 3 # Ensure size is updated correctly after withdrawal + assert jar.size == 3 # Ensure size is updated correctly after withdrawal + def test_not_enough_cookies(): """Test that withdrawing more cookies than available raises a ValueError.""" @@ -35,11 +40,15 @@ def test_not_enough_cookies(): with pytest.raises(ValueError): jar.withdraw(3) # Should raise ValueError as not enough cookies are available + def test_str_representation(): """Test that the string representation of the jar is correct.""" jar = Jar(5) jar.deposit(3) - assert str(jar) == "🍪🍪🍪" # Ensure the string output correctly shows the number of cookies + assert ( + str(jar) == "🍪🍪🍪" + ) # Ensure the string output correctly shows the number of cookies + def test_invalid_capacity(): """Test that initializing the jar with a negative capacity raises a ValueError.""" From b418f54f54d02b47d2f35ce0df5d9007fc7feb8f Mon Sep 17 00:00:00 2001 From: arvidon Date: Wed, 1 Jan 2025 21:45:36 +0530 Subject: [PATCH 34/74] pytest --- solutions/tests/test_jar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/tests/test_jar.py b/solutions/tests/test_jar.py index 4f99387f1..22ba079c1 100644 --- a/solutions/tests/test_jar.py +++ b/solutions/tests/test_jar.py @@ -3,7 +3,7 @@ def test_initialization(): - """Test that the jar is initialized with the correct capacity and zero cookies.""" + """Testing that the jar is initialized with the correct capacity and zero cookies.""" jar = Jar(10) assert jar.capacity == 10 # Ensure capacity is set correctly assert jar.size == 0 # Ensure size starts at zero From a735bb1c4184acc7cc25e9cfe4db09ebeeaad667 Mon Sep 17 00:00:00 2001 From: arvidon Date: Wed, 1 Jan 2025 21:58:24 +0530 Subject: [PATCH 35/74] plates --- solutions/jar.py | 100 --------------------------------- solutions/plates.py | 72 ++++++++++++++++++++++++ solutions/tests/test_jar.py | 56 ------------------ solutions/tests/test_plates.py | 55 ++++++++++++++++++ 4 files changed, 127 insertions(+), 156 deletions(-) delete mode 100644 solutions/jar.py create mode 100644 solutions/plates.py delete mode 100644 solutions/tests/test_jar.py create mode 100644 solutions/tests/test_plates.py diff --git a/solutions/jar.py b/solutions/jar.py deleted file mode 100644 index b355dd53e..000000000 --- a/solutions/jar.py +++ /dev/null @@ -1,100 +0,0 @@ -class Jar: - """ - A class representing a cookie jar with a limited capacity. - - The Jar class allows you to deposit and withdraw cookies, and provides methods - to check the current number of cookies and the jar's capacity. - - Attributes: - capacity (int): The maximum number of cookies the jar can hold. - size (int): The current number of cookies in the jar. - - Methods: - __str__(): Returns a string representation of the jar, showing the current - number of cookies using the "🍪" emoji. - deposit(n): Deposits `n` cookies into the jar, if it does not exceed the capacity. - withdraw(n): Withdraws `n` cookies from the jar, if there are enough cookies available. - - Created On: 01-01-2005 - Author :@arvidon - """ - - def __init__(self, capacity=12): - """ - Initializes a new jar with a specified capacity and zero cookies. - - Args: - capacity (int): The maximum number of cookies the jar can hold. Default is 12. - - Raises: - ValueError: If `capacity` is a negative number. - """ - if capacity < 0: - raise ValueError("Capacity must be a non-negative integer") - self._capacity = capacity - self._cookies = 0 - - def __str__(self): - """ - Returns a string representation of the jar. - - The string consists of "🍪" emojis that represent the current number of cookies. - - Returns: - str: A string showing the current number of cookies in the jar. - """ - return "🍪" * self._cookies - - def deposit(self, n): - """ - Deposits a specified number of cookies into the jar. - - Args: - n (int): The number of cookies to deposit. Must be a positive integer. - - Raises: - ValueError: If `n` is less than or equal to 0. - ValueError: If depositing `n` cookies exceeds the jar's capacity. - """ - if n <= 0: - raise ValueError("Number of cookies to deposit must be positive") - if self._cookies + n > self._capacity: - raise ValueError("Exceeds jar's capacity") - self._cookies += n - - def withdraw(self, n): - """ - Withdraws a specified number of cookies from the jar. - - Args: - n (int): The number of cookies to withdraw. Must be a positive integer. - - Raises: - ValueError: If `n` is less than or equal to 0. - ValueError: If there are not enough cookies in the jar to withdraw the specified number. - """ - if n <= 0: - raise ValueError("Number of cookies to withdraw must be positive") - if self._cookies < n: - raise ValueError("Not enough cookies in the jar") - self._cookies -= n - - @property - def capacity(self): - """ - Returns the maximum capacity of the jar. - - Returns: - int: The capacity of the jar. - """ - return self._capacity - - @property - def size(self): - """ - Returns the current number of cookies in the jar. - - Returns: - int: The current number of cookies. - """ - return self._cookies diff --git a/solutions/plates.py b/solutions/plates.py new file mode 100644 index 000000000..da5ac1efd --- /dev/null +++ b/solutions/plates.py @@ -0,0 +1,72 @@ +def main(): + """ + + Created On: 2025-01-01 + Author: @arvidon + + + Main function that takes user input and checks if the input is a valid license plate. + It calls the `is_valid` function to determine whether the provided text follows the required format. + + The format is: + - Must start with at least two letters. + - Length of the plate should be between 2 and 6 characters. + - No numbers in between the plate, and the first number must not be '0'. + - The plate must be alphanumeric. + """ + # Prompt the user to input a license plate string + text = input("Text: ") + + # Check if the license plate string is valid + if is_valid(text): + print("True") + else: + print("False") + + +def is_valid(s): + """ + Validates a license plate string based on several conditions: + 1. The plate must start with at least two letters. + 2. The length of the plate must be between 2 and 6 characters. + 3. The first number (if any) must not be '0'. + 4. Numbers should not appear between letters. + 5. The plate should only contain alphanumeric characters (letters and numbers). + + Args: + s (str): The license plate string to be validated. + + Returns: + bool: True if the plate is valid, False otherwise. + """ + # Plates should start with at least two letters + if len(s) < 2 or not s[:2].isalpha(): + return False + + # The length of the plate should be between 2 and 6 characters + if len(s) < 2 or len(s) > 6: + return False + + # The first number (if any) should not be 0, and there should be no numbers in between + temp = 0 + for i in range(3): + if s[(len(s)-1)-i].isalpha(): + if s[(len(s)-i-1)-1].isnumeric(): + temp += 1 + if temp > 0: + return False + if temp == 0: + for j in range(len(s)-1): + if s[j].isalpha(): + if s[j+1] == "0": + return False + + # The plate should contain only alphanumeric characters + if not s.isalnum(): + return False + + return True + + +if __name__ == "__main__": + main() diff --git a/solutions/tests/test_jar.py b/solutions/tests/test_jar.py deleted file mode 100644 index 22ba079c1..000000000 --- a/solutions/tests/test_jar.py +++ /dev/null @@ -1,56 +0,0 @@ -import pytest -from solutions.jar import Jar - - -def test_initialization(): - """Testing that the jar is initialized with the correct capacity and zero cookies.""" - jar = Jar(10) - assert jar.capacity == 10 # Ensure capacity is set correctly - assert jar.size == 0 # Ensure size starts at zero - - -def test_deposit(): - """Test depositing cookies into the jar.""" - jar = Jar(10) - jar.deposit(5) - assert jar.size == 5 # Ensure size is updated correctly after deposit - jar.deposit(3) - assert jar.size == 8 # Ensure size is updated correctly after another deposit - - -def test_capacity_exceeded(): - """Test that depositing more cookies than the jar's capacity raises a ValueError.""" - jar = Jar(3) - with pytest.raises(ValueError): - jar.deposit(4) # Should raise ValueError as the capacity is exceeded - - -def test_withdraw(): - """Test withdrawing cookies from the jar.""" - jar = Jar(10) - jar.deposit(5) - jar.withdraw(2) - assert jar.size == 3 # Ensure size is updated correctly after withdrawal - - -def test_not_enough_cookies(): - """Test that withdrawing more cookies than available raises a ValueError.""" - jar = Jar(2) - jar.deposit(1) - with pytest.raises(ValueError): - jar.withdraw(3) # Should raise ValueError as not enough cookies are available - - -def test_str_representation(): - """Test that the string representation of the jar is correct.""" - jar = Jar(5) - jar.deposit(3) - assert ( - str(jar) == "🍪🍪🍪" - ) # Ensure the string output correctly shows the number of cookies - - -def test_invalid_capacity(): - """Test that initializing the jar with a negative capacity raises a ValueError.""" - with pytest.raises(ValueError): - Jar(-2) # Should raise ValueError as the capacity is negative diff --git a/solutions/tests/test_plates.py b/solutions/tests/test_plates.py new file mode 100644 index 000000000..81a409ff0 --- /dev/null +++ b/solutions/tests/test_plates.py @@ -0,0 +1,55 @@ +from solutions.plates import is_valid + +def test_normal(): + """ + Test cases for normal, valid license plates that meet the basic rules. + """ + assert is_valid("CS50") == True # Starts with two letters, followed by numbers, valid format + assert is_valid("JK") == True # Only two letters, valid format + + +def test_len(): + """ + Test case for invalid license plates that exceed the length limit. + """ + assert is_valid("whatisthis") == False # Plate exceeds 6 characters, invalid + + +def test_zero_between(): + """ + Test cases where numbers (particularly '0') appear inappropriately between letters. + """ + assert is_valid("hi0012") == False # '0' appears in between letters, invalid + assert is_valid("xz4yz0") == False # '0' appears after letters, invalid + + +def test_capital(): + """ + Test cases for valid license plates with uppercase letters and numbers. + """ + assert is_valid("AB1900") == True # Starts with letters, then numbers, valid format + assert is_valid("COOKIE") == True # Only letters, valid format + + +def test_firstnum_zero(): + """ + Test case where the first number is '0', which is invalid. + """ + assert is_valid("0CS90") == False # Starts with '0', invalid + + +def test_no_punctuation(): + """ + Test cases where the plate includes invalid punctuation characters. + """ + assert is_valid("xx,.&!") == False # Contains punctuation, invalid + assert is_valid(".kook12!") == False # Contains punctuation, invalid + + +def test_first_two_alpha(): + """ + Test cases where the first two characters are not letters or are invalid. + """ + assert is_valid("s1hag") == False # First character is a number, invalid + assert is_valid("00nod") == False # Starts with '0', invalid + assert is_valid("8805") == False # Does not start with letters, invalid From 4b645d3378c1bea2664536fdbef3b953416c6837 Mon Sep 17 00:00:00 2001 From: arvidon Date: Wed, 1 Jan 2025 22:19:01 +0530 Subject: [PATCH 36/74] Formatted --- solutions/plates.py | 12 ++++++------ solutions/tests/test_plates.py | 29 +++++++++++++++-------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/solutions/plates.py b/solutions/plates.py index da5ac1efd..98435105c 100644 --- a/solutions/plates.py +++ b/solutions/plates.py @@ -4,7 +4,7 @@ def main(): Created On: 2025-01-01 Author: @arvidon - + Main function that takes user input and checks if the input is a valid license plate. It calls the `is_valid` function to determine whether the provided text follows the required format. @@ -16,7 +16,7 @@ def main(): """ # Prompt the user to input a license plate string text = input("Text: ") - + # Check if the license plate string is valid if is_valid(text): print("True") @@ -50,15 +50,15 @@ def is_valid(s): # The first number (if any) should not be 0, and there should be no numbers in between temp = 0 for i in range(3): - if s[(len(s)-1)-i].isalpha(): - if s[(len(s)-i-1)-1].isnumeric(): + if s[(len(s) - 1) - i].isalpha(): + if s[(len(s) - i - 1) - 1].isnumeric(): temp += 1 if temp > 0: return False if temp == 0: - for j in range(len(s)-1): + for j in range(len(s) - 1): if s[j].isalpha(): - if s[j+1] == "0": + if s[j + 1] == "0": return False # The plate should contain only alphanumeric characters diff --git a/solutions/tests/test_plates.py b/solutions/tests/test_plates.py index 81a409ff0..5c611847b 100644 --- a/solutions/tests/test_plates.py +++ b/solutions/tests/test_plates.py @@ -1,55 +1,56 @@ from solutions.plates import is_valid + def test_normal(): """ - Test cases for normal, valid license plates that meet the basic rules. + Test case for valid license plates """ - assert is_valid("CS50") == True # Starts with two letters, followed by numbers, valid format - assert is_valid("JK") == True # Only two letters, valid format + assert is_valid("CS50") is True # Starts with two letters, followed by numbers, valid format + assert is_valid("JK") is True # Only two letters, valid format def test_len(): """ Test case for invalid license plates that exceed the length limit. """ - assert is_valid("whatisthis") == False # Plate exceeds 6 characters, invalid + assert is_valid("whatisthis") is False # Plate exceeds 6 characters, invalid def test_zero_between(): """ Test cases where numbers (particularly '0') appear inappropriately between letters. """ - assert is_valid("hi0012") == False # '0' appears in between letters, invalid - assert is_valid("xz4yz0") == False # '0' appears after letters, invalid + assert is_valid("hi0012") is False # '0' appears in between letters, invalid + assert is_valid("xz4yz0") is False # '0' appears after letters, invalid def test_capital(): """ Test cases for valid license plates with uppercase letters and numbers. """ - assert is_valid("AB1900") == True # Starts with letters, then numbers, valid format - assert is_valid("COOKIE") == True # Only letters, valid format + assert is_valid("AB1900") is True # Starts with letters, then numbers, valid format + assert is_valid("COOKIE") is True # Only letters, valid format def test_firstnum_zero(): """ Test case where the first number is '0', which is invalid. """ - assert is_valid("0CS90") == False # Starts with '0', invalid + assert is_valid("0CS90") is False # Starts with '0', invalid def test_no_punctuation(): """ Test cases where the plate includes invalid punctuation characters. """ - assert is_valid("xx,.&!") == False # Contains punctuation, invalid - assert is_valid(".kook12!") == False # Contains punctuation, invalid + assert is_valid("xx,.&!") is False # Contains punctuation, invalid + assert is_valid(".kook12!") is False # Contains punctuation, invalid def test_first_two_alpha(): """ Test cases where the first two characters are not letters or are invalid. """ - assert is_valid("s1hag") == False # First character is a number, invalid - assert is_valid("00nod") == False # Starts with '0', invalid - assert is_valid("8805") == False # Does not start with letters, invalid + assert is_valid("s1hag") is False # First character is a number, invalid + assert is_valid("00nod") is False # Starts with '0', invalid + assert is_valid("8805") is False # Does not start with letters, invalid From a14071f536c568f1a8c69f2ce4c0fa50cad79290 Mon Sep 17 00:00:00 2001 From: arvidon Date: Wed, 1 Jan 2025 22:20:45 +0530 Subject: [PATCH 37/74] reformatted --- solutions/tests/test_plates.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/solutions/tests/test_plates.py b/solutions/tests/test_plates.py index 5c611847b..85da75a23 100644 --- a/solutions/tests/test_plates.py +++ b/solutions/tests/test_plates.py @@ -5,8 +5,10 @@ def test_normal(): """ Test case for valid license plates """ - assert is_valid("CS50") is True # Starts with two letters, followed by numbers, valid format - assert is_valid("JK") is True # Only two letters, valid format + assert ( + is_valid("CS50") is True + ) # Starts with two letters, followed by numbers, valid format + assert is_valid("JK") is True # Only two letters, valid format def test_len(): @@ -53,4 +55,4 @@ def test_first_two_alpha(): """ assert is_valid("s1hag") is False # First character is a number, invalid assert is_valid("00nod") is False # Starts with '0', invalid - assert is_valid("8805") is False # Does not start with letters, invalid + assert is_valid("8805") is False # Does not start with letters, invalid From 983750d1dc6df1ba7ec8eb8ebf444a637051f686 Mon Sep 17 00:00:00 2001 From: Shagun <133004326+arvidon@users.noreply.github.com> Date: Wed, 1 Jan 2025 22:40:12 +0530 Subject: [PATCH 38/74] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 312ebe261..62683017b 100644 --- a/README.md +++ b/README.md @@ -2,5 +2,5 @@ ****** -welcome to Pyversity
+welcome to Pyversity main repository From af171bbff608b3f6236f541f0a068090baa9fa99 Mon Sep 17 00:00:00 2001 From: Shagun <133004326+arvidon@users.noreply.github.com> Date: Wed, 1 Jan 2025 22:42:20 +0530 Subject: [PATCH 39/74] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 62683017b..8605cf81e 100644 --- a/README.md +++ b/README.md @@ -2,5 +2,4 @@ ****** -welcome to Pyversity -main repository +welcome to Pyversity main repository From ad1d8cc5a2b0ad970415220329c556aa80142622 Mon Sep 17 00:00:00 2001 From: muqaddas96 Date: Tue, 7 Jan 2025 16:59:45 +0300 Subject: [PATCH 40/74] added collaboration files --- collaboration/communication.md | 37 ++++++++++++++++++++++++--------- collaboration/constraints.md | 5 ++++- collaboration/learning_goals.md | 11 ++++++++++ 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/collaboration/communication.md b/collaboration/communication.md index 484652e0f..0de7139b8 100644 --- a/collaboration/communication.md +++ b/collaboration/communication.md @@ -14,16 +14,26 @@ ______________________________________________________________________ ## Communication Schedule | Day | How | The topic of discussion | | --- | :-: | ----------------------- | -| | | | +| 21st Dec | Zoom | How to proceed with the group project? | +| 25th Dec | Zoom | Progress and Discussions on Solutions | +| 7th Jan | Zoom | Finalization | +| 8th Jan | Zoom | Merging | ## Communication Channels -how often will we get in touch on each channel, and what we will discuss there: +We shall have weekly/bi-weekly meetings on slcka/zoom to discuss any issues and progress. - **Issues**: +https://github.com/MIT-Emerging-Talent/ET6-foundations-group-29/issues/3 +https://github.com/MIT-Emerging-Talent/ET6-foundations-group-29/issues/10 +https://github.com/MIT-Emerging-Talent/ET6-foundations-group-29/issues/2 + - **Pull Requests**: -- **Slack/Discord**: -- **Video Calls**: +https://github.com/MIT-Emerging-Talent/ET6-foundations-group-29/pull/9 +https://github.com/MIT-Emerging-Talent/ET6-foundations-group-29/pull/8 +https://github.com/MIT-Emerging-Talent/ET6-foundations-group-29/pull/7 +https://github.com/MIT-Emerging-Talent/ET6-foundations-group-29/pull/5 +https://github.com/MIT-Emerging-Talent/ET6-foundations-group-29/pull/1 ______________________________________________________________________ @@ -33,15 +43,22 @@ ______________________________________________________________________ | Day | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday | | ------ | :----: | :-----: | :-------: | :------: | :----: | :------: | :----: | -| _name_ | | | | | | | | +| Muqaddas | No | No | No | No | Yes | No | Yes | +| Nilofar | No | Yes | No | No | Yes | No | Yes | +| Shagun | No | No | No | No | Yes | No | Yes | +| Anik | No | No | No | No | Yes | No | Yes | +| Momtaz | No | No | No | No | Yes | No | Yes | +| M. Ahmed | No | No | No | No | Yes | No | Yes | + ### How many hours everyone has per day -- name: _5h_; -- name: _6h_; -- name: _5h_; -- name: _4h_; -- name: _3h_; +- Muqaddas: _1.5h_; +- Shagun: _2h_; +- Nilofar: _2h_; +- Anik: _2h_; +- M. Ahmed: _2h_; +- Momtaz: _2h_; ## Asking for Help diff --git a/collaboration/constraints.md b/collaboration/constraints.md index 24079505c..fe64991d6 100644 --- a/collaboration/constraints.md +++ b/collaboration/constraints.md @@ -5,6 +5,7 @@ Some boundaries around our project. ## External +The project must be completed by 8th Jan 2025. ## Internal: Involuntary - +Team members have varying levels of experience with Python, requiring additional time for learning. ## Internal: Voluntary +Every pull request must pass a peer code review before merging. +Agree to use GitHub for version control and task management. ## Internal: Involuntary + Team members have varying levels of experience with Python, requiring additional time for learning. ## Internal: Voluntary + Every pull request must pass a peer code review before merging. Agree to use GitHub for version control and task management. diff --git a/collaboration/learning_goals.md b/collaboration/learning_goals.md index 3fd60e4a9..4ec077274 100644 --- a/collaboration/learning_goals.md +++ b/collaboration/learning_goals.md @@ -1,6 +1,7 @@ # Learning Goals ## Collective + The collective learning goals for a beginner group learning Python include understanding basic syntax, data types, and control structures, along with practicing functions, loops, and error handling. Learners @@ -8,9 +9,10 @@ will also explore data structures, file handling, and an introduction to object-oriented programming to build a solid foundation for coding. ## Individual + Muqaddas: To learn new data science skills. Nilofar: To learn about github and how the coding collaboration works. Shagun: To learn how to effectively collaborate and documentation. Anik: To leanr unit testing and predictive testing. -Momtaz: -M. Ahmed: +Momtaz: +M. Ahmed: From 31395868cde75fcb51bed035046bd21d652af236 Mon Sep 17 00:00:00 2001 From: Muhammad Muqaddas Rehman <167186162+muqaddas96@users.noreply.github.com> Date: Wed, 8 Jan 2025 16:32:04 +0300 Subject: [PATCH 43/74] Update bank.py --- solutions/bank.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/solutions/bank.py b/solutions/bank.py index 960606a85..bc0f03b23 100644 --- a/solutions/bank.py +++ b/solutions/bank.py @@ -4,6 +4,8 @@ Module contents: - main: Gets user input and prints the value based on the greeting. - value: Determines the value of the greeting based on certain conditions. +Created on: 1st Jan 2025 +@author: Shagun """ From 51b53e28914eb41ded96e197c6041198229e8394 Mon Sep 17 00:00:00 2001 From: Muhammad Muqaddas Rehman <167186162+muqaddas96@users.noreply.github.com> Date: Wed, 8 Jan 2025 16:33:23 +0300 Subject: [PATCH 44/74] Update bank.py --- solutions/bank.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/bank.py b/solutions/bank.py index bc0f03b23..970cafa37 100644 --- a/solutions/bank.py +++ b/solutions/bank.py @@ -5,7 +5,7 @@ - main: Gets user input and prints the value based on the greeting. - value: Determines the value of the greeting based on certain conditions. Created on: 1st Jan 2025 -@author: Shagun +@author: arvidon """ From 02fc608adbee6bb5c00eedd1062ab45d5b9eb0b7 Mon Sep 17 00:00:00 2001 From: muqaddas96 Date: Fri, 10 Jan 2025 16:14:38 +0300 Subject: [PATCH 45/74] Updated Retro --- collaboration/retrospective.md | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/collaboration/retrospective.md b/collaboration/retrospective.md index 74e18813b..d8422aa30 100644 --- a/collaboration/retrospective.md +++ b/collaboration/retrospective.md @@ -4,20 +4,63 @@ ## Stop Doing +Spending too much time trying to figure +things out on my own without asking for help sooner. +Overthinking small tasks instead of +just starting and learning along the way. + ## Continue Doing +Working step by step and focusing on +one part of the task at a time. +Asking my teammates for advice and +reviewing their work to learn from them. +Using GitHub features like branches +and pull requests to stay organized. + ## Start Doing +Practicing math and coding challenges +more often so I can solve them faster in the future. +Writing down notes about what I’m +learning so I can remember it for next time. +Paying more attention to small +details in documentation and instructions. + ## Lessons Learned +I realized that working in a team +helps a lot, especially when I don’t know something. +GitHub tools like pull requests and +labels are very useful once you understand how to use them. +Breaking the project into small steps +makes everything easier and less stressful. + ______________________________________________________________________ ## Strategy vs. Board ### What parts of your plan went as expected? +I was able to clone the repository, +create my branch, and push my code. +Submitting a pull request and reviewing +others’ work was smooth and worked as planned. + ### What parts of your plan did not work out? +Some of the math problems were harder than +I expected, and I had to spend extra time on them. +I didn’t fully understand the CI checks at +first, so fixing errors took more time. + ### Did you need to add things that weren't in your strategy? +Yes, I had to look up tutorials on GitHub +features like labeling pull requests and managing CI errors. + ### Or remove extra steps? + +I simplified things by focusing only on the steps +needed to complete the assignment and skipping +any unnecessary experiments with GitHub. From 628440ee82cd7cc3a83f34fef8ab6e4f1870347f Mon Sep 17 00:00:00 2001 From: Mohammad Ahmadi Date: Fri, 10 Jan 2025 20:40:26 +0430 Subject: [PATCH 46/74] test_max_number --- solutions/find_largest_number.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 solutions/find_largest_number.py diff --git a/solutions/find_largest_number.py b/solutions/find_largest_number.py new file mode 100644 index 000000000..c172074b6 --- /dev/null +++ b/solutions/find_largest_number.py @@ -0,0 +1,7 @@ +# Function to Find the Largest Number + +def largest_number(numbers): + return max(numbers) + +numbers = [1,2,3,4,5,12,8] +print(f"This is the largest number {largest_number(numbers)}") \ No newline at end of file From c11c60dbf3a110562c5559e74395eb22d4dd8fba Mon Sep 17 00:00:00 2001 From: Mohammad Ahmadi Date: Fri, 10 Jan 2025 21:15:40 +0430 Subject: [PATCH 47/74] largest --- solutions/find_largest_number.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/solutions/find_largest_number.py b/solutions/find_largest_number.py index c172074b6..328de3bb4 100644 --- a/solutions/find_largest_number.py +++ b/solutions/find_largest_number.py @@ -1,7 +1,9 @@ -# Function to Find the Largest Number +""" Function to Find the Largest Number +@author: msrak +""" def largest_number(numbers): return max(numbers) -numbers = [1,2,3,4,5,12,8] +numbers = [1,2,3,4,21,12,8] print(f"This is the largest number {largest_number(numbers)}") \ No newline at end of file From d3498d2a17e11fc813bf8dcbb1bf9e6d193ad10f Mon Sep 17 00:00:00 2001 From: Nilofar Nikzad Date: Sat, 11 Jan 2025 16:43:58 +0430 Subject: [PATCH 48/74] Create nilofar_solution.py --- solutions/nilofar_solution.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 solutions/nilofar_solution.py diff --git a/solutions/nilofar_solution.py b/solutions/nilofar_solution.py new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/solutions/nilofar_solution.py @@ -0,0 +1 @@ + From 416dad3690c05dc7d062ba4a70b5bdd2f1ce5e5b Mon Sep 17 00:00:00 2001 From: Nilofar Nikzad Date: Sat, 11 Jan 2025 17:08:05 +0430 Subject: [PATCH 49/74] Create nilofar_test_bmi.py --- solutions/nilofar_test_bmi.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 solutions/nilofar_test_bmi.py diff --git a/solutions/nilofar_test_bmi.py b/solutions/nilofar_test_bmi.py new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/solutions/nilofar_test_bmi.py @@ -0,0 +1 @@ + From 9b3b40faba52d3947e516379a201154713a5de1a Mon Sep 17 00:00:00 2001 From: Nilofar Nikzad Date: Sat, 11 Jan 2025 17:11:43 +0430 Subject: [PATCH 50/74] nilofar_test_bmi.py --- solutions/nilofar_test_bmi.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/solutions/nilofar_test_bmi.py b/solutions/nilofar_test_bmi.py index 8b1378917..3319e02d3 100644 --- a/solutions/nilofar_test_bmi.py +++ b/solutions/nilofar_test_bmi.py @@ -1 +1,19 @@ +import unittest +from nilfersolution import calculate_bmi # Import the function from the solution file +class TestBMICalculator(unittest.TestCase): + def test_underweight(self): + self.assertEqual(calculate_bmi(45, 1.7), "Underweight (BMI: 15.57)") + + def test_normal_weight(self): + self.assertEqual(calculate_bmi(68, 1.75), "Normal weight (BMI: 22.20)") + + def test_overweight(self): + self.assertEqual(calculate_bmi(80, 1.7), "Overweight (BMI: 27.68)") + + def test_obesity(self): + self.assertEqual(calculate_bmi(95, 1.6), "Obesity (BMI: 37.11)") + + def test_invalid_input(self): + self.assertEqual(calculate_bmi(-45, 1.7), "Invalid input. Height and weight must be greater than zero.") + self.assertEqual(calculate_bmi(50, 0), "Invalid input. Height and weight must be greater than zero.") From 4f9a8365270fae9b85d2e1f9d65fb126ac25eb78 Mon Sep 17 00:00:00 2001 From: Nilofar Nikzad Date: Sat, 11 Jan 2025 18:14:02 +0430 Subject: [PATCH 51/74] nilofar_solution.py --- solutions/nilofar_solution.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/solutions/nilofar_solution.py b/solutions/nilofar_solution.py index 8b1378917..fd33d1cd1 100644 --- a/solutions/nilofar_solution.py +++ b/solutions/nilofar_solution.py @@ -1 +1,21 @@ - +def calculate_bmi(weight, height): + """ + This function calculates the Body Mass Index (BMI) based on weight (in kilograms) + and height (in meters). + :param weight: float + :param height: float + :return: str + """ + if height <= 0 or weight <= 0: + return "Invalid input. Height and weight must be greater than zero." + + bmi = weight / (height ** 2) + + if bmi < 18.5: + return f"Underweight (BMI: {bmi:.2f})" + elif 18.5 <= bmi < 24.9: + return f"Normal weight (BMI: {bmi:.2f})" + elif 25 <= bmi < 29.9: + return f"Overweight (BMI: {bmi:.2f})" + else: + return f"Obesity (BMI: {bmi:.2f})" From 691f896968f7f6627926753d8960f8a744105cfe Mon Sep 17 00:00:00 2001 From: Momtaz Yaqubi Date: Sat, 11 Jan 2025 18:22:08 +0430 Subject: [PATCH 52/74] Update learning_goals.md --- collaboration/learning_goals.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collaboration/learning_goals.md b/collaboration/learning_goals.md index 4ec077274..919e62877 100644 --- a/collaboration/learning_goals.md +++ b/collaboration/learning_goals.md @@ -14,5 +14,5 @@ Muqaddas: To learn new data science skills. Nilofar: To learn about github and how the coding collaboration works. Shagun: To learn how to effectively collaborate and documentation. Anik: To leanr unit testing and predictive testing. -Momtaz: +Momtaz: Learning how to collaborate as a team, working on the same project together M. Ahmed: From aa41803e9e00e8914c7abd61ea8c4beb3c18d46d Mon Sep 17 00:00:00 2001 From: Momtaz Yaqubi Date: Sat, 11 Jan 2025 18:24:07 +0430 Subject: [PATCH 53/74] Update learning_goals.md --- collaboration/learning_goals.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/collaboration/learning_goals.md b/collaboration/learning_goals.md index 919e62877..ed653ee2c 100644 --- a/collaboration/learning_goals.md +++ b/collaboration/learning_goals.md @@ -11,8 +11,14 @@ introduction to object-oriented programming to build a solid foundation for codi ## Individual Muqaddas: To learn new data science skills. + Nilofar: To learn about github and how the coding collaboration works. + Shagun: To learn how to effectively collaborate and documentation. -Anik: To leanr unit testing and predictive testing. -Momtaz: Learning how to collaborate as a team, working on the same project together -M. Ahmed: + +Anik: To learn unit testing and predictive testing. + +Momtaz: Learning how to collaborate as a team, working on the same project together. + +M. Ahmed: To learn how to use GitHub as a team. + From e345fe8004179f3c0caa83325944a7aeb4964525 Mon Sep 17 00:00:00 2001 From: Nilofar Nikzad Date: Sat, 11 Jan 2025 19:13:12 +0430 Subject: [PATCH 54/74] nilofar_test_water.py --- solutions/nilofar_test_water.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 solutions/nilofar_test_water.py diff --git a/solutions/nilofar_test_water.py b/solutions/nilofar_test_water.py new file mode 100644 index 000000000..5324b202f --- /dev/null +++ b/solutions/nilofar_test_water.py @@ -0,0 +1,19 @@ +import pytest +from nilofar_water_intake import calculate_water_intake + +def test_low_activity_temperate(): + assert calculate_water_intake(70, "Low", "Temperate") == 2.31 + +def test_moderate_activity_hot(): + assert calculate_water_intake(70, "Moderate", "Hot") == 3.31 + +def test_high_activity_cold(): + assert calculate_water_intake(70, "High", "Cold") == 3.13 + +def test_invalid_activity(): + with pytest.raises(ValueError): + calculate_water_intake(70, "Extreme", "Temperate") + +def test_invalid_weight(): + with pytest.raises(ValueError): + calculate_water_intake(-10, "Low", "Temperate") From bad4322c30a02d85d58ccd2032f177086e976a71 Mon Sep 17 00:00:00 2001 From: Momtaz Date: Sat, 11 Jan 2025 19:36:31 +0430 Subject: [PATCH 55/74] solution added --- .vscode/settings.json | 5 ++++- solutions/__init__.py | 0 solutions/add_numbers.py | 17 +++++++++++++++++ solutions/tests/__init__.py | 0 solutions/tests/test_add_numbers.py | 15 +++++++++++++++ 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 solutions/__init__.py create mode 100644 solutions/add_numbers.py create mode 100644 solutions/tests/__init__.py create mode 100644 solutions/tests/test_add_numbers.py diff --git a/.vscode/settings.json b/.vscode/settings.json index 047d285fe..87ad2d7d7 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -119,5 +119,8 @@ ], "githubPullRequests.ignoredPullRequestBranches": [ "main" - ] + ], + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + } } diff --git a/solutions/__init__.py b/solutions/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/solutions/add_numbers.py b/solutions/add_numbers.py new file mode 100644 index 000000000..9ce668374 --- /dev/null +++ b/solutions/add_numbers.py @@ -0,0 +1,17 @@ +def add_numbers(a, b): + """ + Adds two numbers together. + + Parameters: + a (int, float): The first number to add. + b (int, float): The second number to add. + + Returns: + int, float: The result of adding `a` and `b`. + + Raises: + TypeError: If either `a` or `b` is not a number. + """ + if not isinstance(a, (int, float)) or not isinstance(b, (int, float)): + raise TypeError("Both arguments must be numbers") + return a + b diff --git a/solutions/tests/__init__.py b/solutions/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/solutions/tests/test_add_numbers.py b/solutions/tests/test_add_numbers.py new file mode 100644 index 000000000..814e6eb6a --- /dev/null +++ b/solutions/tests/test_add_numbers.py @@ -0,0 +1,15 @@ +import unittest +from solutions.add_numbers import add_numbers + +class TestAddNumbers(unittest.TestCase): + def test_add_positive_numbers(self): + self.assertEqual(add_numbers(2, 3), 5) + + def test_add_negative_numbers(self): + self.assertEqual(add_numbers(-1, -1), -2) + + def test_add_zero(self): + self.assertEqual(add_numbers(0, 0), 0) + +if __name__ == "__main__": + unittest.main() From d15e65e059e10c12c2833116f9ba6a098c48fd18 Mon Sep 17 00:00:00 2001 From: Momtaz Date: Sat, 11 Jan 2025 19:55:26 +0430 Subject: [PATCH 56/74] another solution added --- solutions/tests/test_add_numbers.py | 19 ++++++++++++++++++ solutions/tests/test_reverse.py | 31 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 solutions/tests/test_reverse.py diff --git a/solutions/tests/test_add_numbers.py b/solutions/tests/test_add_numbers.py index 814e6eb6a..e86b98669 100644 --- a/solutions/tests/test_add_numbers.py +++ b/solutions/tests/test_add_numbers.py @@ -2,13 +2,32 @@ from solutions.add_numbers import add_numbers class TestAddNumbers(unittest.TestCase): + """ class of test cases""" def test_add_positive_numbers(self): + """ + Test adding two positive numbers. + + This test ensures that the function correctly adds two positive integers + and returns the expected result. + """ self.assertEqual(add_numbers(2, 3), 5) def test_add_negative_numbers(self): + """ + Test adding two negative numbers. + + This test checks that the function handles negative numbers correctly + and returns the correct sum. + """ self.assertEqual(add_numbers(-1, -1), -2) def test_add_zero(self): + """ + Test adding two zero values. + + This test confirms that the function returns zero when both inputs + are zero. + """ self.assertEqual(add_numbers(0, 0), 0) if __name__ == "__main__": diff --git a/solutions/tests/test_reverse.py b/solutions/tests/test_reverse.py new file mode 100644 index 000000000..bdd325653 --- /dev/null +++ b/solutions/tests/test_reverse.py @@ -0,0 +1,31 @@ +import unittest +from solutions.reverse import reverse_string + +class TestReverseString(unittest.TestCase): + """ + Test class for the reverse_string function. + This class contains test cases to validate the functionality of the reverse_string function. + """ + + def test_reverse_basic(self): + """ + Test case for a basic string reversal. + """ + self.assertEqual(reverse_string("hello"), "olleh") + + def test_reverse_empty(self): + """ + Test case for an empty string. + The expected output is an empty string. + """ + self.assertEqual(reverse_string(""), "") + + def test_reverse_single_character(self): + """ + Test case for a string with a single character. + The expected output is the same single character. + """ + self.assertEqual(reverse_string("a"), "a") + +if __name__ == "__main__": + unittest.main() \ No newline at end of file From bdbc40dfdd475415f82b05ef94a054471046c31a Mon Sep 17 00:00:00 2001 From: Momtaz Date: Sat, 11 Jan 2025 19:56:07 +0430 Subject: [PATCH 57/74] another solution --- solutions/reverse.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 solutions/reverse.py diff --git a/solutions/reverse.py b/solutions/reverse.py new file mode 100644 index 000000000..37aea706e --- /dev/null +++ b/solutions/reverse.py @@ -0,0 +1,11 @@ +def reverse_string(s: str) -> str: + """ + Reverses the given string. + + Args: + s (str): The input string to be reversed. + + Returns: + str: The reversed string. + """ + return s[::-1] \ No newline at end of file From 2b1f07d597aad04c8f527382891496de48881229 Mon Sep 17 00:00:00 2001 From: Momtaz Yaqubi Date: Sat, 11 Jan 2025 20:21:34 +0430 Subject: [PATCH 58/74] Update reverse.py --- solutions/reverse.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/solutions/reverse.py b/solutions/reverse.py index 37aea706e..87ab2539d 100644 --- a/solutions/reverse.py +++ b/solutions/reverse.py @@ -1,3 +1,6 @@ +"""Created on 11 1 2025 +@author: momtaz-yaqubi +""" def reverse_string(s: str) -> str: """ Reverses the given string. @@ -8,4 +11,4 @@ def reverse_string(s: str) -> str: Returns: str: The reversed string. """ - return s[::-1] \ No newline at end of file + return s[::-1] From 040c4a4e01783bacd6dc6204d3042332774766b8 Mon Sep 17 00:00:00 2001 From: Momtaz Yaqubi Date: Sat, 11 Jan 2025 20:21:44 +0430 Subject: [PATCH 59/74] Update reverse.py --- solutions/reverse.py | 1 + 1 file changed, 1 insertion(+) diff --git a/solutions/reverse.py b/solutions/reverse.py index 87ab2539d..0c374779e 100644 --- a/solutions/reverse.py +++ b/solutions/reverse.py @@ -1,6 +1,7 @@ """Created on 11 1 2025 @author: momtaz-yaqubi """ + def reverse_string(s: str) -> str: """ Reverses the given string. From 42e0ff03512658af577a98d8e433d8016affb406 Mon Sep 17 00:00:00 2001 From: Momtaz Date: Sat, 11 Jan 2025 21:10:15 +0430 Subject: [PATCH 60/74] issue resolved --- collaboration/learning_goals.md | 1 - 1 file changed, 1 deletion(-) diff --git a/collaboration/learning_goals.md b/collaboration/learning_goals.md index ed653ee2c..53123b848 100644 --- a/collaboration/learning_goals.md +++ b/collaboration/learning_goals.md @@ -21,4 +21,3 @@ Anik: To learn unit testing and predictive testing. Momtaz: Learning how to collaborate as a team, working on the same project together. M. Ahmed: To learn how to use GitHub as a team. - From c20226b65db545661b2a96bcbd2c857d5f60d76f Mon Sep 17 00:00:00 2001 From: Momtaz Date: Sat, 11 Jan 2025 21:39:19 +0430 Subject: [PATCH 61/74] formatting issue resolved --- solutions/add_numbers.py | 8 ++++++++ solutions/reverse.py | 6 +++++- solutions/tests/test_add_numbers.py | 5 ++++- solutions/tests/test_reverse.py | 6 ++++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/solutions/add_numbers.py b/solutions/add_numbers.py index 9ce668374..9d66c6fc6 100644 --- a/solutions/add_numbers.py +++ b/solutions/add_numbers.py @@ -1,3 +1,11 @@ +""" +A module for adding two numbers + +Created on 11 1 2025 +@author: momtaz-yaqubi +""" + + def add_numbers(a, b): """ Adds two numbers together. diff --git a/solutions/reverse.py b/solutions/reverse.py index 0c374779e..fed39c714 100644 --- a/solutions/reverse.py +++ b/solutions/reverse.py @@ -1,7 +1,11 @@ -"""Created on 11 1 2025 +""" +A function that reverses a string + +Created on 11 1 2025 @author: momtaz-yaqubi """ + def reverse_string(s: str) -> str: """ Reverses the given string. diff --git a/solutions/tests/test_add_numbers.py b/solutions/tests/test_add_numbers.py index e86b98669..aa6a2a289 100644 --- a/solutions/tests/test_add_numbers.py +++ b/solutions/tests/test_add_numbers.py @@ -1,8 +1,10 @@ import unittest from solutions.add_numbers import add_numbers + class TestAddNumbers(unittest.TestCase): - """ class of test cases""" + """class of test cases""" + def test_add_positive_numbers(self): """ Test adding two positive numbers. @@ -30,5 +32,6 @@ def test_add_zero(self): """ self.assertEqual(add_numbers(0, 0), 0) + if __name__ == "__main__": unittest.main() diff --git a/solutions/tests/test_reverse.py b/solutions/tests/test_reverse.py index bdd325653..040b13e51 100644 --- a/solutions/tests/test_reverse.py +++ b/solutions/tests/test_reverse.py @@ -1,12 +1,13 @@ import unittest from solutions.reverse import reverse_string + class TestReverseString(unittest.TestCase): """ Test class for the reverse_string function. This class contains test cases to validate the functionality of the reverse_string function. """ - + def test_reverse_basic(self): """ Test case for a basic string reversal. @@ -27,5 +28,6 @@ def test_reverse_single_character(self): """ self.assertEqual(reverse_string("a"), "a") + if __name__ == "__main__": - unittest.main() \ No newline at end of file + unittest.main() From b59b962847a71bc7dcf0c8955ce3dd423ea902b9 Mon Sep 17 00:00:00 2001 From: Momtaz Date: Sat, 11 Jan 2025 21:48:03 +0430 Subject: [PATCH 62/74] formatted --- solutions/find_largest_number.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/solutions/find_largest_number.py b/solutions/find_largest_number.py index 328de3bb4..7a96f94f7 100644 --- a/solutions/find_largest_number.py +++ b/solutions/find_largest_number.py @@ -1,9 +1,11 @@ -""" Function to Find the Largest Number +"""Function to Find the Largest Number @author: msrak """ + def largest_number(numbers): return max(numbers) -numbers = [1,2,3,4,21,12,8] -print(f"This is the largest number {largest_number(numbers)}") \ No newline at end of file + +numbers = [1, 2, 3, 4, 21, 12, 8] +print(f"This is the largest number {largest_number(numbers)}") From 7fdd4d2b9d3e9fafc8a7f4cc842bdec0df44081c Mon Sep 17 00:00:00 2001 From: Momtaz Yaqubi Date: Sat, 11 Jan 2025 23:15:09 +0430 Subject: [PATCH 63/74] Delete solutions/nilofar_test_water.py --- solutions/nilofar_test_water.py | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 solutions/nilofar_test_water.py diff --git a/solutions/nilofar_test_water.py b/solutions/nilofar_test_water.py deleted file mode 100644 index 5324b202f..000000000 --- a/solutions/nilofar_test_water.py +++ /dev/null @@ -1,19 +0,0 @@ -import pytest -from nilofar_water_intake import calculate_water_intake - -def test_low_activity_temperate(): - assert calculate_water_intake(70, "Low", "Temperate") == 2.31 - -def test_moderate_activity_hot(): - assert calculate_water_intake(70, "Moderate", "Hot") == 3.31 - -def test_high_activity_cold(): - assert calculate_water_intake(70, "High", "Cold") == 3.13 - -def test_invalid_activity(): - with pytest.raises(ValueError): - calculate_water_intake(70, "Extreme", "Temperate") - -def test_invalid_weight(): - with pytest.raises(ValueError): - calculate_water_intake(-10, "Low", "Temperate") From 36e5960a2bce187896aa4a8a0873cee92c74b55e Mon Sep 17 00:00:00 2001 From: Momtaz Yaqubi Date: Sat, 11 Jan 2025 23:16:07 +0430 Subject: [PATCH 64/74] Delete solutions/nilofar_test_bmi.py --- solutions/nilofar_test_bmi.py | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 solutions/nilofar_test_bmi.py diff --git a/solutions/nilofar_test_bmi.py b/solutions/nilofar_test_bmi.py deleted file mode 100644 index 3319e02d3..000000000 --- a/solutions/nilofar_test_bmi.py +++ /dev/null @@ -1,19 +0,0 @@ -import unittest -from nilfersolution import calculate_bmi # Import the function from the solution file - -class TestBMICalculator(unittest.TestCase): - def test_underweight(self): - self.assertEqual(calculate_bmi(45, 1.7), "Underweight (BMI: 15.57)") - - def test_normal_weight(self): - self.assertEqual(calculate_bmi(68, 1.75), "Normal weight (BMI: 22.20)") - - def test_overweight(self): - self.assertEqual(calculate_bmi(80, 1.7), "Overweight (BMI: 27.68)") - - def test_obesity(self): - self.assertEqual(calculate_bmi(95, 1.6), "Obesity (BMI: 37.11)") - - def test_invalid_input(self): - self.assertEqual(calculate_bmi(-45, 1.7), "Invalid input. Height and weight must be greater than zero.") - self.assertEqual(calculate_bmi(50, 0), "Invalid input. Height and weight must be greater than zero.") From 2fe36d196fd2ff514c6b91eab4e598de69f36b9b Mon Sep 17 00:00:00 2001 From: muqaddas96 Date: Sat, 11 Jan 2025 22:10:33 +0300 Subject: [PATCH 65/74] ruff format --- solutions/nilofar_solution.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/solutions/nilofar_solution.py b/solutions/nilofar_solution.py index fd33d1cd1..ca6f4c6e2 100644 --- a/solutions/nilofar_solution.py +++ b/solutions/nilofar_solution.py @@ -8,9 +8,9 @@ def calculate_bmi(weight, height): """ if height <= 0 or weight <= 0: return "Invalid input. Height and weight must be greater than zero." - - bmi = weight / (height ** 2) - + + bmi = weight / (height**2) + if bmi < 18.5: return f"Underweight (BMI: {bmi:.2f})" elif 18.5 <= bmi < 24.9: From 3e84bbf7f59dbca3b514c05bd9843036c1dda841 Mon Sep 17 00:00:00 2001 From: muqaddas96 Date: Sun, 12 Jan 2025 00:42:46 +0300 Subject: [PATCH 66/74] muqaddas_2nd_solution --- solutions/missing_number.py | 41 +++++++++++++++++ solutions/tests/test_missing_number.py | 62 ++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 solutions/missing_number.py create mode 100644 solutions/tests/test_missing_number.py diff --git a/solutions/missing_number.py b/solutions/missing_number.py new file mode 100644 index 000000000..8d9efd224 --- /dev/null +++ b/solutions/missing_number.py @@ -0,0 +1,41 @@ +""" +A module to find the missing number from a range of numbers. + +Module contents: + - find_missing_number: returns the missing number from the given array. + +Created on 11th Jan 2025 +@author: muqaddas96 +""" + + +def missing_number(nums: list[int]) -> int: + """Find the missing number from an array of distinct integers. + + Parameters: + nums (list[int]): List of integers from the range 0 to n. + + Returns: + int: The missing number. + + Raises: + AssertionError: If nums is not a list or contains invalid values. + + Examples: + >>> find_missing_number([3, 0, 1]) + 2 + >>> find_missing_number([0, 1]) + 2 + >>> find_missing_number([9,6,4,2,3,5,7,0,1]) + 8 + >>> find_missing_number([0]) + 1 + """ + assert isinstance(nums, list), "Input must be a list." + assert all(isinstance(num, int) for num in nums), "List elements must be integers." + assert len(nums) == len(set(nums)), "List must contain distinct integers." + + n = len(nums) + expected_sum = n * (n + 1) // 2 # Sum of 0 to n + actual_sum = sum(nums) + return expected_sum - actual_sum diff --git a/solutions/tests/test_missing_number.py b/solutions/tests/test_missing_number.py new file mode 100644 index 000000000..cd3a42381 --- /dev/null +++ b/solutions/tests/test_missing_number.py @@ -0,0 +1,62 @@ +import unittest +from solutions.missing_number import missing_number + + +class TestMissingNumber(unittest.TestCase): + """ + Test cases for the `missing_number` function, which finds the missing number + in an array of distinct integers ranging from 0 to n. + """ + + def test_single_missing_number(self): + """ + Test a case where the input array has a single missing number. + Example: Input [3, 0, 1] should return 2. + """ + self.assertEqual(missing_number([3, 0, 1]), 2) + + def test_missing_last_number(self): + """ + Test a case where the last number in the range is missing. + Example: Input [0, 1, 2] should return 3. + """ + self.assertEqual(missing_number([0, 1, 2]), 3) + + def test_missing_first_number(self): + """ + Test a case where the first number in the range is missing. + Example: Input [1, 2] should return 0. + """ + self.assertEqual(missing_number([1, 2]), 0) + + def test_empty_array(self): + """ + Test the edge case where the input array is empty. + Example: Input [] should return 0. + """ + self.assertEqual(missing_number([]), 0) + + def test_large_array(self): + """ + Test a case with a larger array to ensure the function works with big inputs. + Example: Input [0, 1, 3, 4] should return 2. + """ + self.assertEqual(missing_number([0, 1, 3, 4]), 2) + + def test_single_element_zero(self): + """ + Test a single-element array where the only element is 0. + Example: Input [0] should return 1. + """ + self.assertEqual(missing_number([0]), 1) + + def test_single_element_one(self): + """ + Test a single-element array where the only element is 1. + Example: Input [1] should return 0. + """ + self.assertEqual(missing_number([1]), 0) + + +if __name__ == "__main__": + unittest.main() From 3085b33c8a53fc54048cb6d11140353b11c8b5e0 Mon Sep 17 00:00:00 2001 From: Anik Kumar Adhikary Date: Sun, 12 Jan 2025 10:20:06 +0530 Subject: [PATCH 67/74] adding a new solution --- solutions/is_fibonacci.py | 35 +++++++++++++++++ solutions/tests/test_is_fibonacci.py | 56 ++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 solutions/is_fibonacci.py create mode 100644 solutions/tests/test_is_fibonacci.py diff --git a/solutions/is_fibonacci.py b/solutions/is_fibonacci.py new file mode 100644 index 000000000..3a1e8bdd4 --- /dev/null +++ b/solutions/is_fibonacci.py @@ -0,0 +1,35 @@ +""" +A module that that generates an arithmetic progression (AP). + +Module contents: + - generate_arithmetic_progression generates an arithmetic progression + +Created on 01/09/2025 +@author: Anik Kumar Adhikary +""" + +import math + + +def is_fibonacci_number(n: int) -> bool: + """ + Checks whether a given number is a Fibonacci number. + + A number is a Fibonacci number if and only if one or both of + (5 * n^2 + 4) or (5 * n^2 - 4) is a perfect square. + + Args: + n (int): The number to check. + + Returns: + bool: True if the number is a Fibonacci number, False otherwise. + """ + if n < 0: + return False + + def is_perfect_square(x: int) -> bool: + s = int(math.sqrt(x)) + return s * s == x + + # Check both conditions + return is_perfect_square(5 * n * n + 4) or is_perfect_square(5 * n * n - 4) diff --git a/solutions/tests/test_is_fibonacci.py b/solutions/tests/test_is_fibonacci.py new file mode 100644 index 000000000..5c4fdcbcc --- /dev/null +++ b/solutions/tests/test_is_fibonacci.py @@ -0,0 +1,56 @@ +"""unittest code verifies the behavior of is_fibonacci_number to +check whether a number is fibonaaci number or not""" + +import unittest + +from solutions.is_fibonacci import is_fibonacci_number + + +class TestIsFibonacciNumber(unittest.TestCase): + """Test the is_fibonacci_number function""" + + def test_fibonacci_numbers(self): + """Test known Fibonacci numbers""" + self.assertTrue(is_fibonacci_number(0)) + self.assertTrue(is_fibonacci_number(1)) + self.assertTrue(is_fibonacci_number(2)) + self.assertTrue(is_fibonacci_number(3)) + self.assertTrue(is_fibonacci_number(5)) + self.assertTrue(is_fibonacci_number(8)) + self.assertTrue(is_fibonacci_number(13)) + self.assertTrue(is_fibonacci_number(21)) + self.assertTrue(is_fibonacci_number(34)) + self.assertTrue(is_fibonacci_number(144)) + + def test_non_fibonacci_numbers(self): + """Test non-Fibonacci numbers""" + # Test non-Fibonacci numbers + self.assertFalse(is_fibonacci_number(4)) + self.assertFalse(is_fibonacci_number(6)) + self.assertFalse(is_fibonacci_number(7)) + self.assertFalse(is_fibonacci_number(9)) + self.assertFalse(is_fibonacci_number(10)) + self.assertFalse(is_fibonacci_number(11)) + self.assertFalse(is_fibonacci_number(15)) + self.assertFalse(is_fibonacci_number(20)) + + def test_negative_numbers(self): + """Test negative numbers""" + self.assertFalse(is_fibonacci_number(-1)) + self.assertFalse(is_fibonacci_number(-5)) + self.assertFalse(is_fibonacci_number(-8)) + + def test_large_fibonacci_numbers(self): + """Test larger Fibonacci numbers""" + # Test larger Fibonacci numbers + self.assertTrue(is_fibonacci_number(233)) + self.assertTrue(is_fibonacci_number(377)) + + def test_large_non_fibonacci_numbers(self): + """Test larger non-Fibonacci numbers""" + self.assertFalse(is_fibonacci_number(300)) + self.assertFalse(is_fibonacci_number(400)) + + +if __name__ == "__main__": + unittest.main() From b218c0fa12fb80feae267225d0aa9b7c4b8d666c Mon Sep 17 00:00:00 2001 From: Nilofar Date: Sun, 12 Jan 2025 20:06:11 +0430 Subject: [PATCH 68/74] test_water.py --- solutions/tests/test_water.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 solutions/tests/test_water.py diff --git a/solutions/tests/test_water.py b/solutions/tests/test_water.py new file mode 100644 index 000000000..d511a4eb5 --- /dev/null +++ b/solutions/tests/test_water.py @@ -0,0 +1,35 @@ +import unittest +from solutions.water_solutions import calculate_water_intake + + +def test_low_activity_temperate(): + """Test for low activity in temperate climate.""" + assert calculate_water_intake(70, "Low", "Temperate") == 2.31 + + +def test_moderate_activity_hot(): + """Test for moderate activity in hot climate.""" + assert calculate_water_intake(70, "Moderate", "Hot") == 3.31 + + +def test_high_activity_cold(): + """Test for high activity in cold climate.""" + assert calculate_water_intake(70, "High", "Cold") == 3.13 + + +def test_invalid_weight(): + """Test for invalid weight input.""" + with unittest.raises(ValueError, match="Weight must be a positive number."): + calculate_water_intake(-10, "Low", "Temperate") + + +def test_invalid_activity_level(): + """Test for invalid activity level input.""" + with unittest.raises(ValueError, match="Invalid activity level: InvalidActivity."): + calculate_water_intake(70, "InvalidActivity", "Cold") + + +def test_invalid_climate(): + """Test for invalid climate input.""" + with unittest.raises(ValueError, match="Invalid climate: InvalidClimate."): + calculate_water_intake(70, "Low", "InvalidClimate") From c5aa3df06e3132727a13e842f03012bafff70d0a Mon Sep 17 00:00:00 2001 From: Nilofar Date: Sun, 12 Jan 2025 21:10:25 +0430 Subject: [PATCH 69/74] new update --- solutions/tests/nilofar_solution.py | 63 ++++++++++++++++++++++++ solutions/tests/test_nikzad_bmi.py | 75 +++++++++++++++++++++++++++++ solutions/tests/test_water.py | 2 +- solutions/water_solution.py | 55 +++++++++++++++++++++ 4 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 solutions/tests/nilofar_solution.py create mode 100644 solutions/tests/test_nikzad_bmi.py create mode 100644 solutions/water_solution.py diff --git a/solutions/tests/nilofar_solution.py b/solutions/tests/nilofar_solution.py new file mode 100644 index 000000000..cfb0f6715 --- /dev/null +++ b/solutions/tests/nilofar_solution.py @@ -0,0 +1,63 @@ +""" +nilfersolution.py + +Solution for BMI calculation. + +This script defines the `calculate_bmi` function, which calculates the Body Mass Index (BMI) +given weight (in kilograms) and height (in meters). It also categorizes the BMI into one of +the following categories: +- Underweight +- Normal weight +- Overweight +- Obesity + +Author: [Your Name] +Date: [Today's Date] +""" + + +def calculate_bmi(weight, height): + """ + Calculate the Body Mass Index (BMI) and categorize it. + + Args: + weight (float): The weight of the person in kilograms. + height (float): The height of the person in meters. + + Returns: + str: A message indicating the BMI value and its category. + Returns an error message for invalid input. + + Examples: + >>> calculate_bmi(45, 1.7) + 'Underweight (BMI: 15.57)' + >>> calculate_bmi(68, 1.75) + 'Normal weight (BMI: 22.20)' + >>> calculate_bmi(-45, 1.7) + 'Invalid input. Height and weight must be greater than zero.' + """ + # Validate input: weight and height must be positive + if weight <= 0 or height <= 0: + return "Invalid input. Height and weight must be greater than zero." + + # Calculate BMI + bmi = weight / (height**2) + + # Determine BMI category + if bmi < 18.5: + category = "Underweight" + elif 18.5 <= bmi < 24.9: + category = "Normal weight" + elif 25 <= bmi < 29.9: + category = "Overweight" + else: + category = "Obesity" + + # Format BMI to two decimal places + return f"{category} (BMI: {bmi:.2f})" + + +# Example usage (uncomment the following lines to test): +# print(calculate_bmi(45, 1.7)) # Output: 'Underweight (BMI: 15.57)' +# print(calculate_bmi(68, 1.75)) # Output: 'Normal weight (BMI: 22.20)' +# print(calculate_bmi(-45, 1.7)) # Output: 'Invalid input. Height and weight must be greater than zero.' diff --git a/solutions/tests/test_nikzad_bmi.py b/solutions/tests/test_nikzad_bmi.py new file mode 100644 index 000000000..350371cbb --- /dev/null +++ b/solutions/tests/test_nikzad_bmi.py @@ -0,0 +1,75 @@ +""" +test_nikzad_bmi.py + +Unit tests for the BMI calculation function `calculate_bmi` from `nilfersolution`. + +This script uses the `unittest` framework to validate the correctness of the +BMI calculation function across different scenarios, including: +- Underweight +- Normal weight +- Overweight +- Obesity +- Invalid inputs + +Author: [Your Name] +Date: [Today's Date] +""" + +import unittest +from nilofer_solution import calculate_bmi # Import the function from the solution file + + +class TestBMICalculator(unittest.TestCase): + """ + Unit test class for testing the `calculate_bmi` function. + """ + + def test_underweight(self): + """ + Test case for the underweight category. + """ + result = calculate_bmi(45, 1.7) + self.assertEqual(result, "Underweight (BMI: 15.57)") + + def test_normal_weight(self): + """ + Test case for the normal weight category. + """ + result = calculate_bmi(68, 1.75) + self.assertEqual(result, "Normal weight (BMI: 22.20)") + + def test_overweight(self): + """ + Test case for the overweight category. + """ + result = calculate_bmi(80, 1.7) + self.assertEqual(result, "Overweight (BMI: 27.68)") + + def test_obesity(self): + """ + Test case for the obesity category. + """ + result = calculate_bmi(95, 1.6) + self.assertEqual(result, "Obesity (BMI: 37.11)") + + def test_invalid_input(self): + """ + Test cases for invalid input scenarios. + The function should return an appropriate error message + when height or weight is less than or equal to zero. + """ + result_negative_weight = calculate_bmi(-45, 1.7) + self.assertEqual( + result_negative_weight, + "Invalid input. Height and weight must be greater than zero.", + ) + + result_zero_height = calculate_bmi(50, 0) + self.assertEqual( + result_zero_height, + "Invalid input. Height and weight must be greater than zero.", + ) + + +if __name__ == "__main__": + unittest.main() diff --git a/solutions/tests/test_water.py b/solutions/tests/test_water.py index d511a4eb5..fd159bf4c 100644 --- a/solutions/tests/test_water.py +++ b/solutions/tests/test_water.py @@ -1,5 +1,5 @@ import unittest -from solutions.water_solutions import calculate_water_intake +from solutions.water_solution import calculate_water_intake def test_low_activity_temperate(): diff --git a/solutions/water_solution.py b/solutions/water_solution.py new file mode 100644 index 000000000..94786f175 --- /dev/null +++ b/solutions/water_solution.py @@ -0,0 +1,55 @@ +""" +water_solution.py + +Solution for determining daily water intake based on weight and activity level. + +This script defines the calculate_water_intake function, which calculates the recommended daily +water intake in liters for a person based on their weight (in kilograms) and activity level (in minutes). +The function adjusts water intake based on exercise time. + +Author: Nilofar Nikzad +Date: January 12, 2025 +""" + + +def calculate_water_intake(weight, activity_minutes): + """ + Calculate the recommended daily water intake based on weight and activity level. + + Args: + weight (float): The weight of the person in kilograms. + activity_minutes (float): The daily physical activity time in minutes. + + Returns: + str: A message indicating the recommended daily water intake in liters. + Returns an error message for invalid input. + + Examples: + >>> calculate_water_intake(70, 30) + 'Recommended daily water intake: 2.85 liters' + >>> calculate_water_intake(50, 60) + 'Recommended daily water intake: 2.60 liters' + >>> calculate_water_intake(-70, 30) + 'Invalid input. Weight and activity minutes must be greater than zero.' + """ + # Validate input: weight and activity_minutes must be positive + if weight <= 0 or activity_minutes < 0: + return "Invalid input. Weight and activity minutes must be greater than zero." + + # Base water requirement: 0.033 liters per kg of body weight + base_water_intake = weight * 0.033 + + # Additional water requirement: 0.012 liters per minute of physical activity + additional_water_intake = activity_minutes * 0.012 + + # Total water intake + total_water_intake = base_water_intake + additional_water_intake + + # Format result to two decimal places + return f"Recommended daily water intake: {total_water_intake:.2f} liters" + + +# Example usage (uncomment the following lines to test): +# print(calculate_water_intake(70, 30)) # Output: 'Recommended daily water intake: 2.85 liters' +# print(calculate_water_intake(50, 60)) # Output: 'Recommended daily water intake: 2.60 liters' +# print(calculate_water_intake(-70, 30)) # Output: 'Invalid input. Weight and activity minutes must be greater than zero.' From 833af9dda40a119fc5fc5867f19ffac804d597a3 Mon Sep 17 00:00:00 2001 From: Nilofar Date: Sun, 12 Jan 2025 21:25:19 +0430 Subject: [PATCH 70/74] Finally it worked --- solutions/tests/test_nikzad_bmi.py | 6 +++--- solutions/tests/test_water.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/solutions/tests/test_nikzad_bmi.py b/solutions/tests/test_nikzad_bmi.py index 350371cbb..ebb3decef 100644 --- a/solutions/tests/test_nikzad_bmi.py +++ b/solutions/tests/test_nikzad_bmi.py @@ -11,12 +11,12 @@ - Obesity - Invalid inputs -Author: [Your Name] -Date: [Today's Date] +Author: (Nilofar Nikzad) +Date: [Jan 12,2025] """ import unittest -from nilofer_solution import calculate_bmi # Import the function from the solution file +from solutions.nilofar_solution import calculate_bmi # Import the function from the solution file class TestBMICalculator(unittest.TestCase): diff --git a/solutions/tests/test_water.py b/solutions/tests/test_water.py index fd159bf4c..470c1fb1c 100644 --- a/solutions/tests/test_water.py +++ b/solutions/tests/test_water.py @@ -1,7 +1,7 @@ import unittest from solutions.water_solution import calculate_water_intake - - +class TestWaterIntakeCalculator(unittest.TestCase): + """To test the calculate_water_intake function.""" def test_low_activity_temperate(): """Test for low activity in temperate climate.""" assert calculate_water_intake(70, "Low", "Temperate") == 2.31 From 50fa8c6a3212d8e020d144f398e078351a2febac Mon Sep 17 00:00:00 2001 From: Nilofar Date: Sun, 12 Jan 2025 21:29:18 +0430 Subject: [PATCH 71/74] I hope it works --- solutions/tests/test_nikzad_bmi.py | 4 +++- solutions/tests/test_water.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/solutions/tests/test_nikzad_bmi.py b/solutions/tests/test_nikzad_bmi.py index ebb3decef..2a99f5b93 100644 --- a/solutions/tests/test_nikzad_bmi.py +++ b/solutions/tests/test_nikzad_bmi.py @@ -16,7 +16,9 @@ """ import unittest -from solutions.nilofar_solution import calculate_bmi # Import the function from the solution file +from solutions.nilofar_solution import ( + calculate_bmi, +) # Import the function from the solution file class TestBMICalculator(unittest.TestCase): diff --git a/solutions/tests/test_water.py b/solutions/tests/test_water.py index 470c1fb1c..e33a59963 100644 --- a/solutions/tests/test_water.py +++ b/solutions/tests/test_water.py @@ -1,7 +1,11 @@ import unittest from solutions.water_solution import calculate_water_intake + + class TestWaterIntakeCalculator(unittest.TestCase): """To test the calculate_water_intake function.""" + + def test_low_activity_temperate(): """Test for low activity in temperate climate.""" assert calculate_water_intake(70, "Low", "Temperate") == 2.31 From 03d1388e01060a02a3753e21040d40193d6a5649 Mon Sep 17 00:00:00 2001 From: muqaddas96 Date: Sun, 12 Jan 2025 21:32:03 +0300 Subject: [PATCH 72/74] Nilofar solutions --- ...{nilofar_solution.py => bmi_calculator.py} | 0 ...t_nikzad_bmi.py => test_bmi_calculator.py} | 2 +- solutions/tests/test_water.py | 39 ------------------- solutions/tests/test_water_intake_solution.py | 39 +++++++++++++++++++ ...r_solution.py => water_intake_solution.py} | 0 5 files changed, 40 insertions(+), 40 deletions(-) rename solutions/{nilofar_solution.py => bmi_calculator.py} (100%) rename solutions/tests/{test_nikzad_bmi.py => test_bmi_calculator.py} (98%) delete mode 100644 solutions/tests/test_water.py create mode 100644 solutions/tests/test_water_intake_solution.py rename solutions/{water_solution.py => water_intake_solution.py} (100%) diff --git a/solutions/nilofar_solution.py b/solutions/bmi_calculator.py similarity index 100% rename from solutions/nilofar_solution.py rename to solutions/bmi_calculator.py diff --git a/solutions/tests/test_nikzad_bmi.py b/solutions/tests/test_bmi_calculator.py similarity index 98% rename from solutions/tests/test_nikzad_bmi.py rename to solutions/tests/test_bmi_calculator.py index 2a99f5b93..eb68b5e32 100644 --- a/solutions/tests/test_nikzad_bmi.py +++ b/solutions/tests/test_bmi_calculator.py @@ -16,7 +16,7 @@ """ import unittest -from solutions.nilofar_solution import ( +from solutions.bmi_calculator import ( calculate_bmi, ) # Import the function from the solution file diff --git a/solutions/tests/test_water.py b/solutions/tests/test_water.py deleted file mode 100644 index e33a59963..000000000 --- a/solutions/tests/test_water.py +++ /dev/null @@ -1,39 +0,0 @@ -import unittest -from solutions.water_solution import calculate_water_intake - - -class TestWaterIntakeCalculator(unittest.TestCase): - """To test the calculate_water_intake function.""" - - -def test_low_activity_temperate(): - """Test for low activity in temperate climate.""" - assert calculate_water_intake(70, "Low", "Temperate") == 2.31 - - -def test_moderate_activity_hot(): - """Test for moderate activity in hot climate.""" - assert calculate_water_intake(70, "Moderate", "Hot") == 3.31 - - -def test_high_activity_cold(): - """Test for high activity in cold climate.""" - assert calculate_water_intake(70, "High", "Cold") == 3.13 - - -def test_invalid_weight(): - """Test for invalid weight input.""" - with unittest.raises(ValueError, match="Weight must be a positive number."): - calculate_water_intake(-10, "Low", "Temperate") - - -def test_invalid_activity_level(): - """Test for invalid activity level input.""" - with unittest.raises(ValueError, match="Invalid activity level: InvalidActivity."): - calculate_water_intake(70, "InvalidActivity", "Cold") - - -def test_invalid_climate(): - """Test for invalid climate input.""" - with unittest.raises(ValueError, match="Invalid climate: InvalidClimate."): - calculate_water_intake(70, "Low", "InvalidClimate") diff --git a/solutions/tests/test_water_intake_solution.py b/solutions/tests/test_water_intake_solution.py new file mode 100644 index 000000000..40d262951 --- /dev/null +++ b/solutions/tests/test_water_intake_solution.py @@ -0,0 +1,39 @@ +import unittest +from solutions.water_intake_solution import calculate_water_intake + + +class TestWaterIntakeCalculator(unittest.TestCase): + """To test the calculate_water_intake function.""" + + + def test_low_activity_temperate(): + """Test for low activity in temperate climate.""" + assert calculate_water_intake(70, "Low", "Temperate") == 2.31 + + + def test_moderate_activity_hot(): + """Test for moderate activity in hot climate.""" + assert calculate_water_intake(70, "Moderate", "Hot") == 3.31 + + + def test_high_activity_cold(): + """Test for high activity in cold climate.""" + assert calculate_water_intake(70, "High", "Cold") == 3.13 + + + def test_invalid_weight(): + """Test for invalid weight input.""" + with unittest.raises(ValueError, match="Weight must be a positive number."): + calculate_water_intake(-10, "Low", "Temperate") + + + def test_invalid_activity_level(): + """Test for invalid activity level input.""" + with unittest.raises(ValueError, match="Invalid activity level: InvalidActivity."): + calculate_water_intake(70, "InvalidActivity", "Cold") + + + def test_invalid_climate(): + """Test for invalid climate input.""" + with unittest.raises(ValueError, match="Invalid climate: InvalidClimate."): + calculate_water_intake(70, "Low", "InvalidClimate") diff --git a/solutions/water_solution.py b/solutions/water_intake_solution.py similarity index 100% rename from solutions/water_solution.py rename to solutions/water_intake_solution.py From 118f292321391fee2807a0e0dce8a3722e6b1e7c Mon Sep 17 00:00:00 2001 From: muqaddas96 Date: Sun, 12 Jan 2025 21:33:24 +0300 Subject: [PATCH 73/74] Ruff Formatted --- solutions/tests/test_water_intake_solution.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/solutions/tests/test_water_intake_solution.py b/solutions/tests/test_water_intake_solution.py index 40d262951..21aa9212f 100644 --- a/solutions/tests/test_water_intake_solution.py +++ b/solutions/tests/test_water_intake_solution.py @@ -5,34 +5,30 @@ class TestWaterIntakeCalculator(unittest.TestCase): """To test the calculate_water_intake function.""" - def test_low_activity_temperate(): """Test for low activity in temperate climate.""" assert calculate_water_intake(70, "Low", "Temperate") == 2.31 - def test_moderate_activity_hot(): """Test for moderate activity in hot climate.""" assert calculate_water_intake(70, "Moderate", "Hot") == 3.31 - def test_high_activity_cold(): """Test for high activity in cold climate.""" assert calculate_water_intake(70, "High", "Cold") == 3.13 - def test_invalid_weight(): """Test for invalid weight input.""" with unittest.raises(ValueError, match="Weight must be a positive number."): calculate_water_intake(-10, "Low", "Temperate") - def test_invalid_activity_level(): """Test for invalid activity level input.""" - with unittest.raises(ValueError, match="Invalid activity level: InvalidActivity."): + with unittest.raises( + ValueError, match="Invalid activity level: InvalidActivity." + ): calculate_water_intake(70, "InvalidActivity", "Cold") - def test_invalid_climate(): """Test for invalid climate input.""" with unittest.raises(ValueError, match="Invalid climate: InvalidClimate."): From 8c42dffdaef7669313d76f777bc12f4906607931 Mon Sep 17 00:00:00 2001 From: muqaddas96 Date: Sun, 12 Jan 2025 21:56:43 +0300 Subject: [PATCH 74/74] Nilofar Solutions --- solutions/tests/test_water_intake_solution.py | 38 ++++++++----------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/solutions/tests/test_water_intake_solution.py b/solutions/tests/test_water_intake_solution.py index 21aa9212f..45fd15810 100644 --- a/solutions/tests/test_water_intake_solution.py +++ b/solutions/tests/test_water_intake_solution.py @@ -5,31 +5,23 @@ class TestWaterIntakeCalculator(unittest.TestCase): """To test the calculate_water_intake function.""" - def test_low_activity_temperate(): + def test_low_activity_temperate(self): """Test for low activity in temperate climate.""" - assert calculate_water_intake(70, "Low", "Temperate") == 2.31 + self.assertEqual( + calculate_water_intake(70, 30), + "Recommended daily water intake: 2.67 liters", + ) - def test_moderate_activity_hot(): + def test_moderate_activity_hot(self): """Test for moderate activity in hot climate.""" - assert calculate_water_intake(70, "Moderate", "Hot") == 3.31 + self.assertEqual( + calculate_water_intake(50, 60), + "Recommended daily water intake: 2.37 liters", + ) - def test_high_activity_cold(): - """Test for high activity in cold climate.""" - assert calculate_water_intake(70, "High", "Cold") == 3.13 - - def test_invalid_weight(): + def test_invalid_weight(self): """Test for invalid weight input.""" - with unittest.raises(ValueError, match="Weight must be a positive number."): - calculate_water_intake(-10, "Low", "Temperate") - - def test_invalid_activity_level(): - """Test for invalid activity level input.""" - with unittest.raises( - ValueError, match="Invalid activity level: InvalidActivity." - ): - calculate_water_intake(70, "InvalidActivity", "Cold") - - def test_invalid_climate(): - """Test for invalid climate input.""" - with unittest.raises(ValueError, match="Invalid climate: InvalidClimate."): - calculate_water_intake(70, "Low", "InvalidClimate") + self.assertEqual( + calculate_water_intake(-70, 30), + "Invalid input. Weight and activity minutes must be greater than zero.", + )