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
a0201f37
Commit
a0201f37
authored
May 11, 2012
by
Lyla Fischer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
names not required
parent
a4dae577
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
9 deletions
+52
-9
djangoapps/courseware/capa/responsetypes.py
+16
-2
djangoapps/courseware/test_files/multi_bare.xml
+21
-0
djangoapps/courseware/tests.py
+15
-7
No files found.
djangoapps/courseware/capa/responsetypes.py
View file @
a0201f37
...
...
@@ -79,14 +79,28 @@ class MultipleChoiceResponse(GenericResponse):
return
{
self
.
answer_id
:
self
.
correct_choices
}
def
preprocess_response
(
self
):
i
=
0
for
response
in
self
.
xml
.
xpath
(
"choicegroup"
):
response
.
set
(
"type"
,
"MultipleChoice"
)
for
choice
in
list
(
response
):
if
choice
.
get
(
"name"
)
==
None
:
choice
.
set
(
"name"
,
"choice_"
+
str
(
i
))
i
+=
1
else
:
choice
.
set
(
"name"
,
"choice_"
+
choice
.
get
(
"name"
))
class
TrueFalseResponse
(
MultipleChoiceResponse
):
def
preprocess_response
(
self
):
i
=
0
for
response
in
self
.
xml
.
xpath
(
"choicegroup"
):
response
.
set
(
"type"
,
"TrueFalse"
)
for
choice
in
list
(
response
):
if
choice
.
get
(
"name"
)
==
None
:
choice
.
set
(
"name"
,
"choice_"
+
str
(
i
))
i
+=
1
else
:
choice
.
set
(
"name"
,
"choice_"
+
choice
.
get
(
"name"
))
def
grade
(
self
,
student_answers
):
correct
=
set
(
self
.
correct_choices
)
answers
=
set
(
student_answers
.
get
(
self
.
answer_id
,
[]))
...
...
djangoapps/courseware/test_files/multi_bare.xml
0 → 100644
View file @
a0201f37
<problem>
<multiplechoiceresponse>
<choicegroup>
<choice
correct=
"false"
>
<startouttext
/>
This is foil One.
<endouttext
/>
</choice>
<choice
correct=
"false"
>
<startouttext
/>
This is foil Two.
<endouttext
/>
</choice>
<choice
correct=
"true"
>
<startouttext
/>
This is foil Three.
<endouttext
/>
</choice>
<choice
correct=
"false"
>
<startouttext
/>
This is foil Four.
<endouttext
/>
</choice>
<choice
correct=
"false"
>
<startouttext
/>
This is foil Five.
<endouttext
/>
</choice>
</choicegroup>
</multiplechoiceresponse>
</problem>
djangoapps/courseware/tests.py
View file @
a0201f37
...
...
@@ -67,23 +67,31 @@ class MultiChoiceTest(unittest.TestCase):
def
test_MC_grade
(
self
):
multichoice_file
=
os
.
path
.
dirname
(
__file__
)
+
"/test_files/multichoice.xml"
test_lcp
=
lcp
.
LoncapaProblem
(
open
(
multichoice_file
),
'1'
)
correct_answers
=
{
'1_2_1'
:
'foil3'
}
correct_answers
=
{
'1_2_1'
:
'
choice_
foil3'
}
self
.
assertEquals
(
test_lcp
.
grade_answers
(
correct_answers
)[
'1_2_1'
],
'correct'
)
false_answers
=
{
'1_2_1'
:
'foil2'
}
false_answers
=
{
'1_2_1'
:
'choice_foil2'
}
self
.
assertEquals
(
test_lcp
.
grade_answers
(
false_answers
)[
'1_2_1'
],
'incorrect'
)
def
test_MC_bare_grades
(
self
):
multichoice_file
=
os
.
path
.
dirname
(
__file__
)
+
"/test_files/multi_bare.xml"
test_lcp
=
lcp
.
LoncapaProblem
(
open
(
multichoice_file
),
'1'
)
correct_answers
=
{
'1_2_1'
:
'choice_2'
}
self
.
assertEquals
(
test_lcp
.
grade_answers
(
correct_answers
)[
'1_2_1'
],
'correct'
)
false_answers
=
{
'1_2_1'
:
'choice_1'
}
self
.
assertEquals
(
test_lcp
.
grade_answers
(
false_answers
)[
'1_2_1'
],
'incorrect'
)
def
test_TF_grade
(
self
):
truefalse_file
=
os
.
getcwd
()
+
"/djangoapps/courseware/test_files/truefalse.xml"
test_lcp
=
lcp
.
LoncapaProblem
(
open
(
truefalse_file
),
'1'
)
correct_answers
=
{
'1_2_1'
:[
'
foil2'
,
'
foil1'
]}
correct_answers
=
{
'1_2_1'
:[
'
choice_foil2'
,
'choice_
foil1'
]}
self
.
assertEquals
(
test_lcp
.
grade_answers
(
correct_answers
)[
'1_2_1'
],
'correct'
)
false_answers
=
{
'1_2_1'
:[
'foil1'
]}
false_answers
=
{
'1_2_1'
:[
'
choice_
foil1'
]}
self
.
assertEquals
(
test_lcp
.
grade_answers
(
false_answers
)[
'1_2_1'
],
'incorrect'
)
false_answers
=
{
'1_2_1'
:[
'
foil1'
,
'
foil3'
]}
false_answers
=
{
'1_2_1'
:[
'
choice_foil1'
,
'choice_
foil3'
]}
self
.
assertEquals
(
test_lcp
.
grade_answers
(
false_answers
)[
'1_2_1'
],
'incorrect'
)
false_answers
=
{
'1_2_1'
:[
'foil3'
]}
false_answers
=
{
'1_2_1'
:[
'
choice_
foil3'
]}
self
.
assertEquals
(
test_lcp
.
grade_answers
(
false_answers
)[
'1_2_1'
],
'incorrect'
)
false_answers
=
{
'1_2_1'
:[
'
foil1'
,
'foil2'
,
'
foil3'
]}
false_answers
=
{
'1_2_1'
:[
'
choice_foil1'
,
'choice_foil2'
,
'choice_
foil3'
]}
self
.
assertEquals
(
test_lcp
.
grade_answers
(
false_answers
)[
'1_2_1'
],
'incorrect'
)
class
GradesheetTest
(
unittest
.
TestCase
):
...
...
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