-
Notifications
You must be signed in to change notification settings - Fork 0
/
fruits5-idf-test.py
194 lines (164 loc) · 7.86 KB
/
fruits5-idf-test.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import testingtools
import crawler
import searchdata
import search
output = open('fruits5-idf-failed.txt', 'w')
success_output = open('fruits5-idf-passed.txt', 'w')
#Performing crawl starting at seed http://people.scs.carleton.ca/~davidmckenney/fruits5/N-0.html
crawler.crawl('http://people.scs.carleton.ca/~davidmckenney/fruits5/N-0.html')
#Test #0 checking IDF for word fig
expected = 0.16650266314016507
result = searchdata.get_idf('fig')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #0 checking IDF for word fig\n\n')
output.write('expected = {}\n'.format(str(expected)))
output.write('result = {}\n\n\n'.format(str(result)))
else:
success_output.write('Passed Test #0 checking IDF for word fig\n\n')
success_output.write('expected = {}\n'.format(str(expected)))
success_output.write('result = {}\n\n\n'.format(str(result)))
#Test #1 checking IDF for word apple
expected = 0.15521264992094008
result = searchdata.get_idf('apple')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #1 checking IDF for word apple\n\n')
output.write('expected = {}\n'.format(str(expected)))
output.write('result = {}\n\n\n'.format(str(result)))
else:
success_output.write('Passed Test #1 checking IDF for word apple\n\n')
success_output.write('expected = {}\n'.format(str(expected)))
success_output.write('result = {}\n\n\n'.format(str(result)))
#Test #2 checking IDF for word cherry
expected = 0.15682010974282581
result = searchdata.get_idf('cherry')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #2 checking IDF for word cherry\n\n')
output.write('expected = {}\n'.format(str(expected)))
output.write('result = {}\n\n\n'.format(str(result)))
else:
success_output.write('Passed Test #2 checking IDF for word cherry\n\n')
success_output.write('expected = {}\n'.format(str(expected)))
success_output.write('result = {}\n\n\n'.format(str(result)))
#Test #3 checking IDF for word banana
expected = 0.16326791954086414
result = searchdata.get_idf('banana')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #3 checking IDF for word banana\n\n')
output.write('expected = {}\n'.format(str(expected)))
output.write('result = {}\n\n\n'.format(str(result)))
else:
success_output.write('Passed Test #3 checking IDF for word banana\n\n')
success_output.write('expected = {}\n'.format(str(expected)))
success_output.write('result = {}\n\n\n'.format(str(result)))
#Test #4 checking IDF for word orange
expected = 0.16650266314016507
result = searchdata.get_idf('orange')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #4 checking IDF for word orange\n\n')
output.write('expected = {}\n'.format(str(expected)))
output.write('result = {}\n\n\n'.format(str(result)))
else:
success_output.write('Passed Test #4 checking IDF for word orange\n\n')
success_output.write('expected = {}\n'.format(str(expected)))
success_output.write('result = {}\n\n\n'.format(str(result)))
#Test #5 checking IDF for word blueberry
expected = 0.1729939903610231
result = searchdata.get_idf('blueberry')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #5 checking IDF for word blueberry\n\n')
output.write('expected = {}\n'.format(str(expected)))
output.write('result = {}\n\n\n'.format(str(result)))
else:
success_output.write('Passed Test #5 checking IDF for word blueberry\n\n')
success_output.write('expected = {}\n'.format(str(expected)))
success_output.write('result = {}\n\n\n'.format(str(result)))
#Test #6 checking IDF for word apricot
expected = 0.1729939903610231
result = searchdata.get_idf('apricot')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #6 checking IDF for word apricot\n\n')
output.write('expected = {}\n'.format(str(expected)))
output.write('result = {}\n\n\n'.format(str(result)))
else:
success_output.write('Passed Test #6 checking IDF for word apricot\n\n')
success_output.write('expected = {}\n'.format(str(expected)))
success_output.write('result = {}\n\n\n'.format(str(result)))
#Test #7 checking IDF for word lime
expected = 0.16326791954086414
result = searchdata.get_idf('lime')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #7 checking IDF for word lime\n\n')
output.write('expected = {}\n'.format(str(expected)))
output.write('result = {}\n\n\n'.format(str(result)))
else:
success_output.write('Passed Test #7 checking IDF for word lime\n\n')
success_output.write('expected = {}\n'.format(str(expected)))
success_output.write('result = {}\n\n\n'.format(str(result)))
#Test #8 checking IDF for word kiwi
expected = 0.1729939903610231
result = searchdata.get_idf('kiwi')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #8 checking IDF for word kiwi\n\n')
output.write('expected = {}\n'.format(str(expected)))
output.write('result = {}\n\n\n'.format(str(result)))
else:
success_output.write('Passed Test #8 checking IDF for word kiwi\n\n')
success_output.write('expected = {}\n'.format(str(expected)))
success_output.write('result = {}\n\n\n'.format(str(result)))
#Test #9 checking IDF for word pear
expected = 0.16812275880832706
result = searchdata.get_idf('pear')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #9 checking IDF for word pear\n\n')
output.write('expected = {}\n'.format(str(expected)))
output.write('result = {}\n\n\n'.format(str(result)))
else:
success_output.write('Passed Test #9 checking IDF for word pear\n\n')
success_output.write('expected = {}\n'.format(str(expected)))
success_output.write('result = {}\n\n\n'.format(str(result)))
#Test #10 checking IDF for word peach
expected = 0.1600404125104682
result = searchdata.get_idf('peach')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #10 checking IDF for word peach\n\n')
output.write('expected = {}\n'.format(str(expected)))
output.write('result = {}\n\n\n'.format(str(result)))
else:
success_output.write('Passed Test #10 checking IDF for word peach\n\n')
success_output.write('expected = {}\n'.format(str(expected)))
success_output.write('result = {}\n\n\n'.format(str(result)))
#Test #11 checking IDF for word coconut
expected = 0.1600404125104682
result = searchdata.get_idf('coconut')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #11 checking IDF for word coconut\n\n')
output.write('expected = {}\n'.format(str(expected)))
output.write('result = {}\n\n\n'.format(str(result)))
else:
success_output.write('Passed Test #11 checking IDF for word coconut\n\n')
success_output.write('expected = {}\n'.format(str(expected)))
success_output.write('result = {}\n\n\n'.format(str(result)))
#Test #12 checking IDF for word papaya
expected = 0.16650266314016507
result = searchdata.get_idf('papaya')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #12 checking IDF for word papaya\n\n')
output.write('expected = {}\n'.format(str(expected)))
output.write('result = {}\n\n\n'.format(str(result)))
else:
success_output.write('Passed Test #12 checking IDF for word papaya\n\n')
success_output.write('expected = {}\n'.format(str(expected)))
success_output.write('result = {}\n\n\n'.format(str(result)))
#Test #13 checking IDF for word tomato
expected = 0
result = searchdata.get_idf('tomato')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #13 checking IDF for word tomato\n\n')
output.write('expected = {}\n'.format(str(expected)))
output.write('result = {}\n\n\n'.format(str(result)))
else:
success_output.write('Passed Test #13 checking IDF for word tomato\n\n')
success_output.write('expected = {}\n'.format(str(expected)))
success_output.write('result = {}\n\n\n'.format(str(result)))
output.close()
success_output.close()