|
@@ -9,6 +9,7 @@
|
|
*/
|
|
*/
|
|
|
|
|
|
const { app, assert } = require('egg-mock/bootstrap');
|
|
const { app, assert } = require('egg-mock/bootstrap');
|
|
|
|
+const mathjs = require('mathjs');
|
|
|
|
|
|
describe('test/app/extend/helper.test.js', () => {
|
|
describe('test/app/extend/helper.test.js', () => {
|
|
it('ValidTemplateCode test', function () {
|
|
it('ValidTemplateCode test', function () {
|
|
@@ -48,4 +49,52 @@ describe('test/app/extend/helper.test.js', () => {
|
|
const result = ctx.helper.operationJson(testjson,'ok','world');
|
|
const result = ctx.helper.operationJson(testjson,'ok','world');
|
|
assert(result.ok === 'world');
|
|
assert(result.ok === 'world');
|
|
});
|
|
});
|
|
|
|
+ it('calcExprStr test', function () {
|
|
|
|
+ const ctx = app.mockContext();
|
|
|
|
+ assert(ctx.helper.calcExprStr('1+2').toFixed(2) == 3);
|
|
|
|
+ assert(ctx.helper.calcExprStr('1*2').toFixed(2) == 2);
|
|
|
|
+ assert(ctx.helper.calcExprStr('-1/2').toFixed(2) == -0.5);
|
|
|
|
+ assert(ctx.helper.calcExprStr('1-2').toFixed(2) == -1);
|
|
|
|
+
|
|
|
|
+ assert(ctx.helper.calcExprStr('1-2+3').toFixed(2) == 2);
|
|
|
|
+ assert(ctx.helper.calcExprStr('1-2*2').toFixed(2) == -3);
|
|
|
|
+ assert(ctx.helper.calcExprStr('1-2/2').toFixed(2) == 0);
|
|
|
|
+
|
|
|
|
+ assert(ctx.helper.calcExprStr('(2-1)/2').toFixed(2) == 0.5);
|
|
|
|
+ assert(ctx.helper.calcExprStr('(2+1)*2').toFixed(2) == 6);
|
|
|
|
+
|
|
|
|
+ assert(ctx.helper.calcExprStr('(2+1)*(3-2)').toFixed(2) == 3);
|
|
|
|
+ assert(ctx.helper.calcExprStr('(327+3)*(892-882)').toFixed(2) == 3300);
|
|
|
|
+
|
|
|
|
+ assert(!ctx.helper.calcExprStr('1-'));
|
|
|
|
+ assert(!ctx.helper.calcExprStr('1+'));
|
|
|
|
+ assert(!ctx.helper.calcExprStr('1/'));
|
|
|
|
+ assert(!ctx.helper.calcExprStr('1*'));
|
|
|
|
+ assert(!ctx.helper.calcExprStr('2/0'));
|
|
|
|
+ assert(ctx.helper.calcExprStr('-3').toFixed(2) == -3);
|
|
|
|
+ });
|
|
|
|
+ it('calcExprStrRpn test', function () {
|
|
|
|
+ const ctx = app.mockContext();
|
|
|
|
+ assert(ctx.helper.calcExprStrRpn('1+2').toFixed(2) == 3);
|
|
|
|
+ assert(ctx.helper.calcExprStrRpn('1*2').toFixed(2) == 2);
|
|
|
|
+ assert(ctx.helper.calcExprStrRpn('-1/2').toFixed(2) == -0.5);
|
|
|
|
+ assert(ctx.helper.calcExprStrRpn('1-2').toFixed(2) == -1);
|
|
|
|
+
|
|
|
|
+ assert(ctx.helper.calcExprStrRpn('1-2+3').toFixed(2) == 2);
|
|
|
|
+ assert(ctx.helper.calcExprStrRpn('1-2*2').toFixed(2) == -3);
|
|
|
|
+ assert(ctx.helper.calcExprStrRpn('1-2/2').toFixed(2) == 0);
|
|
|
|
+
|
|
|
|
+ assert(ctx.helper.calcExprStrRpn('(2-1)/2').toFixed(2) == 0.5);
|
|
|
|
+ assert(ctx.helper.calcExprStrRpn('(2+1)*2').toFixed(2) == 6);
|
|
|
|
+
|
|
|
|
+ assert(ctx.helper.calcExprStrRpn('(2+1)*(3-2)').toFixed(2) == 3);
|
|
|
|
+ assert(ctx.helper.calcExprStrRpn('(327+3)*(892-882)').toFixed(2) == 3300);
|
|
|
|
+
|
|
|
|
+ assert(!ctx.helper.calcExprStrRpn('1-'));
|
|
|
|
+ assert(!ctx.helper.calcExprStrRpn('1+'));
|
|
|
|
+ assert(!ctx.helper.calcExprStrRpn('1/'));
|
|
|
|
+ assert(!ctx.helper.calcExprStrRpn('1*'));
|
|
|
|
+ assert(!ctx.helper.calcExprStrRpn('2/0'));
|
|
|
|
+ assert(ctx.helper.calcExprStrRpn('-3').toFixed(2) == -3);
|
|
|
|
+ });
|
|
});
|
|
});
|