-
Notifications
You must be signed in to change notification settings - Fork 0
/
fruits2-idf-test.py
90 lines (76 loc) · 3.57 KB
/
fruits2-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
import testingtools
import crawler
import searchdata
import search
output = open('fruits2-idf-failed.txt', 'w')
success_output = open('fruits2-idf-passed.txt', 'w')
#Performing crawl starting at seed http://people.scs.carleton.ca/~davidmckenney/fruits2/N-0.html
crawler.crawl('http://people.scs.carleton.ca/~davidmckenney/fruits2/N-0.html')
#Test #0 checking IDF for word pear
expected = 0.052894948432125555
result = searchdata.get_idf('pear')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #0 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 #0 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 #1 checking IDF for word apple
expected = 0.05439229681862769
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 banana
expected = 0.052894948432125555
result = searchdata.get_idf('banana')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #2 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 #2 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 #3 checking IDF for word coconut
expected = 0.05739166388833648
result = searchdata.get_idf('coconut')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #3 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 #3 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 #4 checking IDF for word peach
expected = 0.05139915250664415
result = searchdata.get_idf('peach')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #4 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 #4 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 #5 checking IDF for word tomato
expected = 0
result = searchdata.get_idf('tomato')
if not testingtools.compare_doubles(expected, result):
output.write('Failed Test #5 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 #5 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()