From 284bad0ba7e90c2c14ee3adee729af994c0fb37e Mon Sep 17 00:00:00 2001 From: "Kareeiman K." Date: Sun, 12 Jan 2025 04:13:00 +0400 Subject: [PATCH] edits after second review --- solutions/convert_to_uppercase.py | 40 ++++++++++++++ solutions/tests/test_convert_to_uppercase.py | 55 ++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 solutions/convert_to_uppercase.py create mode 100644 solutions/tests/test_convert_to_uppercase.py diff --git a/solutions/convert_to_uppercase.py b/solutions/convert_to_uppercase.py new file mode 100644 index 000000000..0e1888acb --- /dev/null +++ b/solutions/convert_to_uppercase.py @@ -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() diff --git a/solutions/tests/test_convert_to_uppercase.py b/solutions/tests/test_convert_to_uppercase.py new file mode 100644 index 000000000..7d9684020 --- /dev/null +++ b/solutions/tests/test_convert_to_uppercase.py @@ -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_capital +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""" + self.assertEqual(convert_to_uppercase("kareiman"), "KAREIMAN") + + def test_some_are_capital_letters(self): + """It should convert all letters to capital""" + self.assertEqual(convert_to_uppercase("kAREiMan"), "KAREIMAN") + + def test_full_sentence(self): + """It should convert all words to capital""" + 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("")