Skip to content

Commit 11dcb9e

Browse files
bites 162
1 parent bf13a8d commit 11dcb9e

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@
4444
/62/README.md
4545
/86/README.md
4646
/78/README.md
47+
/162/README.md

162/fill.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
HTML_SPACE = ' '
2+
3+
4+
def prefill_with_character(value, column_length=4, fill_char=HTML_SPACE):
5+
"""Prepend value with fill_char for given column_length"""
6+
return (column_length-len(str(value)))*fill_char+str(value)
7+
8+
# prefill_with_character("cxxx")

162/test_fill.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pytest
2+
3+
from fill import prefill_with_character, HTML_SPACE
4+
5+
DIFF_FILL = 'x'
6+
7+
8+
@pytest.mark.parametrize("value, len_, fill, result", [
9+
(1, 4, HTML_SPACE, f'{HTML_SPACE*3}1'),
10+
(20, 4, HTML_SPACE, f'{HTML_SPACE*2}20'),
11+
(315, 4, HTML_SPACE, f'{HTML_SPACE}315'),
12+
(1239, 4, HTML_SPACE, '1239'),
13+
(8, 5, DIFF_FILL, f'{DIFF_FILL*4}8'),
14+
(12, 5, DIFF_FILL, f'{DIFF_FILL*3}12'),
15+
(139, 5, DIFF_FILL, f'{DIFF_FILL*2}139'),
16+
(9827, 5, DIFF_FILL, f'{DIFF_FILL}9827'),
17+
(12345, 5, DIFF_FILL, '12345'),
18+
])
19+
def test_prefill_with_character(value, len_, fill, result):
20+
assert prefill_with_character(value, column_length=len_,
21+
fill_char=fill) == result

0 commit comments

Comments
 (0)