From 52eb98b8fac9cdcb64d8b22c562ed5124957c328 Mon Sep 17 00:00:00 2001 From: zimmersandro Date: Tue, 23 Jun 2026 22:16:25 +0200 Subject: [PATCH] feat: kata transforms sentence into hashtag. test: test cases for hashtag generator. --- src/codewars/kata_the_hashtag_generator.py | 19 +++++++++++++++ .../test_the_hashtag_generator.py | 24 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/codewars/kata_the_hashtag_generator.py create mode 100644 tests/tests_codewars/test_the_hashtag_generator.py diff --git a/src/codewars/kata_the_hashtag_generator.py b/src/codewars/kata_the_hashtag_generator.py new file mode 100644 index 0000000..04b9e32 --- /dev/null +++ b/src/codewars/kata_the_hashtag_generator.py @@ -0,0 +1,19 @@ +def generate_hashtag(s): + if len(s) == 0: + return False + + words = s.split() + hashtag = ["#"] + + for word in words: + word = word.lower() + word = [x for x in word] + word[0] = word[0].upper() + word = "".join(word) + hashtag.append(word) + + s = "".join(hashtag) + + if len(s) > 140: + return False + return s diff --git a/tests/tests_codewars/test_the_hashtag_generator.py b/tests/tests_codewars/test_the_hashtag_generator.py new file mode 100644 index 0000000..c41ed1b --- /dev/null +++ b/tests/tests_codewars/test_the_hashtag_generator.py @@ -0,0 +1,24 @@ +from src.codewars.kata_the_hashtag_generator import generate_hashtag +import pytest + + +@pytest.mark.parametrize( + ("s", "expected"), + [ + ("Codewars", "#Codewars"), + ("Codewars ", "#Codewars"), + (" Codewars", "#Codewars"), + ("Codewars Is Nice", "#CodewarsIsNice"), + ("codewars is nice", "#CodewarsIsNice"), + ("CoDeWaRs is niCe", "#CodewarsIsNice"), + ("c i n", "#CIN"), + ("codewars is nice", "#CodewarsIsNice"), + ("", False), + ( + "Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong", + False, + ), + ], +) +def test_generate_hashtag(s, expected): + assert generate_hashtag(s) == expected