Pep8 fixes and changes to NaN tests
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
# File: courseware/capa/responsetypes.py
|
||||
#
|
||||
'''
|
||||
Problem response evaluation. Handles checking of student responses, of a variety of types.
|
||||
Problem response evaluation. Handles checking of student responses,
|
||||
of a variety of types.
|
||||
|
||||
Used by capa_problem.py
|
||||
'''
|
||||
|
||||
@@ -442,7 +442,7 @@ class FormulaResponseTest(ResponseTest):
|
||||
# This resolves a bug where a problem with relative tolerance would
|
||||
# pass with any arbitrarily large student answer.
|
||||
|
||||
sample_dict = {'x' : (1,2)}
|
||||
sample_dict = {'x': (1, 2)}
|
||||
|
||||
# Test problem
|
||||
problem = self.build_problem(sample_dict=sample_dict,
|
||||
@@ -457,7 +457,7 @@ class FormulaResponseTest(ResponseTest):
|
||||
# attempt to produce a value which causes the student's answer to be
|
||||
# evaluated to nan. See if this is resolved correctly.
|
||||
|
||||
sample_dict = {'x' : (1,2)}
|
||||
sample_dict = {'x': (1, 2)}
|
||||
|
||||
# Test problem
|
||||
problem = self.build_problem(sample_dict=sample_dict,
|
||||
@@ -465,7 +465,11 @@ class FormulaResponseTest(ResponseTest):
|
||||
tolerance="1%",
|
||||
answer="x")
|
||||
# Expect an incorrect answer (+ nan) to be marked incorrect
|
||||
input_formula = "10*x + 0*1e999" # right now this evaluates to 'nan' for a given x
|
||||
# right now this evaluates to 'nan' for a given x (Python implementation-dependent)
|
||||
input_formula = "10*x + 0*1e999"
|
||||
self.assert_grade(problem, input_formula, "incorrect")
|
||||
# Expect an correct answer (+ nan) to be marked incorrect
|
||||
input_formula = "x + 0*1e999"
|
||||
self.assert_grade(problem, input_formula, "incorrect")
|
||||
|
||||
|
||||
@@ -763,7 +767,8 @@ class NumericalResponseTest(ResponseTest):
|
||||
answer=4,
|
||||
tolerance="10%")
|
||||
correct_responses = []
|
||||
incorrect_responses = ["0*1e999"] # right now this evaluates to 'nan' for a given x
|
||||
# right now these evaluate to 'nan'
|
||||
incorrect_responses = ["0*1e999", "4 + 0*1e999"]
|
||||
self.assert_multiple_grade(problem, correct_responses, incorrect_responses)
|
||||
|
||||
def test_grade_with_script(self):
|
||||
|
||||
@@ -23,10 +23,12 @@ def compare_with_tolerance(v1, v2, tol):
|
||||
tolerance = evaluator(dict(), dict(), tol)
|
||||
|
||||
if isinf(v1) or isinf(v2):
|
||||
return v1 == v2 # because the other numerical comparison does not work with infinities
|
||||
# because the other numerical comparison does not work with infinities
|
||||
return v1 == v2
|
||||
else:
|
||||
return abs(v1 - v2) <= tolerance
|
||||
|
||||
|
||||
def contextualize_text(text, context): # private
|
||||
''' Takes a string with variables. E.g. $a+$b.
|
||||
Does a substitution of those variables from the context '''
|
||||
@@ -55,7 +57,8 @@ def convert_files_to_filenames(answers):
|
||||
new_answers = dict()
|
||||
for answer_id in answers.keys():
|
||||
answer = answers[answer_id]
|
||||
if is_list_of_files(answer): # Files are stored as a list, even if one file
|
||||
# Files are stored as a list, even if one file
|
||||
if is_list_of_files(answer):
|
||||
new_answers[answer_id] = [f.name for f in answer]
|
||||
else:
|
||||
new_answers[answer_id] = answers[answer_id]
|
||||
|
||||
Reference in New Issue
Block a user