feat: 1.3.7, solves #15
This commit is contained in:
parent
db3ec53031
commit
e30d6a44b3
16
dist/constants.js
vendored
16
dist/constants.js
vendored
@ -1,17 +1,17 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
Object.defineProperty(exports, '__esModule', {
|
|
||||||
value: true
|
|
||||||
});
|
|
||||||
/*
|
/*
|
||||||
* Constats
|
* Constats
|
||||||
* Keys must be UPPERCASE
|
* Keys must be UPPERCASE
|
||||||
* Values Can be a constant value or a function returning a value
|
* Values Can be a constant value or a function returning a value
|
||||||
* this function doesn't take any arguments (use case: random constats)
|
* this function doesn't take any arguments (use case: random constats)
|
||||||
*/
|
*/
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
Object.defineProperty(exports, '__esModule', {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
exports['default'] = {
|
exports['default'] = {
|
||||||
PI: Math.PI,
|
'PI': Math.PI,
|
||||||
E: Math.E,
|
'E': Math.E,
|
||||||
RAND: Math.random
|
'RAND': Math.random
|
||||||
};
|
};
|
||||||
module.exports = exports['default'];
|
module.exports = exports['default'];
|
64
dist/helpers.js
vendored
64
dist/helpers.js
vendored
@ -17,17 +17,7 @@ var isNumber = function isNumber(a) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.isNumber = isNumber;
|
exports.isNumber = isNumber;
|
||||||
var parseNumbers = (function (_parseNumbers) {
|
var parseNumbers = function parseNumbers(a) {
|
||||||
function parseNumbers(_x) {
|
|
||||||
return _parseNumbers.apply(this, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
parseNumbers.toString = function () {
|
|
||||||
return _parseNumbers.toString();
|
|
||||||
};
|
|
||||||
|
|
||||||
return parseNumbers;
|
|
||||||
})(function (a) {
|
|
||||||
return a.map(function (b) {
|
return a.map(function (b) {
|
||||||
if (isNumber(b)) {
|
if (isNumber(b)) {
|
||||||
return parseFloat(b);
|
return parseFloat(b);
|
||||||
@ -37,7 +27,7 @@ var parseNumbers = (function (_parseNumbers) {
|
|||||||
}
|
}
|
||||||
return b;
|
return b;
|
||||||
});
|
});
|
||||||
});
|
};
|
||||||
|
|
||||||
exports.parseNumbers = parseNumbers;
|
exports.parseNumbers = parseNumbers;
|
||||||
var dive = function dive(arr, n) {
|
var dive = function dive(arr, n) {
|
||||||
@ -49,18 +39,8 @@ var dive = function dive(arr, n) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.dive = dive;
|
exports.dive = dive;
|
||||||
var deep = (function (_deep) {
|
var deep = function deep(arr, n) {
|
||||||
function deep(_x2, _x3) {
|
var index = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
|
||||||
return _deep.apply(this, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
deep.toString = function () {
|
|
||||||
return _deep.toString();
|
|
||||||
};
|
|
||||||
|
|
||||||
return deep;
|
|
||||||
})(function (arr, n) {
|
|
||||||
var index = arguments[2] === undefined ? 0 : arguments[2];
|
|
||||||
|
|
||||||
if (n < 2) {
|
if (n < 2) {
|
||||||
return { arr: arr, index: index };
|
return { arr: arr, index: index };
|
||||||
@ -68,10 +48,10 @@ var deep = (function (_deep) {
|
|||||||
|
|
||||||
var d = arr.reduce(function (a, b, i) {
|
var d = arr.reduce(function (a, b, i) {
|
||||||
if (Array.isArray(b)) {
|
if (Array.isArray(b)) {
|
||||||
var _deep2 = deep(b, n - 1, i);
|
var _deep = deep(b, n - 1, i);
|
||||||
|
|
||||||
var _arr = _deep2.arr;
|
var _arr = _deep.arr;
|
||||||
var x = _deep2.index;
|
var x = _deep.index;
|
||||||
var merged = a.concat(_arr);
|
var merged = a.concat(_arr);
|
||||||
|
|
||||||
index = x;
|
index = x;
|
||||||
@ -81,20 +61,10 @@ var deep = (function (_deep) {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return { arr: d, index: index };
|
return { arr: d, index: index };
|
||||||
});
|
};
|
||||||
|
|
||||||
exports.deep = deep;
|
exports.deep = deep;
|
||||||
var diveTo = (function (_diveTo) {
|
var diveTo = function diveTo(arr, indexes, replace) {
|
||||||
function diveTo(_x4, _x5, _x6) {
|
|
||||||
return _diveTo.apply(this, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
diveTo.toString = function () {
|
|
||||||
return _diveTo.toString();
|
|
||||||
};
|
|
||||||
|
|
||||||
return diveTo;
|
|
||||||
})(function (arr, indexes, replace) {
|
|
||||||
var answer = [];
|
var answer = [];
|
||||||
if (indexes.some(Array.isArray)) {
|
if (indexes.some(Array.isArray)) {
|
||||||
var _iteratorNormalCompletion = true;
|
var _iteratorNormalCompletion = true;
|
||||||
@ -127,20 +97,10 @@ var diveTo = (function (_diveTo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return answer;
|
return answer;
|
||||||
});
|
};
|
||||||
|
|
||||||
exports.diveTo = diveTo;
|
exports.diveTo = diveTo;
|
||||||
var flatten = (function (_flatten) {
|
var flatten = function flatten(arr) {
|
||||||
function flatten(_x7) {
|
|
||||||
return _flatten.apply(this, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
flatten.toString = function () {
|
|
||||||
return _flatten.toString();
|
|
||||||
};
|
|
||||||
|
|
||||||
return flatten;
|
|
||||||
})(function (arr) {
|
|
||||||
if (!Array.isArray(arr) || !arr.some(Array.isArray)) {
|
if (!Array.isArray(arr) || !arr.some(Array.isArray)) {
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
@ -148,7 +108,7 @@ var flatten = (function (_flatten) {
|
|||||||
return arr.reduce(function (a, b) {
|
return arr.reduce(function (a, b) {
|
||||||
return a.concat(flatten(b));
|
return a.concat(flatten(b));
|
||||||
}, []);
|
}, []);
|
||||||
});
|
};
|
||||||
|
|
||||||
exports.flatten = flatten;
|
exports.flatten = flatten;
|
||||||
var removeSymbols = function removeSymbols(string) {
|
var removeSymbols = function removeSymbols(string) {
|
||||||
|
64
dist/index.js
vendored
64
dist/index.js
vendored
@ -1,32 +1,34 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; };
|
|
||||||
|
|
||||||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } };
|
|
||||||
|
|
||||||
var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } };
|
|
||||||
|
|
||||||
Object.defineProperty(exports, '__esModule', {
|
Object.defineProperty(exports, '__esModule', {
|
||||||
value: true
|
value: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();
|
||||||
|
|
||||||
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }
|
||||||
|
|
||||||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||||
|
|
||||||
|
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
|
||||||
|
|
||||||
require('babel/polyfill');
|
require('babel/polyfill');
|
||||||
|
|
||||||
var _ReadStream = require('./readstream');
|
var _readstream = require('./readstream');
|
||||||
|
|
||||||
var _ReadStream2 = _interopRequireWildcard(_ReadStream);
|
var _readstream2 = _interopRequireDefault(_readstream);
|
||||||
|
|
||||||
var _operators = require('./operators');
|
var _operators = require('./operators');
|
||||||
|
|
||||||
var _operators2 = _interopRequireWildcard(_operators);
|
var _operators2 = _interopRequireDefault(_operators);
|
||||||
|
|
||||||
var _constants = require('./constants');
|
var _constants = require('./constants');
|
||||||
|
|
||||||
var _constants2 = _interopRequireWildcard(_constants);
|
var _constants2 = _interopRequireDefault(_constants);
|
||||||
|
|
||||||
var _import = require('./helpers');
|
var _helpers = require('./helpers');
|
||||||
|
|
||||||
var _ = _interopRequireWildcard(_import);
|
var _ = _interopRequireWildcard(_helpers);
|
||||||
|
|
||||||
var Equation = {
|
var Equation = {
|
||||||
/**
|
/**
|
||||||
@ -118,17 +120,13 @@ var Equation = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var solveStack = (function (_solveStack) {
|
var solveStack = function solveStack(_x) {
|
||||||
function solveStack(_x) {
|
var _again = true;
|
||||||
return _solveStack.apply(this, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
solveStack.toString = function () {
|
_function: while (_again) {
|
||||||
return _solveStack.toString();
|
var stack = _x;
|
||||||
};
|
_again = false;
|
||||||
|
|
||||||
return solveStack;
|
|
||||||
})(function (stack) {
|
|
||||||
// if an operator takes an expression argument, we should not dive into it
|
// if an operator takes an expression argument, we should not dive into it
|
||||||
// and solve the expression inside
|
// and solve the expression inside
|
||||||
var hasExpressionArgument = stack.some(function (a) {
|
var hasExpressionArgument = stack.some(function (a) {
|
||||||
@ -143,11 +141,15 @@ var solveStack = (function (_solveStack) {
|
|||||||
return solveStack(group);
|
return solveStack(group);
|
||||||
});
|
});
|
||||||
|
|
||||||
return solveStack(stack);
|
_x = stack;
|
||||||
|
_again = true;
|
||||||
|
hasExpressionArgument = undefined;
|
||||||
|
continue _function;
|
||||||
} else {
|
} else {
|
||||||
return evaluate(stack);
|
return evaluate(stack);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var PRECEDENCES = Object.keys(_operators2['default']).map(function (key) {
|
var PRECEDENCES = Object.keys(_operators2['default']).map(function (key) {
|
||||||
return _operators2['default'][key].precedence;
|
return _operators2['default'][key].precedence;
|
||||||
@ -173,7 +175,7 @@ var parseExpression = function parseExpression(expression) {
|
|||||||
// separately
|
// separately
|
||||||
expression = expression.replace(/,/g, ')(');
|
expression = expression.replace(/,/g, ')(');
|
||||||
|
|
||||||
var stream = new _ReadStream2['default'](expression),
|
var stream = new _readstream2['default'](expression),
|
||||||
stack = [],
|
stack = [],
|
||||||
record = '',
|
record = '',
|
||||||
cur = undefined,
|
cur = undefined,
|
||||||
@ -304,17 +306,7 @@ var formatInfo = function formatInfo(operator) {
|
|||||||
* @return {Array}
|
* @return {Array}
|
||||||
* Grouped expression based on precedences
|
* Grouped expression based on precedences
|
||||||
*/
|
*/
|
||||||
var sortStack = (function (_sortStack) {
|
var sortStack = function sortStack(stack) {
|
||||||
function sortStack(_x2) {
|
|
||||||
return _sortStack.apply(this, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
sortStack.toString = function () {
|
|
||||||
return _sortStack.toString();
|
|
||||||
};
|
|
||||||
|
|
||||||
return sortStack;
|
|
||||||
})(function (stack) {
|
|
||||||
var _iteratorNormalCompletion = true;
|
var _iteratorNormalCompletion = true;
|
||||||
var _didIteratorError = false;
|
var _didIteratorError = false;
|
||||||
var _iteratorError = undefined;
|
var _iteratorError = undefined;
|
||||||
@ -371,7 +363,7 @@ var sortStack = (function (_sortStack) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return stack;
|
return stack;
|
||||||
});
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evaluates the given math expression.
|
* Evaluates the given math expression.
|
||||||
|
32
dist/operators.js
vendored
32
dist/operators.js
vendored
@ -1,14 +1,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; };
|
|
||||||
|
|
||||||
Object.defineProperty(exports, '__esModule', {
|
Object.defineProperty(exports, '__esModule', {
|
||||||
value: true
|
value: true
|
||||||
});
|
});
|
||||||
|
|
||||||
var _Equation = require('./index');
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||||
|
|
||||||
var _Equation2 = _interopRequireWildcard(_Equation);
|
var _index = require('./index');
|
||||||
|
|
||||||
|
var _index2 = _interopRequireDefault(_index);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Operators and Functions
|
* Operators and Functions
|
||||||
@ -77,7 +77,7 @@ exports['default'] = {
|
|||||||
'!': {
|
'!': {
|
||||||
fn: function fn(a) {
|
fn: function fn(a) {
|
||||||
var sum = 1;
|
var sum = 1;
|
||||||
for (var i = 0; i < a; ++i) {
|
for (var i = 1; i <= a; ++i) {
|
||||||
sum *= i;
|
sum *= i;
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
@ -85,61 +85,61 @@ exports['default'] = {
|
|||||||
format: '01',
|
format: '01',
|
||||||
precedence: 2
|
precedence: 2
|
||||||
},
|
},
|
||||||
log: {
|
'log': {
|
||||||
fn: Math.log,
|
fn: Math.log,
|
||||||
format: '10',
|
format: '10',
|
||||||
precedence: -1
|
precedence: -1
|
||||||
},
|
},
|
||||||
ln: {
|
'ln': {
|
||||||
fn: Math.log,
|
fn: Math.log,
|
||||||
format: '10',
|
format: '10',
|
||||||
precedence: -1
|
precedence: -1
|
||||||
},
|
},
|
||||||
lg: {
|
'lg': {
|
||||||
fn: function fn(a) {
|
fn: function fn(a) {
|
||||||
return Math.log(a) / Math.log(2);
|
return Math.log(a) / Math.log(2);
|
||||||
},
|
},
|
||||||
format: '10',
|
format: '10',
|
||||||
precedence: -1
|
precedence: -1
|
||||||
},
|
},
|
||||||
sin: {
|
'sin': {
|
||||||
fn: Math.sin,
|
fn: Math.sin,
|
||||||
format: '10',
|
format: '10',
|
||||||
precedence: -1
|
precedence: -1
|
||||||
},
|
},
|
||||||
cos: {
|
'cos': {
|
||||||
fn: Math.cos,
|
fn: Math.cos,
|
||||||
format: '10',
|
format: '10',
|
||||||
precedence: -1
|
precedence: -1
|
||||||
},
|
},
|
||||||
tan: {
|
'tan': {
|
||||||
fn: Math.tan,
|
fn: Math.tan,
|
||||||
format: '10',
|
format: '10',
|
||||||
precedence: -1
|
precedence: -1
|
||||||
},
|
},
|
||||||
cot: {
|
'cot': {
|
||||||
fn: Math.cot,
|
fn: Math.cot,
|
||||||
format: '10',
|
format: '10',
|
||||||
precedence: -1
|
precedence: -1
|
||||||
},
|
},
|
||||||
round: {
|
'round': {
|
||||||
fn: Math.round,
|
fn: Math.round,
|
||||||
format: '10',
|
format: '10',
|
||||||
precedence: -1
|
precedence: -1
|
||||||
},
|
},
|
||||||
floor: {
|
'floor': {
|
||||||
fn: Math.floor,
|
fn: Math.floor,
|
||||||
format: '10',
|
format: '10',
|
||||||
precedence: -1
|
precedence: -1
|
||||||
},
|
},
|
||||||
sigma: {
|
'sigma': {
|
||||||
fn: function fn(from, to, expression) {
|
fn: function fn(from, to, expression) {
|
||||||
var expr = expression.join('').replace(/,/g, '');
|
var expr = expression.join('').replace(/,/g, '');
|
||||||
var regex = new RegExp(ITERATOR_SIGN, 'g');
|
var regex = new RegExp(ITERATOR_SIGN, 'g');
|
||||||
|
|
||||||
var sum = 0;
|
var sum = 0;
|
||||||
for (var i = from; i <= to; i++) {
|
for (var i = from; i <= to; i++) {
|
||||||
sum += _Equation2['default'].solve(expr.replace(regex, i));
|
sum += _index2['default'].solve(expr.replace(regex, i));
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
},
|
},
|
||||||
|
16
dist/readstream.js
vendored
16
dist/readstream.js
vendored
@ -33,23 +33,13 @@ exports['default'] = function (string) {
|
|||||||
drain: function drain() {
|
drain: function drain() {
|
||||||
return buffer.splice(0, buffer.length);
|
return buffer.splice(0, buffer.length);
|
||||||
},
|
},
|
||||||
replace: (function (_replace) {
|
replace: function replace(start, end, _replace) {
|
||||||
function replace(_x, _x2, _x3) {
|
|
||||||
return _replace.apply(this, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
replace.toString = function () {
|
|
||||||
return _replace.toString();
|
|
||||||
};
|
|
||||||
|
|
||||||
return replace;
|
|
||||||
})(function (start, end, replace) {
|
|
||||||
var temp = string.split('');
|
var temp = string.split('');
|
||||||
temp.splice(start, end, replace);
|
temp.splice(start, end, _replace);
|
||||||
string = temp.join('');
|
string = temp.join('');
|
||||||
|
|
||||||
i = i - (end - start);
|
i = i - (end - start);
|
||||||
}),
|
},
|
||||||
go: function go(n) {
|
go: function go(n) {
|
||||||
i += n;
|
i += n;
|
||||||
},
|
},
|
||||||
|
36
dist/tests/equation.js
vendored
36
dist/tests/equation.js
vendored
@ -1,46 +1,46 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; };
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||||
|
|
||||||
var _expect = require('chai');
|
var _chai = require('chai');
|
||||||
|
|
||||||
var _M = require('../index.js');
|
var _indexJs = require('../index.js');
|
||||||
|
|
||||||
var _M2 = _interopRequireWildcard(_M);
|
var _indexJs2 = _interopRequireDefault(_indexJs);
|
||||||
|
|
||||||
describe('Equations', function () {
|
describe('Equations', function () {
|
||||||
it('should work with one variable', function () {
|
it('should work with one variable', function () {
|
||||||
var equation = _M2['default'].equation('x+2');
|
var equation = _indexJs2['default'].equation('x+2');
|
||||||
|
|
||||||
_expect.expect(equation(2)).to.equal(4);
|
(0, _chai.expect)(equation(2)).to.equal(4);
|
||||||
|
|
||||||
// Issue #10
|
// Issue #10
|
||||||
var subtraction = _M2['default'].equation('x - 3');
|
var subtraction = _indexJs2['default'].equation('x - 3');
|
||||||
_expect.expect(subtraction(10)).to.equal(7);
|
(0, _chai.expect)(subtraction(10)).to.equal(7);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work with multiple variables', function () {
|
it('should work with multiple variables', function () {
|
||||||
var equation = _M2['default'].equation('x+y');
|
var equation = _indexJs2['default'].equation('x+y');
|
||||||
_expect.expect(equation(2, 4)).to.equal(6);
|
(0, _chai.expect)(equation(2, 4)).to.equal(6);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work with multiple instances of the same variable', function () {
|
it('should work with multiple instances of the same variable', function () {
|
||||||
var equation = _M2['default'].equation('x*x');
|
var equation = _indexJs2['default'].equation('x*x');
|
||||||
_expect.expect(equation(4)).to.equal(16);
|
(0, _chai.expect)(equation(4)).to.equal(16);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should only accept lowercase letters', function () {
|
it('should only accept lowercase letters', function () {
|
||||||
var equation = _M2['default'].equation('X+2');
|
var equation = _indexJs2['default'].equation('X+2');
|
||||||
_expect.expect(equation).to['throw']();
|
(0, _chai.expect)(equation).to['throw']();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work with NumVariable expressions like 2x', function () {
|
it('should work with NumVariable expressions like 2x', function () {
|
||||||
var equation = _M2['default'].equation('2x + 6y');
|
var equation = _indexJs2['default'].equation('2x + 6y');
|
||||||
_expect.expect(equation(4, 3)).to.equal(8 + 18);
|
(0, _chai.expect)(equation(4, 3)).to.equal(8 + 18);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test case', function () {
|
it('Test case', function () {
|
||||||
var equation = _M2['default'].equation('2+x*(y+4)+z^2');
|
var equation = _indexJs2['default'].equation('2+x*(y+4)+z^2');
|
||||||
_expect.expect(equation(2, 4, 3)).to.equal(27);
|
(0, _chai.expect)(equation(2, 4, 3)).to.equal(27);
|
||||||
});
|
});
|
||||||
});
|
});
|
60
dist/tests/solve.js
vendored
60
dist/tests/solve.js
vendored
@ -1,116 +1,116 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; };
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||||
|
|
||||||
var _expect = require('chai');
|
var _chai = require('chai');
|
||||||
|
|
||||||
var _M = require('../index.js');
|
var _indexJs = require('../index.js');
|
||||||
|
|
||||||
var _M2 = _interopRequireWildcard(_M);
|
var _indexJs2 = _interopRequireDefault(_indexJs);
|
||||||
|
|
||||||
describe('Basic math operators', function () {
|
describe('Basic math operators', function () {
|
||||||
it('should work for add +', function () {
|
it('should work for add +', function () {
|
||||||
_expect.expect(_M2['default'].solve('2+2')).to.equal(4);
|
(0, _chai.expect)(_indexJs2['default'].solve('2+2')).to.equal(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work for minus -', function () {
|
it('should work for minus -', function () {
|
||||||
_expect.expect(_M2['default'].solve('15-3')).to.equal(12);
|
(0, _chai.expect)(_indexJs2['default'].solve('15-3')).to.equal(12);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work for divison /', function () {
|
it('should work for divison /', function () {
|
||||||
_expect.expect(_M2['default'].solve('20/2')).to.equal(10);
|
(0, _chai.expect)(_indexJs2['default'].solve('20/2')).to.equal(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work for multiplication *', function () {
|
it('should work for multiplication *', function () {
|
||||||
_expect.expect(_M2['default'].solve('6*3')).to.equal(18);
|
(0, _chai.expect)(_indexJs2['default'].solve('6*3')).to.equal(18);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work for power ^', function () {
|
it('should work for power ^', function () {
|
||||||
_expect.expect(_M2['default'].solve('5^2')).to.equal(25);
|
(0, _chai.expect)(_indexJs2['default'].solve('5^2')).to.equal(25);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work for multi-digit numbers', function () {
|
it('should work for multi-digit numbers', function () {
|
||||||
_expect.expect(_M2['default'].solve('12+15')).to.equal(27);
|
(0, _chai.expect)(_indexJs2['default'].solve('12+15')).to.equal(27);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should deal with floating precision of javascript - #5', function () {
|
it('should deal with floating precision of javascript - #5', function () {
|
||||||
_expect.expect(_M2['default'].solve('0.2 + 0.1')).to.equal(0.3);
|
(0, _chai.expect)(_indexJs2['default'].solve('0.2 + 0.1')).to.equal(0.3);
|
||||||
_expect.expect(_M2['default'].solve('0.2 + 0.4')).to.equal(0.6);
|
(0, _chai.expect)(_indexJs2['default'].solve('0.2 + 0.4')).to.equal(0.6);
|
||||||
_expect.expect(_M2['default'].solve('round(floor(1.23456789/0.2)) * 0.2')).to.equal(1.2);
|
(0, _chai.expect)(_indexJs2['default'].solve('round(floor(1.23456789/0.2)) * 0.2')).to.equal(1.2);
|
||||||
_expect.expect(_M2['default'].solve('1.23456789 - (1.23456789 % 0.2)')).to.equal(1.2);
|
(0, _chai.expect)(_indexJs2['default'].solve('1.23456789 - (1.23456789 % 0.2)')).to.equal(1.2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Negative Numbers', function () {
|
describe('Negative Numbers', function () {
|
||||||
it('should work for negative numbers after operators', function () {
|
it('should work for negative numbers after operators', function () {
|
||||||
_expect.expect(_M2['default'].solve('2 + -5')).to.equal(-3);
|
(0, _chai.expect)(_indexJs2['default'].solve('2 + -5')).to.equal(-3);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work for negative numbers after groups', function () {
|
it('should work for negative numbers after groups', function () {
|
||||||
_expect.expect(_M2['default'].solve('1 + (2 - 5) - 2')).to.equal(-4);
|
(0, _chai.expect)(_indexJs2['default'].solve('1 + (2 - 5) - 2')).to.equal(-4);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work for expressions starting with negative numbers', function () {
|
it('should work for expressions starting with negative numbers', function () {
|
||||||
_expect.expect(_M2['default'].solve('-2 + 1')).to.equal(-1);
|
(0, _chai.expect)(_indexJs2['default'].solve('-2 + 1')).to.equal(-1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Precedence', function () {
|
describe('Precedence', function () {
|
||||||
it('Test case 1', function () {
|
it('Test case 1', function () {
|
||||||
_expect.expect(_M2['default'].solve('2+(2+1)*(1+1)^2')).to.equal(14);
|
(0, _chai.expect)(_indexJs2['default'].solve('2+(2+1)*(1+1)^2')).to.equal(14);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test case 2', function () {
|
it('Test case 2', function () {
|
||||||
_expect.expect(_M2['default'].solve('2+5*4/2-2')).to.equal(10);
|
(0, _chai.expect)(_indexJs2['default'].solve('2+5*4/2-2')).to.equal(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test case 3', function () {
|
it('Test case 3', function () {
|
||||||
_expect.expect(_M2['default'].solve('2+(5*4/2)-2')).to.equal(10);
|
(0, _chai.expect)(_indexJs2['default'].solve('2+(5*4/2)-2')).to.equal(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test case 4', function () {
|
it('Test case 4', function () {
|
||||||
_expect.expect(_M2['default'].solve('(2+2)^2+(5+1)*4+(2+(4/2)/2)')).to.equal(16 + 24 + 3);
|
(0, _chai.expect)(_indexJs2['default'].solve('(2+2)^2+(5+1)*4+(2+(4/2)/2)')).to.equal(16 + 24 + 3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Functions', function () {
|
describe('Functions', function () {
|
||||||
it('should work with parantheses', function () {
|
it('should work with parantheses', function () {
|
||||||
_expect.expect(_M2['default'].solve('lg(4) * 5')).to.equal(10);
|
(0, _chai.expect)(_indexJs2['default'].solve('lg(4) * 5')).to.equal(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work without parantheses', function () {
|
it('should work without parantheses', function () {
|
||||||
_expect.expect(_M2['default'].solve('lg4 * 5')).to.equal(10);
|
(0, _chai.expect)(_indexJs2['default'].solve('lg4 * 5')).to.equal(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work for wrapped functions', function () {
|
it('should work for wrapped functions', function () {
|
||||||
_expect.expect(_M2['default'].solve('(lg4)*2')).to.equal(4);
|
(0, _chai.expect)(_indexJs2['default'].solve('(lg4)*2')).to.equal(4);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Constats', function () {
|
describe('Constats', function () {
|
||||||
it('should work for constant values', function () {
|
it('should work for constant values', function () {
|
||||||
_expect.expect(_M2['default'].solve('sin(PI/2)')).to.equal(1);
|
(0, _chai.expect)(_indexJs2['default'].solve('sin(PI/2)')).to.equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work for functions as constants - retry on fail', function () {
|
it('should work for functions as constants - retry on fail', function () {
|
||||||
_expect.expect(_M2['default'].solve('RAND')).to.not.equal(_M2['default'].solve('RAND'));
|
(0, _chai.expect)(_indexJs2['default'].solve('RAND')).to.not.equal(_indexJs2['default'].solve('RAND'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Sigma', function () {
|
describe('Sigma', function () {
|
||||||
it('should work with simple expressions', function () {
|
it('should work with simple expressions', function () {
|
||||||
_expect.expect(_M2['default'].solve('sigma(0, 5, @)')).to.equal(15);
|
(0, _chai.expect)(_indexJs2['default'].solve('sigma(0, 5, @)')).to.equal(15);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work with more complex expressions', function () {
|
it('should work with more complex expressions', function () {
|
||||||
_expect.expect(_M2['default'].solve('sigma(0, 2, 2@+5)')).to.equal(21);
|
(0, _chai.expect)(_indexJs2['default'].solve('sigma(0, 2, 2@+5)')).to.equal(21);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work without an iterator sign', function () {
|
it('should work without an iterator sign', function () {
|
||||||
_expect.expect(_M2['default'].solve('sigma(0, 2, 5*2)')).to.equal(30);
|
(0, _chai.expect)(_indexJs2['default'].solve('sigma(0, 2, 5*2)')).to.equal(30);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work with negative start / end points', function () {
|
it('should work with negative start / end points', function () {
|
||||||
_expect.expect(_M2['default'].solve('sigma(-5, -2, @)')).to.equal(-14);
|
(0, _chai.expect)(_indexJs2['default'].solve('sigma(-5, -2, @)')).to.equal(-14);
|
||||||
});
|
});
|
||||||
});
|
});
|
2581
equation.js
2581
equation.js
File diff suppressed because it is too large
Load Diff
7
equation.min.js
vendored
7
equation.min.js
vendored
File diff suppressed because one or more lines are too long
6544
package-lock.json
generated
Normal file
6544
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,13 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "equations",
|
"name": "equations",
|
||||||
"version": "1.3.6",
|
"version": "1.3.7",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"directories": {
|
"directories": {
|
||||||
"test": "dist/tests"
|
"test": "dist/tests"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "grunt test"
|
"test": "grunt test",
|
||||||
|
"build": "grunt build"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Math",
|
"Math",
|
||||||
|
Loading…
Reference in New Issue
Block a user