Skip to content

Commit afdc177

Browse files
committed
Refactor tests for readability
1 parent 7e0037d commit afdc177

File tree

1 file changed

+55
-17
lines changed

1 file changed

+55
-17
lines changed

tests/test_coverage.py

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,88 @@
1-
# -*- coding: utf-8 -*-
2-
1+
import os
32
import sys
43
from .context import wordsegment
5-
from wordsegment import segment, main
4+
from wordsegment import load, main, segment
5+
6+
load()
67

78
def test_segment_0():
8-
assert segment('choosespain') == ['choose', 'spain']
9+
result = ['choose', 'spain']
10+
assert segment(''.join(result)) == result
911

1012
def test_segment_1():
11-
assert segment('thisisatest') == ['this', 'is', 'a', 'test']
13+
result = ['this', 'is', 'a', 'test']
14+
assert segment(''.join(result)) == result
1215

1316
def test_segment_2():
14-
assert segment('wheninthecourseofhumaneventsitbecomesnecessary') == ['when', 'in', 'the', 'course', 'of', 'human', 'events', 'it', 'becomes', 'necessary']
17+
result = [
18+
'when', 'in', 'the', 'course', 'of', 'human', 'events', 'it',
19+
'becomes', 'necessary'
20+
]
21+
assert segment(''.join(result)) == result
1522

1623
def test_segment_3():
17-
assert segment('whorepresents') == ['who', 'represents']
24+
result = ['who', 'represents']
25+
assert segment(''.join(result)) == result
1826

1927
def test_segment_4():
20-
assert segment('expertsexchange') == ['experts', 'exchange']
28+
result = ['experts', 'exchange']
29+
assert segment(''.join(result)) == result
2130

2231
def test_segment_5():
23-
assert segment('speedofart') == ['speed', 'of', 'art']
32+
result = ['speed', 'of', 'art']
33+
assert segment(''.join(result)) == result
2434

2535
def test_segment_6():
26-
assert segment('nowisthetimeforallgood') == ['now', 'is', 'the', 'time', 'for', 'all', 'good']
36+
result = ['now', 'is', 'the', 'time', 'for', 'all', 'good']
37+
assert segment(''.join(result)) == result
2738

2839
def test_segment_7():
29-
assert segment('itisatruthuniversallyacknowledged') == ['it', 'is', 'a', 'truth', 'universally', 'acknowledged']
40+
result = ['it', 'is', 'a', 'truth', 'universally', 'acknowledged']
41+
assert segment(''.join(result)) == result
3042

3143
def test_segment_8():
32-
assert segment('itwasabrightcolddayinaprilandtheclockswerestrikingthirteen') == ['it', 'was', 'a', 'bright', 'cold', 'day', 'in', 'april', 'and', 'the', 'clocks', 'were', 'striking', 'thirteen']
44+
result = [
45+
'it', 'was', 'a', 'bright', 'cold', 'day', 'in', 'april', 'and', 'the',
46+
'clocks', 'were', 'striking', 'thirteen'
47+
]
48+
assert segment(''.join(result)) == result
3349

3450
def test_segment_9():
35-
assert segment('itwasthebestoftimesitwastheworstoftimesitwastheageofwisdomitwastheageoffoolishness') == ['it', 'was', 'the', 'best', 'of', 'times', 'it', 'was', 'the', 'worst', 'of', 'times', 'it', 'was', 'the', 'age', 'of', 'wisdom', 'it', 'was', 'the', 'age', 'of', 'foolishness']
51+
result = [
52+
'it', 'was', 'the', 'best', 'of', 'times', 'it', 'was', 'the', 'worst',
53+
'of', 'times', 'it', 'was', 'the', 'age', 'of', 'wisdom', 'it', 'was',
54+
'the', 'age', 'of', 'foolishness'
55+
]
56+
assert segment(''.join(result)) == result
3657

3758
def test_segment_10():
38-
assert segment('asgregorsamsaawokeonemorningfromuneasydreamshefoundhimselftransformedinhisbedintoagiganticinsect') == ['as', 'gregor', 'samsa', 'awoke', 'one', 'morning', 'from', 'uneasy', 'dreams', 'he', 'found', 'himself', 'transformed', 'in', 'his', 'bed', 'into', 'a', 'gigantic', 'insect']
59+
result = [
60+
'as', 'gregor', 'samsa', 'awoke', 'one', 'morning', 'from', 'uneasy',
61+
'dreams', 'he', 'found', 'himself', 'transformed', 'in', 'his', 'bed',
62+
'into', 'a', 'gigantic', 'insect'
63+
]
64+
assert segment(''.join(result)) == result
3965

4066
def test_segment_11():
41-
assert segment('inaholeinthegroundtherelivedahobbitnotanastydirtywetholefilledwiththeendsofwormsandanoozysmellnoryetadrybaresandyholewithnothinginittositdownonortoeatitwasahobbitholeandthatmeanscomfort') == ['in', 'a', 'hole', 'in', 'the', 'ground', 'there', 'lived', 'a', 'hobbit', 'not', 'a', 'nasty', 'dirty', 'wet', 'hole', 'filled', 'with', 'the', 'ends', 'of', 'worms', 'and', 'an', 'oozy', 'smell', 'nor', 'yet', 'a', 'dry', 'bare', 'sandy', 'hole', 'with', 'nothing', 'in', 'it', 'to', 'sit', 'down', 'on', 'or', 'to', 'eat', 'it', 'was', 'a', 'hobbit', 'hole', 'and', 'that', 'means', 'comfort']
67+
result = [
68+
'in', 'a', 'hole', 'in', 'the', 'ground', 'there', 'lived', 'a',
69+
'hobbit', 'not', 'a', 'nasty', 'dirty', 'wet', 'hole', 'filled', 'with',
70+
'the', 'ends', 'of', 'worms', 'and', 'an', 'oozy', 'smell', 'nor',
71+
'yet', 'a', 'dry', 'bare', 'sandy', 'hole', 'with', 'nothing', 'in',
72+
'it', 'to', 'sit', 'down', 'on', 'or', 'to', 'eat', 'it', 'was', 'a',
73+
'hobbit', 'hole', 'and', 'that', 'means', 'comfort'
74+
]
75+
assert segment(''.join(result)) == result
4276

4377
def test_segment_12():
44-
assert segment('faroutintheunchartedbackwatersoftheunfashionableendofthewesternspiralarmofthegalaxyliesasmallunregardedyellowsun') == ['far', 'out', 'in', 'the', 'uncharted', 'backwaters', 'of', 'the', 'unfashionable', 'end', 'of', 'the', 'western', 'spiral', 'arm', 'of', 'the', 'galaxy', 'lies', 'a', 'small', 'un', 'regarded', 'yellow', 'sun']
78+
result = [
79+
'far', 'out', 'in', 'the', 'uncharted', 'backwaters', 'of', 'the',
80+
'unfashionable', 'end', 'of', 'the', 'western', 'spiral', 'arm', 'of',
81+
'the', 'galaxy', 'lies', 'a', 'small', 'un', 'regarded', 'yellow', 'sun'
82+
]
83+
assert segment(''.join(result)) == result
4584

4685
def test_main():
4786
main(['tests/test.txt'])
48-
import os
4987
result = os.linesep.join(('choose spain', 'this is a test')) + os.linesep
5088
assert sys.stdout.getvalue() == result

0 commit comments

Comments
 (0)