feat: kata transforms sentence into hashtag. test: test cases for hashtag generator.
This commit is contained in:
parent
7ee6263630
commit
52eb98b8fa
19
src/codewars/kata_the_hashtag_generator.py
Normal file
19
src/codewars/kata_the_hashtag_generator.py
Normal file
@ -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
|
||||||
24
tests/tests_codewars/test_the_hashtag_generator.py
Normal file
24
tests/tests_codewars/test_the_hashtag_generator.py
Normal file
@ -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
|
||||||
Loading…
x
Reference in New Issue
Block a user