-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from jtprogru/dev
upd: #19 - Add task0029
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |