Skip to content
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

Capital letters #32

Merged
merged 16 commits into from
Jan 12, 2025
Binary file added .pylintrc
Binary file not shown.
39 changes: 39 additions & 0 deletions solutions/convert_to_capital.py
Kareiman marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# !/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
A module that converts letters to uppercase

Created on 31 12 2024

@author: Kareiman Altayeb
"""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improvement: The module docstring does not specify the function’s behavior as clearly as it could. Consider improving the explanation of the function and its purpose.

"""
This function takes a user input string and returns the string with all characters in uppercase.
It handles edge cases where the input is empty or contains only spaces.
"""

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added more description but explaining the edge behavior is mentioned within the tests



def convert_to_capital(user_text: str) -> str:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Current: convert_to_capital

Improvement: While this name is clear, it could be more explicit in describing what the function does, such as convert_to_uppercase, to clearly convey that it deals with uppercase conversion. "Capital" can be ambiguous because people might think it deals with capitalization rules (e.g., first letter capitalized), not case swapping.

Suggested Improvement: convert_to_uppercase

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

"""Asks the user to enter a text and returns the text in capital

Parameters:
user_text (str): The user input text to be converted to uppercase.

Returns:
str : user_text in capital letters

Raises:
AssertionError: If the input is empty or contains only spaces.

Examples:
>>> convert_to_capital('hello')
'HELLO'
>>> convert_to_capital('HelLo')
'HELLO'
>>> convert_to_capital('123hello')
'123HELLO'
"""

user_text = user_text.strip()

if not user_text:
raise AssertionError("Entry cannot be empty or just spaces")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improvement: The use of strip() and then checking if not user_text is good. However, you can directly handle empty strings in the assertion, which makes the function simpler:
Action: Use strip() to handle spaces at the beginning or end of the input more cleanly in the assertion check.

e.g

if not user_text.strip():
raise AssertionError("Entry cannot be empty or just spaces")

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already call strip() when checking for empty strings, so there’s no need to call it again on user_text, it is redundant.

return user_text.upper()
40 changes: 40 additions & 0 deletions solutions/convert_to_uppercase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# !/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
A module that converts letters to uppercase

Created on 31 12 2024

@author: Kareiman Altayeb
"""


def convert_to_uppercase(user_text: str) -> str:
"""Asks the user to enter a text and returns the text in capital
with all characters in uppercase

Parameters:
user_text (str): The user input text to be converted to uppercase.

Returns:
str : user_text in capital letters

Raises:
AssertionError: If the input is empty or contains only spaces.

Examples:
>>> convert_to_uppercase('hello')
'HELLO'
>>> convert_to_uppercase('HelLo')
'HELLO'
>>> convert_to_uppercase('123hello')
'123HELLO'
"""

user_text = user_text.strip()

if not user_text:
raise AssertionError("Entry cannot be empty or just spaces")

return user_text.upper()
55 changes: 55 additions & 0 deletions solutions/tests/test_convert_to_capital.py
Kareiman marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# !/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
A module to test convert_to_capital function

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add here the Test categories with Standard cases, Edge cases, and Defensive tests

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Test categories:
- Standard cases: Regular text with different length
- Edge cases: Mix of different data types
- Defensive tests: Empty input

Created on 03 01 2025

@author: Kareiman Altayeb
"""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test file’s docstring is minimal and could be expanded to better describe the purpose of the tests.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of the edge, classical cases and defensive tests is explained below

import unittest

# To test convert_to_capital
from solutions.convert_to_capital import convert_to_capital


class TestConvertCapitalLetters(unittest.TestCase):
"Tests convert_to_capital function"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improvement: The test class name TestConvertCapitalLetters is clear, but it could be improved to use a more conventional PascalCase naming style.

Action: Use PascalCase for the test class name, e.g., TestConvertToCapital.

class TestConvertToCapital(unittest.TestCase):

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


# Standard test cases

def test_all_small_letters(self):
"""It should convert all letters to capital"""
self.assertEqual(convert_to_capital("kareiman"), "KAREIMAN")

def test_some_are_capital_letters(self):
"""It should convert all letters to capital"""
self.assertEqual(convert_to_capital("kAREiMan"), "KAREIMAN")

def test_full_sentence(self):
"""It should convert all words to capital"""
self.assertEqual(convert_to_capital("happy new year"), "HAPPY NEW YEAR")

# Edge cases

def test_mixed_with_numbers(self):
"""It should return the numbers the same"""
self.assertEqual(convert_to_capital("12345kareiman"), "12345KAREIMAN")

def test_special_characters(self):
"""It should return special characters the same"""
self.assertEqual(convert_to_capital("?!!!"), "?!!!")

# Defensive tests

def test_empty_entry(self):
"""It should raise an error for space or empty entry"""
with self.assertRaises(AssertionError):
convert_to_capital("")
55 changes: 55 additions & 0 deletions solutions/tests/test_convert_to_uppercase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# !/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
A module to test convert_to_uppercase function

Test categories:
- Standard cases: Regular text with different length
- Edge cases: Mix of different data types
- Defensive tests: Empty input

Created on 03 01 2025

@author: Kareiman Altayeb
"""

import unittest

# To test convert_to_uppercase
from solutions.convert_to_uppercase import convert_to_uppercase


class TestConvertToCapitalLetters(unittest.TestCase):
"Tests convert_to_capital function"

# Standard test cases

def test_all_small_letters(self):
"""It should convert all letters to capital letter"""
self.assertEqual(convert_to_uppercase("kareiman"), "KAREIMAN")

def test_some_are_capital_letters(self):
"""It should convert all letters to capital letters"""
self.assertEqual(convert_to_uppercase("kAREiMan"), "KAREIMAN")

def test_full_sentence(self):
"""It should convert all words to capital letters"""
self.assertEqual(convert_to_uppercase("happy new year"), "HAPPY NEW YEAR")

# Edge cases

def test_mixed_with_numbers(self):
"""It should return the numbers the same"""
self.assertEqual(convert_to_uppercase("12345kareiman"), "12345KAREIMAN")

def test_special_characters(self):
"""It should return special characters the same"""
self.assertEqual(convert_to_uppercase("?!!!"), "?!!!")

# Defensive tests

def test_empty_entry(self):
"""It should raise an error for space or empty entry"""
with self.assertRaises(AssertionError):
convert_to_uppercase("")
Loading