-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
79 lines (65 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
70
71
72
73
74
75
76
77
78
79
import unittest
from wikigraph import WikiGraph
from wikiapi import WikiAPI
top10pages = '''\
United States
Donald Trump
Barack Obama
India
World War II
Michael Jackson
Sex
United Kingdom
Lady Gaga
Eminem'''.split('\n')
samplepages = '''\
Turkey at the 1964 Summer Olympics
Olympics
Eurema sarilata
Variegated mountain lizard
Boerhaave
Tetrastrum
WordDive
Ashaga Fyndygan
derivatives
The Eagle (1925 film)
Bee
'''.split('\n')
class TestWikiGraph(unittest.TestCase):
def test_find_path(self):
'''Basic test to see if '''
wiki_graph = WikiGraph()
start, end = ('Tom Hanks', 'Will I Am')
path = wiki_graph.find_path(start, end)
self.assertEqual(path.start, start)
self.assertEqual(path.end, end)
self.assertTrue(path, "Path not found")
self.assertTrue(len(path) < 6, "Path too long len=%d" % len(path))
def test_find_path_benchmark(self):
wiki_graph = WikiGraph(print_requests=True)
total_requests = 0
total_time = 0
failures = []
# Loop through and test if paths exit
for page in samplepages:
(start, end) = (page, "Homunculus")
path = wiki_graph.find_path(start, end)
if path.degree == -1:
failures.append(path)
total_requests += path.requests
total_time += path.time
print("Total Failures:", len(failures))
print(failures)
print("Total requests:", total_requests)
print("Avg number of requests per path: %.2f" % (total_requests / len(top10pages)))
print("Total time: ", total_time)
print("Avg time per path: %.2f" % (total_time / len(top10pages)))
class TestWikiAPI(unittest.TestCase):
def test_get_links(self):
api = WikiAPI()
links = api.links('Bee', inbound=False)
self.assertGreater(len(links), 100)
linkshere = api.links('Bee', inbound=True)
self.assertGreater(len(linkshere), 100)
if __name__ == '__main__':
unittest.main()