-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
106 lines (90 loc) · 3.29 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
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
import unittest
import main as model
def test(self, list_arg, function):
"""
Parameters:
self - pass the argument from the test* functions
list_arg - list of binary tuples of the form: [(z, y), ...]
where x is the string to be processed,
y is the expected result for the function passed
as 3rd argument to this function for the argument x.
function - function returning string result,
taking a single string as the only parameter
Fails the test unless the function evaluations for all inputs are equal to their expected values
"""
for subject in list_arg:
input_string, expected_result = subject
result = function(input_string)
if result != expected_result:
print("Expected: " + str(expected_result) + " computed: " + str(result))
print("input: " + input_string)
self.failUnless(result == expected_result)
class RegExprTests(unittest.TestCase):
def test_extract_keywords(self):
list_arg = [
('<META NAME="KLUCZOWE_1" CONTENT="aaa">'
'\n<META NAME="KLUCZOWE_2" CONTENT="ccc">'
'\n<META NAME="KLUCZOWE_3" CONTENT="sss">',
'\'aaa\', \'ccc\', \'sss\'')
]
test(self, list_arg, model.extract_keywords)
pass
def test_count_sentences(self):
list_arg = [
('Aaaaa aa aa 12.8.j.9. Aaaa. Aaaaaa12.', 3)
]
test(self, list_arg, model.count_sentences)
pass
def test_count_abbreviations(self):
list_arg = [
('etc. s. dsa.', 3),
('aaaa. ccccc. .', 0)
]
test(self, list_arg, model.count_abbreviations)
pass
def test_count_emails(self):
list_arg = [
('a1@a.a.a.com a1@a.a a@a.a', 3),
(' a@a..a ', 0)
]
test(self, list_arg, model.count_emails)
pass
def test_count_integers(self):
list_arg = [
('\n 123 -342 000000000000000000002 0000000000000 -32768 32767', 6),
('\n -327.69 327.679 1498321478934918 0000000032768 -00000000000032769 23.4 33333 -33333', 0),
('123', 1),
('23-40 32+35', 4)
]
test(self, list_arg, model.count_integers)
pass
def test_count_float_numbers(self):
list_arg = [
('a-3.2e-2a 1.2 .3 234.52 s-3.12e-2.\n.8,', 6),
(' 1e10 2e+10 4e-32 ', 0)
]
test(self, list_arg, model.count_float_numbers)
pass
def test_count_dates(self):
list_arg = [
(r'05-03-2009a w13/03/1995d 29.02.1111 2222-21-10 ', 4),
(r' 00-00-0000 02-00-1111 00-32-2222 234-55-2345 88-03-2003 ', 0)
]
test(self, list_arg, model.count_dates)
pass
def test_extract_department(self):
list_arg = [
(r'<META NAME="DZIAL" CONTENT="gazeta/Sport">', 'Sport')
]
test(self, list_arg, model.extract_department)
pass
def test_extract_author(self):
list_arg = [(
'\n <META NAME = "AUTOR" CONTENT = " Danuta Walewska,Wiesława Mazur">\n',
" Danuta Walewska,Wiesława Mazur"
)]
test(self, list_arg, model.extract_author)
def execute():
unittest.main()
if __name__ == '__main__':
execute()