-
Notifications
You must be signed in to change notification settings - Fork 0
/
testingtools.py
81 lines (58 loc) · 1.72 KB
/
testingtools.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
def compare_doubles(a, b):
return abs(a-b) < 0.0001
def compare_unsorted_lists(a,b):
if a == None or b == None:
return a == b
if len(a) != len(b):
return False
for i in a:
if a.count(i) != b.count(i):
return False
return True
def compare_sorted_lists(a,b):
if a == None or b == None:
return a == b
if len(a) != len(b):
return False
for i in range(len(a)):
if a[i] != a[b]:
return False
return True
def bin_results(a):
result = []
cur_bin = [a[0]]
for i in range(1, len(a)):
entry = a[i]
if abs(entry["score"] - a[i-1]["score"]) < 0.00001:
cur_bin.append(entry)
else:
result.append(cur_bin)
cur_bin = [entry]
result.append(cur_bin)
return result
def find_match_index(entry, a):
for i in range(len(a)):
e = a[i]
if e["title"] == entry["title"] and e["url"] == entry["url"]:
return i
return -1
def compare_binned_results(a,b):
if len(a) != len (b):
return False
for i in range(len(a)):
if len(a[i]) != len(b[i]):
return False
while len(a[i]) > 0:
entry = a[i].pop()
match_index = find_match_index(entry, b[i])
if match_index >= 0:
b[i].pop(match_index)
else:
return False
return True
def compare_search_results(a, b):
if len(a) == 0 and len(b) == 0:
return True
a = bin_results(a)
b = bin_results(b)
return compare_binned_results(a,b)