Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit af3b653

Browse files
committed
Add reverse string task
1 parent e0dad5c commit af3b653

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎python_tests/test_5.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import pytest
2+
3+
4+
def reverse_string(input):
5+
if not input:
6+
raise Exception("String cannot be empty")
7+
if not input.isascii():
8+
raise Exception("String cannot be digits or other special characters")
9+
tmp = input.split(" ")
10+
return " ".join(tmp[::-1])
11+
12+
13+
def test_reverse_string():
14+
input_string = "How are you?"
15+
expected_value = "you? are How"
16+
assert reverse_string(input_string) == expected_value
17+
18+
19+
def test_reverse_string_empty():
20+
input_string = ""
21+
with pytest.raises(Exception):
22+
reverse_string(input_string)
23+
24+
25+
def test_reverse_string_with_bool():
26+
input_string = True
27+
with pytest.raises(Exception):
28+
reverse_string(input_string)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /