From 24367d62b3b55e8fb56be7f822a3cd015fd14c29 Mon Sep 17 00:00:00 2001 From: likechrisss Date: Sun, 29 Dec 2024 00:10:51 -0500 Subject: [PATCH 1/5] feat: Solution and Test for Sponge Case Challenge --- solutions/README.md | 21 +++++++- solutions/spongecase.py | 39 ++++++++++++++ solutions/tests/test_spongecase.py | 82 ++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 solutions/spongecase.py create mode 100644 solutions/tests/test_spongecase.py diff --git a/solutions/README.md b/solutions/README.md index 9852346d2..71903884f 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -1 +1,20 @@ -# Solutions +# Challenge: SpongeCase + +## Description + +SpongeCase is a style of text where letters alternately appear +in lower and upper case. +For example, the word in spongeCase would be `sPoNgEcAsE`. + +Write a function that converts the given string into spongeCase. + +## Example + +```python +spongecase("hello world") +# Output: "hElLo wOrLd" + +spongecase("Python") +# Output: "pYtHoN" + +- Challenge Link: [GitHub Issue](https:https://github.com/MIT-Emerging-Talent/ET6-foundations-group-04/issues/2) diff --git a/solutions/spongecase.py b/solutions/spongecase.py new file mode 100644 index 000000000..9620e4407 --- /dev/null +++ b/solutions/spongecase.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +A module for converting strings into SpongeCase (alternating lower and upper case). + +Module contents: + - spongecase: Converts a string into SpongeCase + +Created on 28/12/2024 +Author: Chrismy Leprince Paul Augustin +""" + + +def spongecase(text: str) -> str: + """Converts a string into SpongeCase, where letters alternate between lower + and upper case, starting with lower case. + + Parameters: + text: str, a string to be converted into SpongeCase + + Returns -> str: The SpongeCase version of the input string + + Examples: + >>> spongecase("hello world") + 'hElLo wOrLd' + >>> spongecase("PYTHON") + 'pYtHoN' + >>> spongecase("HELLO!") + 'hElLo!' + """ + result_chars = [] + for index, char in enumerate(text): + if index % 2 == 0: + # Even index -> lowercase + result_chars.append(char.lower()) + else: + # Odd index -> uppercase + result_chars.append(char.upper()) + return "".join(result_chars) diff --git a/solutions/tests/test_spongecase.py b/solutions/tests/test_spongecase.py new file mode 100644 index 000000000..ea768ca8f --- /dev/null +++ b/solutions/tests/test_spongecase.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Test module for spongecase function. + +Test categories: + - Basic cases: typical strings, single words + - Edge cases: empty string, all uppercase, all lowercase + - Special characters: punctuation, digits, symbols + +Created on 2024-12-28 +Author: Chrismy Leprince Paul Augustin +""" + +import unittest +from solutions.spongecase import spongecase + + +class TestSpongeCase(unittest.TestCase): + """Test suite for the spongecase function.""" + + def test_spongecase_basic(self): + """ + It should convert a typical string containing spaces into SpongeCase. + + Example: + "hello world" -> "hElLo wOrLd" + """ + self.assertEqual(spongecase("hello world"), "hElLo wOrLd") + + def test_spongecase_single_word(self): + """ + It should convert a single word into SpongeCase. + + Example: + "Python" -> "pYtHoN" + """ + self.assertEqual(spongecase("Python"), "pYtHoN") + + def test_spongecase_empty_string(self): + """ + It should handle an empty string by returning an empty string. + + Example: + "" -> "" + """ + self.assertEqual(spongecase(""), "") + + def test_spongecase_all_caps(self): + """ + It should convert an all-caps string into SpongeCase. + + Example: + "HELLO" -> "hElLo" + """ + self.assertEqual(spongecase("HELLO"), "hElLo") + + def test_spongecase_all_lowercase(self): + """ + It should convert an all-lowercase string into SpongeCase. + + Example: + "world" -> "wOrLd" + """ + self.assertEqual(spongecase("world"), "wOrLd") + + def test_spongecase_special_characters(self): + """ + It should alternate case while preserving special characters + and digits in place. + + Mapping indices: + Index: 0 1 2 3 4 5 6 7 8 9 + Char: H e l l o ? 1 # A b + Case: h E l L o ? 1 # a B + Result: "hElLo?1#aB" + """ + self.assertEqual(spongecase("Hello?1#Ab"), "hElLo?1#aB") + + +if __name__ == "__main__": + unittest.main() From 4be24afa6f3922bbc572a9c5b2274ef8fd70ec2b Mon Sep 17 00:00:00 2001 From: likechrisss Date: Sun, 29 Dec 2024 00:19:13 -0500 Subject: [PATCH 2/5] Fixed an issue within the README --- solutions/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solutions/README.md b/solutions/README.md index 71903884f..f27d2fb8c 100644 --- a/solutions/README.md +++ b/solutions/README.md @@ -17,4 +17,4 @@ spongecase("hello world") spongecase("Python") # Output: "pYtHoN" -- Challenge Link: [GitHub Issue](https:https://github.com/MIT-Emerging-Talent/ET6-foundations-group-04/issues/2) +- Challenge Link: [GitHub Issue](https://github.com/MIT-Emerging-Talent/ET6-foundations-group-04/issues/2) From 9c9d817250c5c64e69feef8004980878f7a328a8 Mon Sep 17 00:00:00 2001 From: likechrisss Date: Sun, 29 Dec 2024 14:23:40 -0500 Subject: [PATCH 3/5] Fixed the structure --- solutions/tests/challenge_2/README.md | 59 --------------------------- 1 file changed, 59 deletions(-) delete mode 100644 solutions/tests/challenge_2/README.md diff --git a/solutions/tests/challenge_2/README.md b/solutions/tests/challenge_2/README.md deleted file mode 100644 index b6eefe12e..000000000 --- a/solutions/tests/challenge_2/README.md +++ /dev/null @@ -1,59 +0,0 @@ -# Tests - -This directory contains the unit tests for the project. -The tests are written using the `unittest` framework. - -## Running Tests - -To run the tests, use the following command: - -```sh -python -m unittest -``` - -This command will automatically discover and run all the test cases in this directory. - -## Directory Structure - -The tests are organized as follows: - -```md -solutions/ - tests/ - __init__.py - test_example.py -``` - -- `__init__.py`: This file makes the directory a Python package. -- `test_example.py`: This file contains example test cases. - -## Writing Tests - -To add new tests, create a new file in the `tests` directory -and define your test cases using the `unittest` framework. - -Here is an example of a simple test case: - -```python -import unittest - -class TestExample(unittest.TestCase): - def test_addition(self): - self.assertEqual(1 + 1, 2) - -``` - -## Test Coverage - -Ensure that your tests cover all the critical parts of your codebase. -Aim for high test coverage to catch potential issues early. - -## Contributing - -If you would like to contribute to the tests, please follow these guidelines: - -1. Write clear and concise test cases. -2. Ensure that your tests pass before submitting a pull request. -3. Follow the existing code style and conventions. - -Let's maintain a high-quality codebase! 👩‍💻✨🚀 From 4b5980f6cb626f093deb9006e8750a43266ec5dd Mon Sep 17 00:00:00 2001 From: likechrisss Date: Sun, 29 Dec 2024 14:50:25 -0500 Subject: [PATCH 4/5] Issues running tests --- solutions/challenge_2/__init__.py | 1 - solutions/tests/challenge_2/__init__.py | 1 - 2 files changed, 2 deletions(-) diff --git a/solutions/challenge_2/__init__.py b/solutions/challenge_2/__init__.py index 8b1378917..e69de29bb 100644 --- a/solutions/challenge_2/__init__.py +++ b/solutions/challenge_2/__init__.py @@ -1 +0,0 @@ - diff --git a/solutions/tests/challenge_2/__init__.py b/solutions/tests/challenge_2/__init__.py index 8b1378917..e69de29bb 100644 --- a/solutions/tests/challenge_2/__init__.py +++ b/solutions/tests/challenge_2/__init__.py @@ -1 +0,0 @@ - From 07ae2a2c73f5c5c7dae4b00db725f1a57a25c38c Mon Sep 17 00:00:00 2001 From: RamonColmenares Date: Sun, 29 Dec 2024 14:59:51 -0500 Subject: [PATCH 5/5] add init file on tests folder to fix issue 0 tests run --- 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