Skip to content

Commit

Permalink
Merge pull request #22 from jtprogru/dev
Browse files Browse the repository at this point in the history
upd: #19 - Add task0029
  • Loading branch information
jtprogru authored Mar 7, 2023
2 parents 9b581f5 + ebaf1d9 commit 79b15ba
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tasks/task0029.py
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions tests/test_task0029.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 79b15ba

Please sign in to comment.