Test for infinity in numerical and formula responses
This commit is contained in:
@@ -1869,8 +1869,6 @@ class FormulaResponse(LoncapaResponse):
|
||||
log.debug('formularesponse: error %s in formula' % err)
|
||||
raise StudentInputError("Invalid input: Could not parse '%s' as a formula" %
|
||||
cgi.escape(given))
|
||||
if numpy.isnan(student_result) or numpy.isinf(student_result):
|
||||
return "incorrect"
|
||||
if not compare_with_tolerance(student_result, instructor_result, self.tolerance):
|
||||
return "incorrect"
|
||||
return "correct"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from .calc import evaluator, UndefinedVariable
|
||||
from cmath import isinf
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
#
|
||||
@@ -20,8 +21,11 @@ def compare_with_tolerance(v1, v2, tol):
|
||||
tolerance = tolerance_rel * max(abs(v1), abs(v2))
|
||||
else:
|
||||
tolerance = evaluator(dict(), dict(), tol)
|
||||
return abs(v1 - v2) <= tolerance
|
||||
|
||||
if isinf(v1) or isinf(v2):
|
||||
return v1 == v2 # because the other numerical comparison does not work with infinities
|
||||
else:
|
||||
return abs(v1 - v2) <= tolerance
|
||||
|
||||
def contextualize_text(text, context): # private
|
||||
''' Takes a string with variables. E.g. $a+$b.
|
||||
|
||||
Reference in New Issue
Block a user