Commit e1288eba by Mike Chen

support for tolerance and decimals

parent 3c9ff574
......@@ -10,10 +10,21 @@ start
StudentProducedResponseIdentifier
= '='
NumericalToleranceValueType
= decimal / percentage / integer
NumericalTolerance
= '+-' OptionalSpaces value:NumericalToleranceValueType OptionalSpaces
{
return value;
}
NumericalResponse
= StudentProducedResponseIdentifier OptionalSpaces '(' OptionalSpaces value:NumericalValue OptionalSpaces ')' OptionalSpaces Linebreak
= StudentProducedResponseIdentifier OptionalSpaces '(' OptionalSpaces value:NumericalValue OptionalSpaces tolerance:NumericalTolerance? ')' OptionalSpaces Linebreak
{
return {'type': 'numerical', 'answer': value};
if (tolerance == "")
tolerance = "5%"
return {'type': 'numerical', 'answer': value, 'tolerance': tolerance};
}
StringResponse
......@@ -80,7 +91,6 @@ OptionalSpaces
Linebreak
= ('\n')
NumericalValue
= additive
......@@ -96,10 +106,16 @@ multiplicative
/ primary
primary
= integer
= decimal
/ integer
/ "(" additive:additive ")" { return additive; }
decimal "decimal"
= first:[0-9]+ point:'.' last:[0-9]+
{ return parseFloat(first.join("") + point + last.join("")); }
integer "integer"
= digits:[0-9]+ { return parseInt(digits.join(""), 10); }
percentage "percentage"
= digits:[0-9]+ '%' { return parseInt(digits.join(""), 10) + '%'; }
\ No newline at end of file
......@@ -81,6 +81,12 @@ class @CapaDescriptor
newel = $(doc.createElement('numericalresponse'))
newel.attr 'answer', section.answer
tolerance = $(doc.createElement('responseparam'))
tolerance.attr 'type', 'tolerance'
tolerance.attr 'default', section.tolerance
tolerance.attr 'name', 'tol'
tolerance.attr 'description', 'Numerical Tolerance'
newel.append tolerance
newel.append doc.createElement('textline')
problem.append(newel)
......
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