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
00f966a9
Commit
00f966a9
authored
Jan 21, 2013
by
Alexander Kryklia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
populate -> __init__
parent
a95e8098
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
23 deletions
+19
-23
common/lib/capa/capa/verifiers/draganddrop.py
+10
-13
common/lib/capa/capa/verifiers/tests_draganddrop.py
+9
-10
No files found.
common/lib/capa/capa/verifiers/draganddrop.py
View file @
00f966a9
...
@@ -101,11 +101,6 @@ class PositionsCompare(list):
...
@@ -101,11 +101,6 @@ class PositionsCompare(list):
class
DragAndDrop
(
object
):
class
DragAndDrop
(
object
):
""" Grader class for drag and drop inputtype.
""" Grader class for drag and drop inputtype.
"""
"""
def
__init__
(
self
):
self
.
correct_groups
=
dict
()
# correct groups from xml
self
.
correct_positions
=
dict
()
# correct positions for comparing
self
.
user_groups
=
dict
()
# will be populated from user answer
self
.
user_positions
=
dict
()
# will be populated from user answer
def
grade
(
self
):
def
grade
(
self
):
''' Grader user answer.
''' Grader user answer.
...
@@ -243,7 +238,7 @@ class DragAndDrop(object):
...
@@ -243,7 +238,7 @@ class DragAndDrop(object):
return
True
return
True
def
populate
(
self
,
correct_answer
,
user_answer
):
def
__init__
(
self
,
correct_answer
,
user_answer
):
""" Populates DragAndDrop variables from user_answer and correct_answer.
""" Populates DragAndDrop variables from user_answer and correct_answer.
If correct_answer is dict, converts it to list.
If correct_answer is dict, converts it to list.
Correct answer in dict form is simpe structure for fast and simple
Correct answer in dict form is simpe structure for fast and simple
...
@@ -289,10 +284,13 @@ class DragAndDrop(object):
...
@@ -289,10 +284,13 @@ class DragAndDrop(object):
Args:
Args:
user_answer: json
user_answer: json
correct_answer: dict or list
correct_answer: dict or list
"""
Returns: None
self
.
correct_groups
=
dict
()
# correct groups from xml
self
.
correct_positions
=
dict
()
# correct positions for comparing
self
.
user_groups
=
dict
()
# will be populated from user answer
self
.
user_positions
=
dict
()
# will be populated from user answer
"""
# convert from dict answer format to list format
# convert from dict answer format to list format
if
isinstance
(
correct_answer
,
dict
):
if
isinstance
(
correct_answer
,
dict
):
tmp
=
[]
tmp
=
[]
...
@@ -330,8 +328,8 @@ class DragAndDrop(object):
...
@@ -330,8 +328,8 @@ class DragAndDrop(object):
def
grade
(
user_input
,
correct_answer
):
def
grade
(
user_input
,
correct_answer
):
"""
Popul
ates DragAndDrop instance from user_input and correct_answer and
"""
Cre
ates DragAndDrop instance from user_input and correct_answer and
calls DragAndDrop.
d
rade for grading.
calls DragAndDrop.
g
rade for grading.
Supports two interfaces for correct_answer: dict and list.
Supports two interfaces for correct_answer: dict and list.
...
@@ -373,6 +371,5 @@ def grade(user_input, correct_answer):
...
@@ -373,6 +371,5 @@ def grade(user_input, correct_answer):
Returns: bool
Returns: bool
"""
"""
dnd
=
DragAndDrop
()
return
DragAndDrop
(
correct_answer
=
correct_answer
,
dnd
.
populate
(
correct_answer
=
correct_answer
,
user_answer
=
user_input
)
user_answer
=
user_input
)
.
grade
()
return
dnd
.
grade
()
common/lib/capa/capa/verifiers/tests_draganddrop.py
View file @
00f966a9
...
@@ -520,11 +520,10 @@ class Test_DragAndDrop_Grade(unittest.TestCase):
...
@@ -520,11 +520,10 @@ class Test_DragAndDrop_Grade(unittest.TestCase):
class
Test_DragAndDrop_Populate
(
unittest
.
TestCase
):
class
Test_DragAndDrop_Populate
(
unittest
.
TestCase
):
def
test_1
(
self
):
def
test_1
(
self
):
dnd
=
draganddrop
.
DragAndDrop
()
correct_answer
=
{
'1'
:
[[
40
,
10
],
29
],
'name_with_icon'
:
[
20
,
20
]}
correct_answer
=
{
'1'
:
[[
40
,
10
],
29
],
'name_with_icon'
:
[
20
,
20
]}
user_input
=
'{"draggables":
\
user_input
=
'{"draggables":
\
[{"1": [10, 10]}, {"name_with_icon": [20, 20]}]}'
[{"1": [10, 10]}, {"name_with_icon": [20, 20]}]}'
dnd
.
populate
(
correct_answer
,
user_input
)
dnd
=
draganddrop
.
DragAndDrop
(
correct_answer
,
user_input
)
correct_groups
=
{
'1'
:
[
'name_with_icon'
],
'0'
:
[
'1'
]}
correct_groups
=
{
'1'
:
[
'name_with_icon'
],
'0'
:
[
'1'
]}
correct_positions
=
{
'1'
:
{
'exact'
:
[[
20
,
20
]]},
'0'
:
{
'exact'
:
[[[
40
,
10
],
29
]]}}
correct_positions
=
{
'1'
:
{
'exact'
:
[[
20
,
20
]]},
'0'
:
{
'exact'
:
[[[
40
,
10
],
29
]]}}
...
@@ -540,49 +539,49 @@ class Test_DragAndDrop_Populate(unittest.TestCase):
...
@@ -540,49 +539,49 @@ class Test_DragAndDrop_Populate(unittest.TestCase):
class
Test_DraAndDrop_Compare_Positions
(
unittest
.
TestCase
):
class
Test_DraAndDrop_Compare_Positions
(
unittest
.
TestCase
):
def
test_1
(
self
):
def
test_1
(
self
):
dnd
=
draganddrop
.
DragAndDrop
()
dnd
=
draganddrop
.
DragAndDrop
(
{
'1'
:
't1'
},
'{"draggables": [{"1": "t1"}]}'
)
self
.
assertTrue
(
dnd
.
compare_positions
(
correct
=
[[
1
,
1
],
[
2
,
3
]],
self
.
assertTrue
(
dnd
.
compare_positions
(
correct
=
[[
1
,
1
],
[
2
,
3
]],
user
=
[[
2
,
3
],
[
1
,
1
]],
user
=
[[
2
,
3
],
[
1
,
1
]],
flag
=
'anyof'
))
flag
=
'anyof'
))
def
test_2a
(
self
):
def
test_2a
(
self
):
dnd
=
draganddrop
.
DragAndDrop
()
dnd
=
draganddrop
.
DragAndDrop
(
{
'1'
:
't1'
},
'{"draggables": [{"1": "t1"}]}'
)
self
.
assertTrue
(
dnd
.
compare_positions
(
correct
=
[[
1
,
1
],
[
2
,
3
]],
self
.
assertTrue
(
dnd
.
compare_positions
(
correct
=
[[
1
,
1
],
[
2
,
3
]],
user
=
[[
2
,
3
],
[
1
,
1
]],
user
=
[[
2
,
3
],
[
1
,
1
]],
flag
=
'exact'
))
flag
=
'exact'
))
def
test_2b
(
self
):
def
test_2b
(
self
):
dnd
=
draganddrop
.
DragAndDrop
()
dnd
=
draganddrop
.
DragAndDrop
(
{
'1'
:
't1'
},
'{"draggables": [{"1": "t1"}]}'
)
self
.
assertFalse
(
dnd
.
compare_positions
(
correct
=
[[
1
,
1
],
[
2
,
3
]],
self
.
assertFalse
(
dnd
.
compare_positions
(
correct
=
[[
1
,
1
],
[
2
,
3
]],
user
=
[[
2
,
13
],
[
1
,
1
]],
user
=
[[
2
,
13
],
[
1
,
1
]],
flag
=
'exact'
))
flag
=
'exact'
))
def
test_3
(
self
):
def
test_3
(
self
):
dnd
=
draganddrop
.
DragAndDrop
()
dnd
=
draganddrop
.
DragAndDrop
(
{
'1'
:
't1'
},
'{"draggables": [{"1": "t1"}]}'
)
self
.
assertFalse
(
dnd
.
compare_positions
(
correct
=
[
"a"
,
"b"
],
self
.
assertFalse
(
dnd
.
compare_positions
(
correct
=
[
"a"
,
"b"
],
user
=
[
"a"
,
"b"
,
"c"
],
user
=
[
"a"
,
"b"
,
"c"
],
flag
=
'anyof'
))
flag
=
'anyof'
))
def
test_4
(
self
):
def
test_4
(
self
):
dnd
=
draganddrop
.
DragAndDrop
()
dnd
=
draganddrop
.
DragAndDrop
(
{
'1'
:
't1'
},
'{"draggables": [{"1": "t1"}]}'
)
self
.
assertTrue
(
dnd
.
compare_positions
(
correct
=
[
"a"
,
"b"
,
"c"
],
self
.
assertTrue
(
dnd
.
compare_positions
(
correct
=
[
"a"
,
"b"
,
"c"
],
user
=
[
"a"
,
"b"
],
user
=
[
"a"
,
"b"
],
flag
=
'anyof'
))
flag
=
'anyof'
))
def
test_5
(
self
):
def
test_5
(
self
):
dnd
=
draganddrop
.
DragAndDrop
()
dnd
=
draganddrop
.
DragAndDrop
(
{
'1'
:
't1'
},
'{"draggables": [{"1": "t1"}]}'
)
self
.
assertFalse
(
dnd
.
compare_positions
(
correct
=
[
"a"
,
"b"
,
"c"
],
self
.
assertFalse
(
dnd
.
compare_positions
(
correct
=
[
"a"
,
"b"
,
"c"
],
user
=
[
"a"
,
"c"
,
"b"
],
user
=
[
"a"
,
"c"
,
"b"
],
flag
=
'exact'
))
flag
=
'exact'
))
def
test_6
(
self
):
def
test_6
(
self
):
dnd
=
draganddrop
.
DragAndDrop
()
dnd
=
draganddrop
.
DragAndDrop
(
{
'1'
:
't1'
},
'{"draggables": [{"1": "t1"}]}'
)
self
.
assertTrue
(
dnd
.
compare_positions
(
correct
=
[
"a"
,
"b"
,
"c"
],
self
.
assertTrue
(
dnd
.
compare_positions
(
correct
=
[
"a"
,
"b"
,
"c"
],
user
=
[
"a"
,
"c"
,
"b"
],
user
=
[
"a"
,
"c"
,
"b"
],
flag
=
'anyof'
))
flag
=
'anyof'
))
def
test_7
(
self
):
def
test_7
(
self
):
dnd
=
draganddrop
.
DragAndDrop
()
dnd
=
draganddrop
.
DragAndDrop
(
{
'1'
:
't1'
},
'{"draggables": [{"1": "t1"}]}'
)
self
.
assertFalse
(
dnd
.
compare_positions
(
correct
=
[
"a"
,
"b"
,
"b"
],
self
.
assertFalse
(
dnd
.
compare_positions
(
correct
=
[
"a"
,
"b"
,
"b"
],
user
=
[
"a"
,
"c"
,
"b"
],
user
=
[
"a"
,
"c"
,
"b"
],
flag
=
'anyof'
))
flag
=
'anyof'
))
...
...
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