Commit 2b9d78df by Peter Baratta

Pep8 fixes and changes to NaN tests

parent a1db394b
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
# File: courseware/capa/responsetypes.py # 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 Used by capa_problem.py
''' '''
......
...@@ -442,7 +442,7 @@ class FormulaResponseTest(ResponseTest): ...@@ -442,7 +442,7 @@ class FormulaResponseTest(ResponseTest):
# This resolves a bug where a problem with relative tolerance would # This resolves a bug where a problem with relative tolerance would
# pass with any arbitrarily large student answer. # pass with any arbitrarily large student answer.
sample_dict = {'x' : (1,2)} sample_dict = {'x': (1, 2)}
# Test problem # Test problem
problem = self.build_problem(sample_dict=sample_dict, problem = self.build_problem(sample_dict=sample_dict,
...@@ -457,7 +457,7 @@ class FormulaResponseTest(ResponseTest): ...@@ -457,7 +457,7 @@ class FormulaResponseTest(ResponseTest):
# attempt to produce a value which causes the student's answer to be # attempt to produce a value which causes the student's answer to be
# evaluated to nan. See if this is resolved correctly. # evaluated to nan. See if this is resolved correctly.
sample_dict = {'x' : (1,2)} sample_dict = {'x': (1, 2)}
# Test problem # Test problem
problem = self.build_problem(sample_dict=sample_dict, problem = self.build_problem(sample_dict=sample_dict,
...@@ -465,7 +465,11 @@ class FormulaResponseTest(ResponseTest): ...@@ -465,7 +465,11 @@ class FormulaResponseTest(ResponseTest):
tolerance="1%", tolerance="1%",
answer="x") answer="x")
# Expect an incorrect answer (+ nan) to be marked incorrect # 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") self.assert_grade(problem, input_formula, "incorrect")
...@@ -763,7 +767,8 @@ class NumericalResponseTest(ResponseTest): ...@@ -763,7 +767,8 @@ class NumericalResponseTest(ResponseTest):
answer=4, answer=4,
tolerance="10%") tolerance="10%")
correct_responses = [] 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) self.assert_multiple_grade(problem, correct_responses, incorrect_responses)
def test_grade_with_script(self): def test_grade_with_script(self):
......
...@@ -23,10 +23,12 @@ def compare_with_tolerance(v1, v2, tol): ...@@ -23,10 +23,12 @@ def compare_with_tolerance(v1, v2, tol):
tolerance = evaluator(dict(), dict(), tol) tolerance = evaluator(dict(), dict(), tol)
if isinf(v1) or isinf(v2): 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: else:
return abs(v1 - v2) <= tolerance return abs(v1 - v2) <= tolerance
def contextualize_text(text, context): # private def contextualize_text(text, context): # private
''' Takes a string with variables. E.g. $a+$b. ''' Takes a string with variables. E.g. $a+$b.
Does a substitution of those variables from the context ''' Does a substitution of those variables from the context '''
...@@ -55,7 +57,8 @@ def convert_files_to_filenames(answers): ...@@ -55,7 +57,8 @@ def convert_files_to_filenames(answers):
new_answers = dict() new_answers = dict()
for answer_id in answers.keys(): for answer_id in answers.keys():
answer = answers[answer_id] 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] new_answers[answer_id] = [f.name for f in answer]
else: else:
new_answers[answer_id] = answers[answer_id] new_answers[answer_id] = answers[answer_id]
......
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