|
1 |
| -# -*- coding: utf-8 -*- |
2 |
| - |
| 1 | +import os |
3 | 2 | import sys
|
4 | 3 | from .context import wordsegment
|
5 |
| -from wordsegment import segment, main |
| 4 | +from wordsegment import load, main, segment |
| 5 | + |
| 6 | +load() |
6 | 7 |
|
7 | 8 | def test_segment_0():
|
8 |
| - assert segment('choosespain') == ['choose', 'spain'] |
| 9 | + result = ['choose', 'spain'] |
| 10 | + assert segment(''.join(result)) == result |
9 | 11 |
|
10 | 12 | def test_segment_1():
|
11 |
| - assert segment('thisisatest') == ['this', 'is', 'a', 'test'] |
| 13 | + result = ['this', 'is', 'a', 'test'] |
| 14 | + assert segment(''.join(result)) == result |
12 | 15 |
|
13 | 16 | 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 |
15 | 22 |
|
16 | 23 | def test_segment_3():
|
17 |
| - assert segment('whorepresents') == ['who', 'represents'] |
| 24 | + result = ['who', 'represents'] |
| 25 | + assert segment(''.join(result)) == result |
18 | 26 |
|
19 | 27 | def test_segment_4():
|
20 |
| - assert segment('expertsexchange') == ['experts', 'exchange'] |
| 28 | + result = ['experts', 'exchange'] |
| 29 | + assert segment(''.join(result)) == result |
21 | 30 |
|
22 | 31 | def test_segment_5():
|
23 |
| - assert segment('speedofart') == ['speed', 'of', 'art'] |
| 32 | + result = ['speed', 'of', 'art'] |
| 33 | + assert segment(''.join(result)) == result |
24 | 34 |
|
25 | 35 | 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 |
27 | 38 |
|
28 | 39 | 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 |
30 | 42 |
|
31 | 43 | 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 |
33 | 49 |
|
34 | 50 | 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 |
36 | 57 |
|
37 | 58 | 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 |
39 | 65 |
|
40 | 66 | 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 |
42 | 76 |
|
43 | 77 | 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 |
45 | 84 |
|
46 | 85 | def test_main():
|
47 | 86 | main(['tests/test.txt'])
|
48 |
| - import os |
49 | 87 | result = os.linesep.join(('choose spain', 'this is a test')) + os.linesep
|
50 | 88 | assert sys.stdout.getvalue() == result
|
0 commit comments