Permalink
Browse files

fixed test case generation bug, which happened if the item value == 9…

…9, which would cause the generator to lose a test case
  • Loading branch information...
timothyasp committed May 16, 2012
1 parent d5ef8ce commit 174d30c812d40c50dbed6dc5ed38a103cb6e129f
Showing with 12 additions and 6 deletions.
  1. +12 −6 EvaluateCFRandom.py
View
@@ -19,15 +19,21 @@
- size: number of test cases to generate
"""
+def get_ratings(data, userID):
+ return data[userID]['ratings']
+
+def get_val(data, userID, itemID):
+ return float(get_ratings(data, userID)[itemID])
+
def gen_tests(data, size):
tests = []
for i in xrange(size):
uid = random.randint(0, len(data)-1)
- iid = random.randint(0, len(data[uid]['ratings'])-1)
- if float(data[uid]['ratings'][iid]) != 99:
- tests.append([uid,iid])
- else:
- tests.append([uid,random.randint(0, len(data[uid]['ratings'])-1)])
+ iid = random.randint(0, len(get_ratings(data, uid))-1)
+ while get_val(data, uid, iid) == 99:
+ iid = random.randint(0, len(get_ratings(data, uid))-1)
+
+ tests.append([uid,iid])
return tests
@@ -66,5 +72,5 @@ def print_evaluation(f, method, results):
print_evaluation(f, "Cosine Adjusted Weighted Sum", c_a_w_results)
else:
results = f.execute(method, testData)
- print_evaluation(f, results)
+ print_evaluation(f, method, results)

0 comments on commit 174d30c

Please sign in to comment.