Bug fix for #214.
https://edx.lighthouseapp.com/projects/102637-studio/tickets/214-Via-Tender-Numerical-Input-answer-0-a-tolerance-is-not-accepted#ticket-214-4
This commit is contained in:
@@ -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>Enter the numerical value of Pi:</p>
|
||||
<numericalresponse answer="3.14159 ">
|
||||
<numericalresponse answer="3.14159">
|
||||
<responseparam type="tolerance" default=".02" />
|
||||
<textline />
|
||||
</numericalresponse>
|
||||
|
||||
<p>Enter the approximate value of 502*9:</p>
|
||||
<numericalresponse answer="4518 ">
|
||||
<numericalresponse answer="4518">
|
||||
<responseparam type="tolerance" default="15%" />
|
||||
<textline />
|
||||
</numericalresponse>
|
||||
@@ -147,6 +147,20 @@ describe 'MarkdownEditingDescriptor', ->
|
||||
|
||||
</div>
|
||||
</solution>
|
||||
</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', ->
|
||||
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.
|
||||
@@ -369,4 +383,4 @@ describe 'MarkdownEditingDescriptor', ->
|
||||
<p>bad tests require drivel</p>
|
||||
</div>
|
||||
</problem>""")
|
||||
# failure tests
|
||||
# failure tests here
|
||||
|
||||
@@ -231,13 +231,14 @@ class @MarkdownEditingDescriptor extends XModule.Descriptor
|
||||
// replace string and numerical
|
||||
xml = xml.replace(/^\=\s*(.*?$)/gm, function(match, p) {
|
||||
var string;
|
||||
var params = /(.*?)\+\-\s*(.*?$)/.exec(p);
|
||||
if(parseFloat(p)) {
|
||||
var floatValue = parseFloat(p);
|
||||
if(!isNaN(floatValue)) {
|
||||
var params = /(.*?)\+\-\s*(.*?$)/.exec(p);
|
||||
if(params) {
|
||||
string = '<numericalresponse answer="' + params[1] + '">\n';
|
||||
string = '<numericalresponse answer="' + floatValue + '">\n';
|
||||
string += ' <responseparam type="tolerance" default="' + params[2] + '" />\n';
|
||||
} else {
|
||||
string = '<numericalresponse answer="' + p + '">\n';
|
||||
string = '<numericalresponse answer="' + floatValue + '">\n';
|
||||
}
|
||||
string += ' <textline />\n';
|
||||
string += '</numericalresponse>\n\n';
|
||||
|
||||
Reference in New Issue
Block a user