Skip to content

Commit fb8d3a7

Browse files
committed
update tests
1 parent 7268aff commit fb8d3a7

5 files changed

Lines changed: 90 additions & 45 deletions

File tree

tests/jme-runtime.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9741,6 +9741,9 @@ var jme = Numbas.jme = /** @lends Numbas.jme */ {
97419741
var jmeifier = new Numbas.jme.display.JMEifier({}, scope);
97429742
return jmeifier.niceNumber(v.value, Numbas.jme.display.number_options(v));
97439743
},
9744+
'integer': function(v, scope) {
9745+
return v.bigValue.toString();
9746+
},
97449747
'rational': function(v) {
97459748
var f = v.value.reduced();
97469749
return f.toString();
@@ -17822,7 +17825,7 @@ builtin_function_set({name: 'jme', description: 'Working with JME expressions'},
1782217825

1782317826
set.add_function('expression', [TString], TExpression, null, {
1782417827
evaluate: function(args, scope) {
17825-
var notation = Numbas.locale.default_number_notation;
17828+
var number_notation = Numbas.locale.default_number_notation;
1782617829
Numbas.locale.default_number_notation = ['plain'];
1782717830
/**
1782817831
* Replace all strings in the given expression with copies marked with `subjme`.
@@ -17848,13 +17851,17 @@ builtin_function_set({name: 'jme', description: 'Working with JME expressions'},
1784817851
try {
1784917852
var str = scope.evaluate(arg);
1785017853
} finally {
17851-
Numbas.locale.default_number_notation = notation;
17854+
Numbas.locale.default_number_notation = number_notation;
1785217855
}
1785317856
if(!jme.isType(str, 'string')) {
1785417857
throw(new Numbas.Error('jme.typecheck.no right type definition', {op:'expression'}));
1785517858
}
1785617859
str = jme.castToType(str, 'string');
17857-
return new TExpression(jme.compile(str.value));
17860+
17861+
var jme_notation_name = args.length > 1 ? jme.castToType(scope.evaluate(args[1]), 'string').value : 'standard';
17862+
var jme_notation = get_notation(jme_notation_name);
17863+
17864+
return new TExpression(jme_notation.compile(str.value));
1785817865
}
1785917866
});
1786017867
Numbas.jme.lazyOps.push('expression');
@@ -20939,7 +20946,7 @@ var typeToJME = Numbas.jme.display.typeToJME = {
2093920946
return 'nothing';
2094020947
},
2094120948
'integer': function(tree, tok, bits) {
20942-
return this.number(tok.value, number_options(tok));
20949+
return math.niceNumber(tok.bigValue, number_options(tok));
2094320950
},
2094420951
'rational': function(tree, tok, bits) {
2094520952
var value = tok.value.reduced();
@@ -22162,6 +22169,7 @@ class RealIntervalNotation extends Notation {
2216222169
}
2216322170

2216422171
class PatternNotation extends Notation {
22172+
name = 'Pattern matching';
2216522173
Parser = jme.rules.PatternParser;
2216622174
}
2216722175

tests/jme/jme-tests.mjs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,8 +2478,8 @@ Numbas.queueScript('jme_tests',['qunit','jme','jme-rules','jme-display','jme-cal
24782478
assert.equal(simplifyExpression('-4+5i','all'),'-4 + 5i','-4+5i - unary minus brought out of complex number properly');
24792479
assert.equal(simplifyExpression('(1-i)+(-2+2i)','collectComplex'),'1 - i - 2 + 2i','(1-i)+(-2+2i) - addition of complex numbers with negative imaginary parts');
24802480
assert.equal(simplifyExpression('(1-i)-(-2+2i)','collectComplex'),'1 - i + 2 - 2i','(1-i)-(-2+2i) - addition of complex numbers with negative imaginary parts');
2481-
assert.equal(simplifyExpression('10000000000000000000000000',{flags:{noscientificnumbers:false}}),'1*10^(25)','scientific notation - 1*10^25');
2482-
assert.equal(simplifyExpression('47652000000000000000000000',{flags:{noscientificnumbers:false}}),'4.7652*10^(25)','scientific notation - 4.7652*10^25');
2481+
assert.equal(simplifyExpression('10000000000000000000000000.0',{flags:{noscientificnumbers:false}}),'1*10^(25)','scientific notation - 1*10^25');
2482+
assert.equal(simplifyExpression('47652000000000000000000000.0',{flags:{noscientificnumbers:false}}),'4.7652*10^(25)','scientific notation - 4.7652*10^25');
24832483
assert.equal(simplifyExpression('x+(-10+2)','all,collectNumbers'),'x - 8','x+(-10+2) - negative number in the middle of an addition gets cancelled through properly');
24842484
assert.equal(simplifyExpression('4-(x^2+x+1)',[]),'4 - (x^2 + x + 1)',"4-(x^2+x+1) - brackets round right-hand operand in subtraction kept when they\'re wrapping an addition.");
24852485
assert.equal(simplifyExpression('(x^2+x)-4',[]),'x^2 + x - 4','(x^2+x)-4 - brackets round left-hand operand in subtraction can be dropped.');
@@ -2828,7 +2828,7 @@ Numbas.queueScript('jme_tests',['qunit','jme','jme-rules','jme-display','jme-cal
28282828

28292829
QUnit.module('Promises');
28302830
QUnit.test('makeVariablesPromise', async function(assert) {
2831-
assert.expect(4);
2831+
assert.expect(3);
28322832
const done = assert.async();
28332833

28342834
const scope = new jme.Scope([jme.builtinScope]);
@@ -2847,8 +2847,6 @@ Numbas.queueScript('jme_tests',['qunit','jme','jme-rules','jme-display','jme-cal
28472847
const todo = {
28482848
'q': { tree: jme.compile('wait(0.1)'), vars: []},
28492849
'z': { tree: jme.compile('q+1'), vars: ['q']},
2850-
'fetched_file': { tree: jme.compile('fetch_text("/README.md")'), vars: []},
2851-
'file_length': { tree: jme.compile('len(fetched_file)'), vars: ['fetched_file']},
28522850
};
28532851

28542852
const res = jme.variables.makeVariablesPromise(todo, scope);
@@ -2857,7 +2855,6 @@ Numbas.queueScript('jme_tests',['qunit','jme','jme-rules','jme-display','jme-cal
28572855
res.then((result) => {
28582856
assert.equal(result.variables.q.type, 'number', 'q is a number');
28592857
assert.equal(result.variables.z.value, '1.1', 'z = q + 1 = 1.1');
2860-
assert.equal(result.variables.fetched_file.type, 'string', 'fetched_file is a string');
28612858
done();
28622859
});
28632860
});

tests/locales.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,8 +2068,8 @@ Numbas.locale = {
20682068
"question.score feedback.score total actual": "Score: {{score,niceNumber}}/{{marks,niceNumber}}",
20692069
"question.score feedback.score actual.plain": "{{scoreString}}",
20702070
"question.score feedback.score total actual.plain": "{{score,niceNumber}}/{{marks,niceNumber}}",
2071-
"question.score feedback.correct": "Your answer is correct",
2072-
"question.score feedback.partial": "Your answer is partially correct",
2071+
"question.score feedback.correct": "Your answer is correct.",
2072+
"question.score feedback.partial": "Your answer is partially correct.",
20732073
"question.score feedback.wrong": "Your answer is incorrect",
20742074
"question.objectives": "Objectives",
20752075
"question.penalties": "Penalties",
@@ -2155,7 +2155,12 @@ Numbas.locale = {
21552155
"worksheet.right": "Right",
21562156
"modal.style.text size preview": "Most text will be this big.",
21572157
"part.show feedback": "Show feedback",
2158-
"part.hide feedback": "Hide feedback"
2158+
"part.hide feedback": "Hide feedback",
2159+
"icon.correct": "✔",
2160+
"icon.partial": "✔",
2161+
"icon.wrong": "✘",
2162+
"icon.warning": "❗",
2163+
"icon.none": ""
21592164
}
21602165
}
21612166
,

0 commit comments

Comments
 (0)