Skip to content

Commit

Permalink
bite 115
Browse files Browse the repository at this point in the history
  • Loading branch information
boraxpr committed Nov 5, 2019
1 parent be4f208 commit 73f4954
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 115/indents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def count_indents(text):
"""Takes a string and counts leading white spaces, return int count"""
counts = 0
for char in text:
if char.isspace() and char != "\t" and char !="\n":
counts += 1
elif char.isalpha():
break
return counts

# print(count_indents("\t\toxzcxc"))
# "ddd dd dd".
16 changes: 16 additions & 0 deletions 115/test_indents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest

from indents import count_indents


@pytest.mark.parametrize("input_string, count", [
('string ', 0),
(' string', 2),
(' string', 4),
(' string', 12),
('\t\tstring', 0),
(' str ing', 2),
(' str ', 2),
])
def test_count_indents(input_string, count):
assert count_indents(input_string) == count

0 comments on commit 73f4954

Please sign in to comment.