Equation.js/dist/tests/equation.js

47 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2015-04-20 09:28:11 +00:00
'use strict';
2020-06-09 13:58:42 +00:00
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
2015-04-20 09:28:11 +00:00
2020-06-09 13:58:42 +00:00
var _chai = require('chai');
2015-04-20 09:28:11 +00:00
2020-06-09 13:58:42 +00:00
var _indexJs = require('../index.js');
2015-04-20 09:28:11 +00:00
2020-06-09 13:58:42 +00:00
var _indexJs2 = _interopRequireDefault(_indexJs);
2015-04-20 09:28:11 +00:00
describe('Equations', function () {
it('should work with one variable', function () {
2020-06-09 13:58:42 +00:00
var equation = _indexJs2['default'].equation('x+2');
2015-04-20 09:28:11 +00:00
2020-06-09 13:58:42 +00:00
(0, _chai.expect)(equation(2)).to.equal(4);
2015-07-07 11:20:05 +00:00
2015-08-25 21:51:31 +00:00
// Issue #10
2020-06-09 13:58:42 +00:00
var subtraction = _indexJs2['default'].equation('x - 3');
(0, _chai.expect)(subtraction(10)).to.equal(7);
2015-04-20 09:28:11 +00:00
});
it('should work with multiple variables', function () {
2020-06-09 13:58:42 +00:00
var equation = _indexJs2['default'].equation('x+y');
(0, _chai.expect)(equation(2, 4)).to.equal(6);
2015-04-20 09:28:11 +00:00
});
it('should work with multiple instances of the same variable', function () {
2020-06-09 13:58:42 +00:00
var equation = _indexJs2['default'].equation('x*x');
(0, _chai.expect)(equation(4)).to.equal(16);
2015-04-20 09:28:11 +00:00
});
it('should only accept lowercase letters', function () {
2020-06-09 13:58:42 +00:00
var equation = _indexJs2['default'].equation('X+2');
(0, _chai.expect)(equation).to['throw']();
2015-04-20 09:28:11 +00:00
});
it('should work with NumVariable expressions like 2x', function () {
2020-06-09 13:58:42 +00:00
var equation = _indexJs2['default'].equation('2x + 6y');
(0, _chai.expect)(equation(4, 3)).to.equal(8 + 18);
});
2015-04-20 09:28:11 +00:00
it('Test case', function () {
2020-06-09 13:58:42 +00:00
var equation = _indexJs2['default'].equation('2+x*(y+4)+z^2');
(0, _chai.expect)(equation(2, 4, 3)).to.equal(27);
2015-04-20 09:28:11 +00:00
});
2020-06-09 13:58:42 +00:00
});