From ebaf1d9e9f0e23dc321fda36322d6720e31bec70 Mon Sep 17 00:00:00 2001 From: Michael Savin Date: Tue, 7 Mar 2023 21:40:15 +0300 Subject: [PATCH] upd: #19 - Add task0029 --- tasks/task0029.py | 30 ++++++++++++++++++++++++++++++ tests/test_task0029.py | 27 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tasks/task0029.py create mode 100644 tests/test_task0029.py diff --git a/tasks/task0029.py b/tasks/task0029.py new file mode 100644 index 0000000..73433fa --- /dev/null +++ b/tasks/task0029.py @@ -0,0 +1,30 @@ +""" +The marketing team is spending way too much time typing in hashtags. +Let's help them with our own Hashtag Generator! + +Here's the deal: + +It must start with a hashtag (#). +All words must have their first letter capitalized. +If the final result is longer than 140 chars it must return false. +If the input or the result is an empty string it must return false. + +Examples: + +" Hello there thanks for trying my Kata" => "#HelloThereThanksForTryingMyKata" +" Hello World " => "#HelloWorld" +"" => false + +""" + +from typing import Union + + +def solution(s: str) -> Union[str, bool]: + if s == "": + return False + res = "#" + s.title().replace(" ", "") + if len(res) > 140: + return False + + return res diff --git a/tests/test_task0029.py b/tests/test_task0029.py new file mode 100644 index 0000000..5a0b1e9 --- /dev/null +++ b/tests/test_task0029.py @@ -0,0 +1,27 @@ +import pytest + +from tasks.task0029 import solution + + +@pytest.mark.parametrize( + "s, result", + [ + (" Hello there thanks for trying my Kata", "#HelloThereThanksForTryingMyKata"), + (" Hello World ", "#HelloWorld"), + ("", False), + ( + "Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong Cat", + False, + ), + ("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"), + ], +) +def test_task0028_solution(s, result): + assert solution(s) == result