-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathtest_coverage.py
More file actions
110 lines (90 loc) · 3.49 KB
/
test_coverage.py
File metadata and controls
110 lines (90 loc) · 3.49 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import os
import sys
from .context import wordsegment
from wordsegment import (
clean, load, main, isegment, segment, UNIGRAMS, BIGRAMS, WORDS,
)
load()
def test_unigrams():
assert 'test' in UNIGRAMS
def test_bigrams():
assert 'in the' in BIGRAMS
def test_clean():
assert clean("Can't buy me love!") == 'cantbuymelove'
def test_segment_0():
result = ['choose', 'spain']
assert segment(''.join(result)) == result
def test_segment_1():
result = ['this', 'is', 'a', 'test']
assert segment(''.join(result)) == result
def test_segment_2():
result = [
'when', 'in', 'the', 'course', 'of', 'human', 'events', 'it',
'becomes', 'necessary'
]
assert segment(''.join(result)) == result
def test_segment_3():
result = ['who', 'represents']
assert segment(''.join(result)) == result
def test_segment_4():
result = ['experts', 'exchange']
assert segment(''.join(result)) == result
def test_segment_5():
result = ['speed', 'of', 'art']
assert segment(''.join(result)) == result
def test_segment_6():
result = ['now', 'is', 'the', 'time', 'for', 'all', 'good']
assert segment(''.join(result)) == result
def test_segment_7():
result = ['it', 'is', 'a', 'truth', 'universally', 'acknowledged']
assert segment(''.join(result)) == result
def test_segment_8():
result = [
'it', 'was', 'a', 'bright', 'cold', 'day', 'in', 'april', 'and', 'the',
'clocks', 'were', 'striking', 'thirteen'
]
assert segment(''.join(result)) == result
def test_segment_9():
result = [
'it', 'was', 'the', 'best', 'of', 'times', 'it', 'was', 'the', 'worst',
'of', 'times', 'it', 'was', 'the', 'age', 'of', 'wisdom', 'it', 'was',
'the', 'age', 'of', 'foolishness'
]
assert segment(''.join(result)) == result
def test_segment_10():
result = [
'as', 'gregor', 'samsa', 'awoke', 'one', 'morning', 'from', 'uneasy',
'dreams', 'he', 'found', 'himself', 'transformed', 'in', 'his', 'bed',
'into', 'a', 'gigantic', 'insect'
]
assert segment(''.join(result)) == result
def test_segment_11():
result = [
'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'
]
assert list(isegment(''.join(result))) == result
def test_segment_12():
result = [
'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'
]
assert segment(''.join(result)) == result
def test_main():
main(['tests/test.txt'])
result = os.linesep.join(('choose spain', 'this is a test')) + os.linesep
assert sys.stdout.getvalue() == result
def test_words():
assert len(WORDS) > 0
assert WORDS[0] == 'aa'
assert WORDS[-1] == 'zzz'
def test_keep_case():
assert segment('\tMaintainCasing \nwith variableSpaCING', True) \
== ['Maintain', 'Casing', 'with', 'variable', 'SpaCING']
assert segment('\tMaintainCasing \nwith variableSpaCING', False) \
== ['maintain', 'casing', 'with', 'variable', 'spacing']