Skip to content

Commit 73f4954

Browse files
author
boraxpr
committed
bite 115
1 parent be4f208 commit 73f4954

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

115/indents.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
def count_indents(text):
2+
"""Takes a string and counts leading white spaces, return int count"""
3+
counts = 0
4+
for char in text:
5+
if char.isspace() and char != "\t" and char !="\n":
6+
counts += 1
7+
elif char.isalpha():
8+
break
9+
return counts
10+
11+
# print(count_indents("\t\toxzcxc"))
12+
# "ddd dd dd".

115/test_indents.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
3+
from indents import count_indents
4+
5+
6+
@pytest.mark.parametrize("input_string, count", [
7+
('string ', 0),
8+
(' string', 2),
9+
(' string', 4),
10+
(' string', 12),
11+
('\t\tstring', 0),
12+
(' str ing', 2),
13+
(' str ', 2),
14+
])
15+
def test_count_indents(input_string, count):
16+
assert count_indents(input_string) == count

0 commit comments

Comments
 (0)