Skip to content

Commit

Permalink
Add to_uppercase module and tests with Ruff formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
NimahMasuud committed Jan 11, 2025
1 parent 11eb838 commit 9799df1
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 87 deletions.
38 changes: 0 additions & 38 deletions solutions/multiply.py

This file was deleted.

49 changes: 0 additions & 49 deletions solutions/tests/test_multiply.py

This file was deleted.

40 changes: 40 additions & 0 deletions solutions/tests/test_to_uppercase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Unit tests for the to_uppercase function.
Created on XX XX XX
@author: Your Name
"""

import unittest
from solutions.to_uppercase import to_uppercase


class TestToUppercase(unittest.TestCase):
"""Tests for the to_uppercase function."""

def test_valid_string(self):
"""It should convert lowercase to uppercase."""
self.assertEqual(to_uppercase("hello"), "HELLO")

def test_mixed_case_string(self):
"""It should convert mixed case to uppercase."""
self.assertEqual(to_uppercase("Python"), "PYTHON")

def test_alphanumeric_string(self):
"""It should handle alphanumeric strings."""
self.assertEqual(to_uppercase("123abc"), "123ABC")

def test_empty_string(self):
"""It should return an empty string."""
self.assertEqual(to_uppercase(""), "")

def test_non_string_input(self):
"""It should raise TypeError for non-string inputs."""
with self.assertRaises(TypeError):
to_uppercase(123)


if __name__ == "__main__":
unittest.main()
37 changes: 37 additions & 0 deletions solutions/to_uppercase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Module for converting strings to uppercase.
Module contents:
- to_uppercase: Converts a given string to uppercase.
Created on XX XX XX
@author: Your Name
"""


def to_uppercase(s: str) -> str:
"""Converts a string to uppercase.
Parameters:
s (str): The string to be converted.
Returns:
str: The string with all characters in uppercase.
Raises:
TypeError: If the input is not a string.
>>> to_uppercase("hello")
'HELLO'
>>> to_uppercase("Python")
'PYTHON'
>>> to_uppercase("123abc")
'123ABC'
"""
if not isinstance(s, str):
raise TypeError("Input must be a string.")
return s.upper()

0 comments on commit 9799df1

Please sign in to comment.