Commit 38830f00 by Don Mitchell

Merge pull request #1564 from MITx/bug/christina/misc

Bug/christina/misc
parents f33c5754 e47d11be
...@@ -119,13 +119,13 @@ describe 'MarkdownEditingDescriptor', -> ...@@ -119,13 +119,13 @@ describe 'MarkdownEditingDescriptor', ->
<p>The answer is correct if it is within a specified numerical tolerance of the expected answer.</p> <p>The answer is correct if it is within a specified numerical tolerance of the expected answer.</p>
<p>Enter the numerical value of Pi:</p> <p>Enter the numerical value of Pi:</p>
<numericalresponse answer="3.14159 "> <numericalresponse answer="3.14159">
<responseparam type="tolerance" default=".02" /> <responseparam type="tolerance" default=".02" />
<textline /> <textline />
</numericalresponse> </numericalresponse>
<p>Enter the approximate value of 502*9:</p> <p>Enter the approximate value of 502*9:</p>
<numericalresponse answer="4518 "> <numericalresponse answer="4518">
<responseparam type="tolerance" default="15%" /> <responseparam type="tolerance" default="15%" />
<textline /> <textline />
</numericalresponse> </numericalresponse>
...@@ -148,6 +148,20 @@ describe 'MarkdownEditingDescriptor', -> ...@@ -148,6 +148,20 @@ describe 'MarkdownEditingDescriptor', ->
</div> </div>
</solution> </solution>
</problem>""") </problem>""")
it 'will convert 0 as a numerical response (instead of string response)', ->
data = MarkdownEditingDescriptor.markdownToXml("""
Enter 0 with a tolerance:
= 0 +- .02
""")
expect(data).toEqual("""<problem>
<p>Enter 0 with a tolerance:</p>
<numericalresponse answer="0">
<responseparam type="tolerance" default=".02" />
<textline />
</numericalresponse>
</problem>""")
it 'converts multiple choice to xml', -> it 'converts multiple choice to xml', ->
data = MarkdownEditingDescriptor.markdownToXml("""A multiple choice problem presents radio buttons for student input. Students can only select a single option presented. Multiple Choice questions have been the subject of many areas of research due to the early invention and adoption of bubble sheets. data = MarkdownEditingDescriptor.markdownToXml("""A multiple choice problem presents radio buttons for student input. Students can only select a single option presented. Multiple Choice questions have been the subject of many areas of research due to the early invention and adoption of bubble sheets.
......
...@@ -231,13 +231,14 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor ...@@ -231,13 +231,14 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
// replace string and numerical // replace string and numerical
xml = xml.replace(/^\=\s*(.*?$)/gm, function(match, p) { xml = xml.replace(/^\=\s*(.*?$)/gm, function(match, p) {
var string; var string;
var params = /(.*?)\+\-\s*(.*?$)/.exec(p); var floatValue = parseFloat(p);
if(parseFloat(p)) { if(!isNaN(floatValue)) {
var params = /(.*?)\+\-\s*(.*?$)/.exec(p);
if(params) { if(params) {
string = '<numericalresponse answer="' + params[1] + '">\n'; string = '<numericalresponse answer="' + floatValue + '">\n';
string += ' <responseparam type="tolerance" default="' + params[2] + '" />\n'; string += ' <responseparam type="tolerance" default="' + params[2] + '" />\n';
} else { } else {
string = '<numericalresponse answer="' + p + '">\n'; string = '<numericalresponse answer="' + floatValue + '">\n';
} }
string += ' <textline />\n'; string += ' <textline />\n';
string += '</numericalresponse>\n\n'; string += '</numericalresponse>\n\n';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment