-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
boraxpr
committed
Nov 5, 2019
1 parent
be4f208
commit 73f4954
Showing
2 changed files
with
28 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,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". |
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,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 |