Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
06efd40b
Commit
06efd40b
authored
May 13, 2013
by
Peter Baratta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Comment capitalization
parent
2b9d78df
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
6 deletions
+12
-6
common/lib/capa/capa/tests/test_responsetypes.py
+9
-5
common/lib/capa/capa/util.py
+3
-1
No files found.
common/lib/capa/capa/tests/test_responsetypes.py
View file @
06efd40b
...
...
@@ -452,9 +452,12 @@ class FormulaResponseTest(ResponseTest):
# Expect such a large answer to be marked incorrect
input_formula
=
"x*1e999"
self
.
assert_grade
(
problem
,
input_formula
,
"incorrect"
)
# Expect such a large negative answer to be marked incorrect
input_formula
=
"-x*1e999"
self
.
assert_grade
(
problem
,
input_formula
,
"incorrect"
)
def
test_grade_nan
(
self
):
#
a
ttempt to produce a value which causes the student's answer to be
#
A
ttempt 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
)}
...
...
@@ -465,7 +468,7 @@ class FormulaResponseTest(ResponseTest):
tolerance
=
"1
%
"
,
answer
=
"x"
)
# Expect an incorrect answer (+ nan) to be marked incorrect
#
r
ight now this evaluates to 'nan' for a given x (Python implementation-dependent)
#
R
ight 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
...
...
@@ -756,18 +759,19 @@ class NumericalResponseTest(ResponseTest):
answer
=
4
,
tolerance
=
"10
%
"
)
correct_responses
=
[]
incorrect_responses
=
[
"1e999"
]
incorrect_responses
=
[
"1e999"
,
"-1e999"
]
self
.
assert_multiple_grade
(
problem
,
correct_responses
,
incorrect_responses
)
def
test_grade_nan
(
self
):
#
a
ttempt to produce a value which causes the student's answer to be
#
A
ttempt to produce a value which causes the student's answer to be
# evaluated to nan. See if this is resolved correctly.
problem
=
self
.
build_problem
(
question_text
=
"What is 2 + 2 approximately?"
,
explanation
=
"The answer is 4"
,
answer
=
4
,
tolerance
=
"10
%
"
)
correct_responses
=
[]
# right now these evaluate to 'nan'
# Right now these evaluate to `nan`
# `4 + nan` should be incorrect
incorrect_responses
=
[
"0*1e999"
,
"4 + 0*1e999"
]
self
.
assert_multiple_grade
(
problem
,
correct_responses
,
incorrect_responses
)
...
...
common/lib/capa/capa/util.py
View file @
06efd40b
...
...
@@ -23,7 +23,9 @@ def compare_with_tolerance(v1, v2, tol):
tolerance
=
evaluator
(
dict
(),
dict
(),
tol
)
if
isinf
(
v1
)
or
isinf
(
v2
):
# because the other numerical comparison does not work with infinities
# If an input is infinite, we can end up with `abs(v1-v2)` and
# `tolerance` both equal to infinity. Then, below we would have
# `inf <= inf` which is a fail. Instead, compare directly.
return
v1
==
v2
else
:
return
abs
(
v1
-
v2
)
<=
tolerance
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment