-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtests.py
executable file
·69 lines (52 loc) · 1.99 KB
/
tests.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
"""
This is the "test" module.
This shows how a doc test can be used to test the module, e.g.
>>> wc = WordCounter("samples/test1.txt")
>>> wc.total_words
319
>>> wc.top_10
['sed', 'quis', 'eu', 'ip-sum', 'vel', 'et', 'ultricies', 'nunc', 'tortor', 'leo']
>>> wc = WordCounter("samples/test6.txt")
>>> wc.total_words
1095695
Below assert is used to check the expected values. Changing the expected values will show a fail.
The assertions are checked first.
"""
import doctest
from word_counter.counter import WordCounter
# Lorem ipsum file with hyphenated words
wc = WordCounter("samples/test1.txt")
assert wc.top_10 == ['sed', 'ipsum', 'quis', 'eu', 'ip-sum', 'vel', 'et', 'ultricies', 'nunc', 'tortor'], wc.top_10
assert wc.total_words == 326, wc.total_words
# Test basic punctuation
wc = WordCounter("samples/test2.txt")
assert wc.top_10 == ['this', 'is', 'and', 'test', 'simple', 'very', 'a'], wc.top_10
assert wc.total_words == 12, wc.total_words
# Test case sensitivity
wc = WordCounter("samples/test3.txt")
assert wc.top_10 == ['ten', 'nine', 'eight', 'seven', 'six', 'five', 'four', 'three', 'two', 'one'], wc.top_10
assert wc.total_words == 16
# Test single line file
wc = WordCounter("samples/test3.txt")
assert wc.top_10 == ['ten', 'nine', 'eight', 'seven', 'six', 'five', 'four', 'three', 'two', 'one']
assert wc.total_words == 16
# Test empty file
wc = WordCounter("samples/test5.txt")
assert wc.top_10 == []
assert wc.total_words == 0
# Test large file
wc = WordCounter("samples/test6.txt")
assert wc.top_10 == ['the', 'of', 'and', 'to', 'in', 'a', 'he', 'that', 'was', 'his'], wc.top_10
assert wc.total_words == 1095695
# Test numbers
wc = WordCounter("samples/test7.txt")
assert wc.top_10 == ['69', '123', '567', '67', '45', '345'], wc.top_10
assert wc.total_words == 12
# Test hyphens
wc = WordCounter("samples/test8.txt")
assert wc.top_10 == ['winter', 'win-ter'], wc.top_10
assert wc.total_words == 12, wc.total_words
# Uncomment to run doc-test
# doctest.testmod()
print("Done!")