Commit f3c3436f by Felix Sun

Addressing more PR comments. Fixed a test that broke when new code came in.

parent d6715749
...@@ -1799,7 +1799,7 @@ class FormulaResponse(LoncapaResponse): ...@@ -1799,7 +1799,7 @@ class FormulaResponse(LoncapaResponse):
self.correct_answer, given, self.samples) self.correct_answer, given, self.samples)
return CorrectMap(self.answer_id, correctness) return CorrectMap(self.answer_id, correctness)
def hash_answers(self, answer, var_dict_list): def tupleize_answers(self, answer, var_dict_list):
""" """
Takes in an answer and a list of dictionaries mapping variables to values. Takes in an answer and a list of dictionaries mapping variables to values.
Each dictionary represents a test case for the answer. Each dictionary represents a test case for the answer.
...@@ -1850,7 +1850,7 @@ class FormulaResponse(LoncapaResponse): ...@@ -1850,7 +1850,7 @@ class FormulaResponse(LoncapaResponse):
def randomize_variables(self, samples): def randomize_variables(self, samples):
""" """
Returns a list of dictionaries mapping variables to random values in range, Returns a list of dictionaries mapping variables to random values in range,
as expected by hash_answers. as expected by tupleize_answers.
""" """
variables = samples.split('@')[0].split(',') variables = samples.split('@')[0].split(',')
numsamples = int(samples.split('@')[1].split('#')[1]) numsamples = int(samples.split('@')[1].split('#')[1])
...@@ -1876,13 +1876,15 @@ class FormulaResponse(LoncapaResponse): ...@@ -1876,13 +1876,15 @@ class FormulaResponse(LoncapaResponse):
"correct" or "incorrect". "correct" or "incorrect".
""" """
var_dict_list = self.randomize_variables(samples) var_dict_list = self.randomize_variables(samples)
student_result = self.hash_answers(given, var_dict_list) student_result = self.tupleize_answers(given, var_dict_list)
instructor_result = self.hash_answers(expected, var_dict_list) instructor_result = self.tupleize_answers(expected, var_dict_list)
for i in xrange(len(instructor_result)): correct = all(compare_with_tolerance(student, instructor, self.tolerance)
if not compare_with_tolerance(student_result[i], instructor_result[i], self.tolerance): for student, instructor in zip(student_result, instructor_result))
return "incorrect" if correct:
return "correct" return "correct"
else:
return "incorrect"
def compare_answer(self, a, b): def compare_answer(self, a, b):
""" """
...@@ -1897,7 +1899,7 @@ class FormulaResponse(LoncapaResponse): ...@@ -1897,7 +1899,7 @@ class FormulaResponse(LoncapaResponse):
""" """
var_dict_list = self.randomize_variables(self.samples) var_dict_list = self.randomize_variables(self.samples)
try: try:
self.hash_answers(answer, var_dict_list) self.tupleize_answers(answer, var_dict_list)
return True return True
except StudentInputError: except StudentInputError:
return False return False
......
...@@ -76,7 +76,12 @@ class CrowdsourceHinterModule(CrowdsourceHinterFields, XModule): ...@@ -76,7 +76,12 @@ class CrowdsourceHinterModule(CrowdsourceHinterFields, XModule):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
XModule.__init__(self, *args, **kwargs) XModule.__init__(self, *args, **kwargs)
# We need to know whether we are working with a FormulaResponse problem. # We need to know whether we are working with a FormulaResponse problem.
responder = self.get_display_items()[0].lcp.responders.values()[0] try:
responder = self.get_display_items()[0].lcp.responders.values()[0]
except (IndexError, AttributeError):
log.exception('Unable to find a capa problem child.')
return
self.is_formula = (type(responder) == FormulaResponse) self.is_formula = (type(responder) == FormulaResponse)
if self.is_formula: if self.is_formula:
self.answer_to_str = self.formula_answer_to_str self.answer_to_str = self.formula_answer_to_str
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment