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
eb5a90a3
Commit
eb5a90a3
authored
Jul 19, 2013
by
Felix Sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for validate_answer in response types.
parent
544aa55e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
1 deletions
+29
-1
common/lib/capa/capa/responsetypes.py
+1
-1
common/lib/capa/capa/tests/test_responsetypes.py
+28
-0
No files found.
common/lib/capa/capa/responsetypes.py
View file @
eb5a90a3
...
...
@@ -935,7 +935,7 @@ class NumericalResponse(LoncapaResponse):
try
:
evaluator
(
dict
(),
dict
(),
answer
)
return
True
except
StudentInputError
:
except
(
StudentInputError
,
UndefinedVariable
)
:
return
False
def
get_answers
(
self
):
...
...
common/lib/capa/capa/tests/test_responsetypes.py
View file @
eb5a90a3
...
...
@@ -496,6 +496,20 @@ class FormulaResponseTest(ResponseTest):
input_dict
=
{
'1_2_1'
:
'1/0'
}
self
.
assertRaises
(
StudentInputError
,
problem
.
grade_answers
,
input_dict
)
def
test_validate_answer
(
self
):
"""
Makes sure that validate_answer works.
"""
sample_dict
=
{
'x'
:
(
1
,
2
)}
problem
=
self
.
build_problem
(
sample_dict
=
sample_dict
,
num_samples
=
10
,
tolerance
=
"1
%
"
,
answer
=
"x"
)
self
.
assertTrue
(
problem
.
responders
.
values
()[
0
]
.
validate_answer
(
'14*x'
))
self
.
assertFalse
(
problem
.
responders
.
values
()[
0
]
.
validate_answer
(
'3*y+2*x'
))
class
StringResponseTest
(
ResponseTest
):
from
capa.tests.response_xml_factory
import
StringResponseXMLFactory
...
...
@@ -915,6 +929,20 @@ class NumericalResponseTest(ResponseTest):
with
self
.
assertRaisesRegexp
(
StudentInputError
,
msg_regex
):
problem
.
grade_answers
({
'1_2_1'
:
'foobar'
})
def
test_answer_compare
(
self
):
"""Tests the answer compare function."""
problem
=
self
.
build_problem
(
answer
=
"42"
)
responder
=
problem
.
responders
.
values
()[
0
]
self
.
assertTrue
(
responder
.
answer_compare
(
'48'
,
'8*6'
))
self
.
assertFalse
(
responder
.
answer_compare
(
'48'
,
'9*5'
))
def
test_validate_answer
(
self
):
"""Tests the answer validation function."""
problem
=
self
.
build_problem
(
answer
=
"42"
)
responder
=
problem
.
responders
.
values
()[
0
]
self
.
assertTrue
(
responder
.
validate_answer
(
'23.5'
))
self
.
assertFalse
(
responder
.
validate_answer
(
'fish'
))
class
CustomResponseTest
(
ResponseTest
):
from
capa.tests.response_xml_factory
import
CustomResponseXMLFactory
...
...
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