Commit e1288eba by Mike Chen

support for tolerance and decimals

parent 3c9ff574
...@@ -10,10 +10,21 @@ start ...@@ -10,10 +10,21 @@ start
StudentProducedResponseIdentifier StudentProducedResponseIdentifier
= '=' = '='
NumericalToleranceValueType
= decimal / percentage / integer
NumericalTolerance
= '+-' OptionalSpaces value:NumericalToleranceValueType OptionalSpaces
{
return value;
}
NumericalResponse 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 StringResponse
...@@ -80,7 +91,6 @@ OptionalSpaces ...@@ -80,7 +91,6 @@ OptionalSpaces
Linebreak Linebreak
= ('\n') = ('\n')
NumericalValue NumericalValue
= additive = additive
...@@ -96,10 +106,16 @@ multiplicative ...@@ -96,10 +106,16 @@ multiplicative
/ primary / primary
primary primary
= integer = decimal
/ integer
/ "(" additive:additive ")" { return additive; } / "(" additive:additive ")" { return additive; }
decimal "decimal"
= first:[0-9]+ point:'.' last:[0-9]+
{ return parseFloat(first.join("") + point + last.join("")); }
integer "integer" integer "integer"
= digits:[0-9]+ { return parseInt(digits.join(""), 10); } = 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 ...@@ -81,6 +81,12 @@ class @CapaDescriptor
newel = $(doc.createElement('numericalresponse')) newel = $(doc.createElement('numericalresponse'))
newel.attr 'answer', section.answer 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') newel.append doc.createElement('textline')
problem.append(newel) 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