Skip to content

Commit

Permalink
Added changes as per request of the reveiwer such as including edge c…
Browse files Browse the repository at this point in the history
…ases tests and more descriptive docstrings
  • Loading branch information
TibyanKhalid committed Jan 12, 2025
1 parent fdc1af4 commit c3d22d0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
8 changes: 5 additions & 3 deletions solutions/Swap_letters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Created on 08/01/2024
@author: Tibyan Khalid
This file contains the function Swap_letters that swaps the case of each letter in a string.
"""


Expand Down Expand Up @@ -29,9 +31,9 @@ def Swap_letters(string: str) -> str:
changed_string = ""
for char in string:
if char.islower():
changed_string = changed_string + char.upper()
changed_string += char.upper()
elif char.isupper():
changed_string = changed_string + char.lower()
changed_string += char.lower()
else:
changed_string = changed_string + char
changed_string += char
return changed_string
15 changes: 13 additions & 2 deletions solutions/tests/test_Swap_letters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
Created on 08/01/2024
@author: Tibyan Khalid
This file contains boundary cases and defensive assertion tests for the function Swap_letters.
"""

import unittest

from ..Swap_letters import Swap_letters


class TestSwapletters(unittest.TestCase):
"""Unittests for the Swap_letters function"""
class TestSwapLettersFunctionality(unittest.TestCase):
"""Test cases for validating the behavior of the Swap_letters function,
including edge cases and defensive assertions."""

def test_lowercase_all(self):
"Testing from lowercase to uppercase"
Expand All @@ -33,6 +36,14 @@ def test_spaces(self):
"Handle spaces correctly"
self.assertEqual(Swap_letters("Hello World"), "hELLO wORLD")

def test_empty_string(self):
"Test for an empty string input"
self.assertEqual(Swap_letters(""), "")

def test_special_characters(self):
"Test for special characters input"
self.assertEqual(Swap_letters("1234!@#$"), "1234!@#$")


if __name__ == "__main__":
unittest.main()

0 comments on commit c3d22d0

Please sign in to comment.