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
Merged

Capital letters #32

merged 16 commits into from
Jan 12, 2025

Conversation

Kareiman
Copy link

@Kareiman Kareiman commented Jan 3, 2025


name: solution review
about: A template PR for code review with a checklist

Behavior

Files

  • The file name describes the function's behavior
  • There is a module docstring in the function file
  • The test file's name matches the function file name -
    /tests/test_file_name.py
  • There is a module docstring in the tests file

Unit Tests

  • The test class has a helpful name in PascalCase
  • The test class has a docstring
  • Every unit test has
    • A helpful name
    • A clear docstring
    • Only one assertion
    • There is no logic in the unit test
  • All tests pass
  • There are tests for defensive assertions
  • There are tests for boundary cases

Function Docstring

  • The function's behavior is described
  • The function's arguments are described:
    • Type
    • Purpose
    • Other assumptions (eg. if it's a number, what's the expected range?)
  • The return value is described
    • Type
    • Other assumptions are documented
  • The defensive assertions are documented using Raises:
    • Each assumption about an argument is checked with an assertion
    • Each assertion checks for only one assumption about the argument
  • Include 3 or more (passing!) doctests

The Function

  • The function's name describes it's behavior
  • The function's name matches the file name
  • The function has correct type annotations
  • The function is not called in the function file

Strategy

Do's

  • Variable names help to understand the strategy
  • Any comments are clear and describe the strategy
  • Lines of code are spaced to help show different stages of the strategy

Don'ts

  • The function's strategy is not described in the documentation
  • Comments explain the strategy, not the implementation
  • The function does not have more comments than code
    • If it does, consider finding a new strategy or a simpler implementation

Implementation

  • The code passes the formatting checks
  • The code passes all Ruff linting checks
  • The code has no (reasonable) Pylint errors
    • In code review, you can decide when fixing a Pylint error is helpful and
      when it's too restricting.
  • Variables are named with snake_case
  • Variable names are clear and helpful
  • The code follows the strategy as simply as possible
  • The implementation is as simple as possible given the strategy
  • There are no commented lines of code
  • There are no print statements anywhere
  • The code includes defensive assertions
  • Defensive assertions include as little logic as possible

@Kareiman Kareiman linked an issue Jan 3, 2025 that may be closed by this pull request
@Frank2446-dotcom Frank2446-dotcom requested review from Frank2446-dotcom and removed request for Frank2446-dotcom January 8, 2025 05:09
@Kareiman Kareiman self-assigned this Jan 9, 2025
Copy link

@Frank2446-dotcom Frank2446-dotcom left a comment

Choose a reason for hiding this comment

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

The challenge is tackled effectively, with a well-implemented solution and comprehensive testing to ensure functionality across a variety of scenarios, including standard, edge, and defensive cases. Excellent work on maintaining clarity, input validation, and robust test coverage, demonstrating a thorough understanding of the task—well done!

solutions/tests/test_convert_to_capital.py Show resolved Hide resolved
solutions/convert_to_capital.py Show resolved Hide resolved
@Emanfalouji Emanfalouji requested review from Emanfalouji and removed request for Emanfalouji January 11, 2025 20:55
# -*- coding: utf-8 -*-

"""
A module that converts letters to upper case

Choose a reason for hiding this comment

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

just correct that uppercase is a one word

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

parameters:
user_text = in str

Choose a reason for hiding this comment

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

it could be corrected to this format
user_text (type): description
like
user_text (str): The user input text to be converted to uppercase.

parameters:
user_text = in str
returns:
user_text in capital letters

Choose a reason for hiding this comment

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

you could add the return type here to be like this
(str) : user_text in capital letters

user_text in capital letters

raises:
AssertionError: if input is empty

Choose a reason for hiding this comment

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

could you add as you mentioned in the assrtionError message to be like this
AssertionError: If the input is empty or contains only spaces.

raises:
AssertionError: if input is empty

examples:

Choose a reason for hiding this comment

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

could you rewrite Examples with capital E
also the previous lines , to start with capital letter (Raises , Returns and Parameters)


"""
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

"""


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.

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


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.


@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



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

Copy link

@Frank2446-dotcom Frank2446-dotcom left a comment

Choose a reason for hiding this comment

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

Well done

Copy link

@Emanfalouji Emanfalouji left a comment

Choose a reason for hiding this comment

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

Great work kariman ..

@Frank2446-dotcom Frank2446-dotcom merged commit 960c83b into main Jan 12, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Challenge_Convert_Letters_Capital
4 participants