From c0f0ef0cd2fea7dcd18aa7a150f143d17207a4cd Mon Sep 17 00:00:00 2001 From: cahrens Date: Wed, 27 Feb 2013 17:34:08 -0500 Subject: [PATCH] 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 --- .../xmodule/js/spec/problem/edit_spec.coffee | 20 ++++++++++++++++--- .../xmodule/js/src/problem/edit.coffee | 9 +++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/common/lib/xmodule/xmodule/js/spec/problem/edit_spec.coffee b/common/lib/xmodule/xmodule/js/spec/problem/edit_spec.coffee index 9b8062d60d..cf7d6bef94 100644 --- a/common/lib/xmodule/xmodule/js/spec/problem/edit_spec.coffee +++ b/common/lib/xmodule/xmodule/js/spec/problem/edit_spec.coffee @@ -119,13 +119,13 @@ describe 'MarkdownEditingDescriptor', ->

The answer is correct if it is within a specified numerical tolerance of the expected answer.

Enter the numerical value of Pi:

- +

Enter the approximate value of 502*9:

- + @@ -147,6 +147,20 @@ describe 'MarkdownEditingDescriptor', -> + """) + 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(""" +

Enter 0 with a tolerance:

+ + + + + +
""") 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', ->

bad tests require drivel

""") - # failure tests + # failure tests here diff --git a/common/lib/xmodule/xmodule/js/src/problem/edit.coffee b/common/lib/xmodule/xmodule/js/src/problem/edit.coffee index 2bfe483a7f..b723f230e9 100644 --- a/common/lib/xmodule/xmodule/js/src/problem/edit.coffee +++ b/common/lib/xmodule/xmodule/js/src/problem/edit.coffee @@ -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 = '\n'; + string = '\n'; string += ' \n'; } else { - string = '\n'; + string = '\n'; } string += ' \n'; string += '\n\n';