-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swap_letters review #48
Conversation
Created on 08/01/2024 | ||
|
||
@author: Tibyan Khalid | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring is good for keeping track of the file's creation and author. However, it would be more helpful if you included a brief description of the file's purpose or functionality here. For example:
"""This file contains the function Swap_letters that swaps the case of each letter in a string."""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea yeah okay I'll do that now
|
||
>>> Swap_letters("HeLlO") | ||
'hElLo' | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring is clear and provides example usage (which is good for doctests). However:
Add edge cases in the doctests, such as empty strings, strings with digits, or special characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added the edge cases tests in the tests file already
'hElLo' | ||
""" | ||
if not isinstance(string, str): | ||
"Make sure the expected input is a string" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string literal "Make sure the expected input is a string" doesn’t do anything in the code. It should either be removed or converted to a comment:
Make sure the expected input is a string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just for documenting purposes, it acts as a comment
changed_string = changed_string + char.lower() | ||
else: | ||
changed_string = changed_string + char | ||
return changed_string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function implementation is clear, but you can simplify the concatenation in the loop:
changed_string += char.upper() if char.islower() else char.lower() if char.isupper() else char
Using += is cleaner and avoids multiple concatenations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I the only one who doesn't like " += " haha, but yeah I think it definitely is clearer I'll change it now
Created on 08/01/2024 | ||
|
||
@author: Tibyan Khalid | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the previous file—consider adding a description of what the test file is testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay sure
solutions/tests/test_Swap_letters.py
Outdated
|
||
|
||
class TestSwapletters(unittest.TestCase): | ||
"""Unittests for the Swap_letters function""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class name TestSwapletters should be in PascalCase, which is correct. However, the name should be more descriptive, such as TestSwapLettersFunctionality to better describe what exactly is being tested.
The docstring for the class is good, but could be more specific. For example:
"""Test cases for validating the behavior of the Swap_letters function, including edge cases."""
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted I'll make it more descriptive right now
|
||
def test_lowercase_all(self): | ||
"Testing from lowercase to uppercase" | ||
self.assertEqual(Swap_letters("tibyan"), "TIBYAN") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s a good idea to add edge case tests, such as testing an empty string or special characters.
You could consider adding more boundary tests for edge cases (empty strings, non-letters).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I added them omg, okay I'll add them right nowww
…ases tests and more descriptive docstrings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice Job
name: solution review
about: A template PR for code review with a checklist
The function convert all lowercase letters to uppercase letters and vice versa.
Input: string
Return: the modified string
Sample input:
"Hello World"
Output:
"hELLO wORLD"
Behavior
Files
/tests/test_file_name.py
Unit Tests
Function Docstring
Raises:
The Function
Strategy
Do's
Don'ts
Implementation
when it's too restricting.
print
statements anywhere