-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_justify.py
55 lines (42 loc) · 1.35 KB
/
test_justify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pytest
from justify import justify
# Width must be greater than 0
def test_zero_width():
with pytest.raises(ValueError):
justify('', 0)
# Empty paragraph should result in an empty list
def test_empty_paragraph():
assert justify('', 1) == []
# Word longer than the width should be placed on its own line
def test_long_word():
paragraph = 'Hello, world!'
assert justify(paragraph, 1) == [
'Hello,',
'world!'
]
# Two words should be kept as one line if the width is just enough
def test_one_line():
paragraph = 'Hello, world!'
assert justify(paragraph, len(paragraph)) == [
'Hello, world!'
]
# Two words should be put on two lines if the width is not enough for both
def test_two_lines():
paragraph = 'Hello, world!'
assert justify(paragraph, len(paragraph) - 1) == [
'Hello,',
'world!'
]
# Example from the problem statement
def test_example():
paragraph = 'This is a sample text but a complicated problem to be solved, so we are adding more text to see that it actually works.'
width = 20
assert justify(paragraph, width) == [
"This is a sample",
"text but a",
"complicated problem",
"to be solved, so we",
"are adding more text",
"to see that it",
"actually works.",
]