Skip to content

Commit

Permalink
correctPrecision check in numberentry part uses the cleaned answer
Browse files Browse the repository at this point in the history
  • Loading branch information
christianp committed Mar 8, 2021
1 parent 3e6a9b5 commit 18faf93
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
2 changes: 1 addition & 1 deletion marking_scripts/numberentry.jme
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ numberInRange (Is the student's number in the allowed range?):
)

correctPrecision (Has the student's answer been given to the desired precision?):
if(togivenprecision(studentanswer,settings['precisionType'],settings['precision'],settings["strictPrecision"]),
if(togivenprecision(cleanedStudentAnswer,settings['precisionType'],settings['precision'],settings["strictPrecision"]),
true
,
multiply_credit(settings["precisionPC"],settings["precisionMessage"]);
Expand Down
35 changes: 32 additions & 3 deletions tests/jme-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,33 @@ Numbas.queueScript('localisation',['i18next','localisation-resources'],function(
resources: Numbas.locale.resources
});
module.exports.R = function(){{ return i18next.t.apply(i18next,arguments) }};

var plain_en = ['plain','en','si-en'];
var plain_eu = ['plain-eu','eu','si-fr'];
Numbas.locale.default_number_notations = {
'ar-SA': plain_en,
'en-GB': plain_en,
'de-DE': plain_eu,
'es-ES': plain_eu,
'fr-FR': plain_eu,
'he-IL': plain_en,
'in-ID': plain_eu,
'it-IT': plain_eu,
'ja-JP': plain_en,
'ko-KR': plain_en,
'nb-NO': plain_eu,
'nl-NL': plain_eu,
'pl-PL': plain_eu,
'pt-BR': plain_eu,
'sq-AL': plain_eu,
'sv-SR': plain_eu,
'tr-TR': plain_eu,
'vi-VN': plain_eu,
'zh-CN': plain_en
}

Numbas.locale.default_number_notation = Numbas.locale.default_number_notations[Numbas.locale.preferred_locale] || plain_en;

});

/*
Expand Down Expand Up @@ -2575,10 +2602,11 @@ var math = Numbas.math = /** @lends Numbas.math */ {
if(options.precisionType === undefined && (piD = math.piDegree(n,false)) > 0)
n /= Math.pow(Math.PI,piD);
var out;
var style = options.style || Numbas.locale.default_number_notation[0];
if(options.style=='scientific') {
var s = n.toExponential();
var bits = math.parseScientific(s);
var noptions = {precisionType: options.precisionType, precision: options.precision, style: 'plain'};
var noptions = {precisionType: options.precisionType, precision: options.precision, style: style}
var significand = math.niceNumber(bits.significand,noptions);
var exponent = bits.exponent;
if(exponent>=0) {
Expand Down Expand Up @@ -2614,13 +2642,13 @@ var math = Numbas.math = /** @lends Numbas.math */ {
}
}
out = math.unscientific(out);
if(options.style && Numbas.util.numberNotationStyles[options.style]) {
if(style && Numbas.util.numberNotationStyles[style]) {
var match_neg = /^(-)?(.*)/.exec(out);
var minus = match_neg[1] || '';
var bits = match_neg[2].split('.');
var integer = bits[0];
var decimal = bits[1];
out = minus+Numbas.util.numberNotationStyles[options.style].format(integer,decimal);
out = minus+Numbas.util.numberNotationStyles[style].format(integer,decimal);
}
}
switch(piD)
Expand Down Expand Up @@ -4869,6 +4897,7 @@ var setmath = Numbas.setmath = {
return set.length;
}
}

});

Numbas.queueScript('i18next',[],function(module) {
Expand Down
35 changes: 32 additions & 3 deletions tests/numbas-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,33 @@ Numbas.queueScript('localisation',['i18next','localisation-resources'],function(
resources: Numbas.locale.resources
});
module.exports.R = function(){{ return i18next.t.apply(i18next,arguments) }};

var plain_en = ['plain','en','si-en'];
var plain_eu = ['plain-eu','eu','si-fr'];
Numbas.locale.default_number_notations = {
'ar-SA': plain_en,
'en-GB': plain_en,
'de-DE': plain_eu,
'es-ES': plain_eu,
'fr-FR': plain_eu,
'he-IL': plain_en,
'in-ID': plain_eu,
'it-IT': plain_eu,
'ja-JP': plain_en,
'ko-KR': plain_en,
'nb-NO': plain_eu,
'nl-NL': plain_eu,
'pl-PL': plain_eu,
'pt-BR': plain_eu,
'sq-AL': plain_eu,
'sv-SR': plain_eu,
'tr-TR': plain_eu,
'vi-VN': plain_eu,
'zh-CN': plain_en
}

Numbas.locale.default_number_notation = Numbas.locale.default_number_notations[Numbas.locale.preferred_locale] || plain_en;

});

/*
Expand Down Expand Up @@ -2575,10 +2602,11 @@ var math = Numbas.math = /** @lends Numbas.math */ {
if(options.precisionType === undefined && (piD = math.piDegree(n,false)) > 0)
n /= Math.pow(Math.PI,piD);
var out;
var style = options.style || Numbas.locale.default_number_notation[0];
if(options.style=='scientific') {
var s = n.toExponential();
var bits = math.parseScientific(s);
var noptions = {precisionType: options.precisionType, precision: options.precision, style: 'plain'};
var noptions = {precisionType: options.precisionType, precision: options.precision, style: style}
var significand = math.niceNumber(bits.significand,noptions);
var exponent = bits.exponent;
if(exponent>=0) {
Expand Down Expand Up @@ -2614,13 +2642,13 @@ var math = Numbas.math = /** @lends Numbas.math */ {
}
}
out = math.unscientific(out);
if(options.style && Numbas.util.numberNotationStyles[options.style]) {
if(style && Numbas.util.numberNotationStyles[style]) {
var match_neg = /^(-)?(.*)/.exec(out);
var minus = match_neg[1] || '';
var bits = match_neg[2].split('.');
var integer = bits[0];
var decimal = bits[1];
out = minus+Numbas.util.numberNotationStyles[options.style].format(integer,decimal);
out = minus+Numbas.util.numberNotationStyles[style].format(integer,decimal);
}
}
switch(piD)
Expand Down Expand Up @@ -4869,6 +4897,7 @@ var setmath = Numbas.setmath = {
return set.length;
}
}

});

Numbas.queueScript('jme-rules',['base','math','jme-base','util'],function() {
Expand Down

0 comments on commit 18faf93

Please sign in to comment.