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
ab3eb99b
Commit
ab3eb99b
authored
Feb 25, 2013
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1552 from MITx/jth/fix_draganddrop
Jth/fix draganddrop
parents
9fb1c0b2
ac7fe063
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
8 deletions
+22
-8
common/lib/capa/capa/verifiers/draganddrop.py
+10
-8
common/lib/capa/capa/verifiers/tests_draganddrop.py
+12
-0
No files found.
common/lib/capa/capa/verifiers/draganddrop.py
View file @
ab3eb99b
...
...
@@ -111,7 +111,7 @@ class DragAndDrop(object):
Returns: bool.
'''
for
draggable
in
self
.
excess_draggables
:
if
not
self
.
excess_draggables
[
draggable
]:
if
self
.
excess_draggables
[
draggable
]:
return
False
# user answer has more draggables than correct answer
# Number of draggables in user_groups may be differ that in
...
...
@@ -304,8 +304,13 @@ class DragAndDrop(object):
user_answer
=
json
.
loads
(
user_answer
)
# check if we have draggables that are not in correct answer:
self
.
excess_draggables
=
{}
# This dictionary will hold a key for each draggable the user placed on
# the image. The value is True if that draggable is not mentioned in any
# correct_answer entries. If the draggable is mentioned in at least one
# correct_answer entry, the value is False.
# default to consider every user answer excess until proven otherwise.
self
.
excess_draggables
=
dict
((
users_draggable
.
keys
()[
0
],
True
)
for
users_draggable
in
user_answer
[
'draggables'
])
# create identical data structures from user answer and correct answer
for
i
in
xrange
(
0
,
len
(
correct_answer
)):
...
...
@@ -322,11 +327,8 @@ class DragAndDrop(object):
self
.
user_groups
[
groupname
]
.
append
(
draggable_name
)
self
.
user_positions
[
groupname
][
'user'
]
.
append
(
draggable_dict
[
draggable_name
])
self
.
excess_draggables
[
draggable_name
]
=
True
else
:
self
.
excess_draggables
[
draggable_name
]
=
\
self
.
excess_draggables
.
get
(
draggable_name
,
False
)
# proved that this is not excess
self
.
excess_draggables
[
draggable_name
]
=
False
def
grade
(
user_input
,
correct_answer
):
""" Creates DragAndDrop instance from user_input and correct_answer and
...
...
common/lib/capa/capa/verifiers/tests_draganddrop.py
View file @
ab3eb99b
...
...
@@ -46,6 +46,18 @@ class Test_DragAndDrop_Grade(unittest.TestCase):
correct_answer
=
{
'1'
:
't1'
,
'name_with_icon'
:
't2'
}
self
.
assertTrue
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
def
test_expect_no_actions_wrong
(
self
):
user_input
=
'{"draggables": [{"1": "t1"},
\
{"name_with_icon": "t2"}]}'
correct_answer
=
[]
self
.
assertFalse
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
def
test_expect_no_actions_right
(
self
):
user_input
=
'{"draggables": []}'
correct_answer
=
[]
self
.
assertTrue
(
draganddrop
.
grade
(
user_input
,
correct_answer
))
def
test_targets_false
(
self
):
user_input
=
'{"draggables": [{"1": "t1"},
\
{"name_with_icon": "t2"}]}'
...
...
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