2015-04-20 09:28:11 +00:00
|
|
|
import {expect} from 'chai';
|
|
|
|
import M from '../index.js';
|
|
|
|
|
|
|
|
describe('Equations', () => {
|
|
|
|
it('should work with one variable', () => {
|
|
|
|
let equation = M.equation('x+2');
|
|
|
|
|
|
|
|
expect(equation(2)).to.equal(4);
|
2015-07-07 11:20:05 +00:00
|
|
|
|
|
|
|
// Issue #10
|
|
|
|
let subtraction = M.equation('x - 3');
|
|
|
|
expect(subtraction(10)).to.equal(7);
|
2015-04-20 09:28:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should work with multiple variables', () => {
|
|
|
|
let equation = M.equation('x+y');
|
|
|
|
expect(equation(2, 4)).to.equal(6);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should work with multiple instances of the same variable', () => {
|
|
|
|
let equation = M.equation('x*x');
|
|
|
|
expect(equation(4)).to.equal(16);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should only accept lowercase letters', () => {
|
|
|
|
let equation = M.equation('X+2');
|
|
|
|
expect(equation).to.throw();
|
|
|
|
});
|
|
|
|
|
2015-06-18 11:44:13 +00:00
|
|
|
it('should work with NumVariable expressions like 2x', () => {
|
|
|
|
let equation = M.equation('2x + 6y');
|
|
|
|
expect(equation(4, 3)).to.equal(8 + 18);
|
|
|
|
});
|
|
|
|
|
2015-04-20 09:28:11 +00:00
|
|
|
it('Test case', () => {
|
|
|
|
let equation = M.equation('2+x*(y+4)+z^2');
|
|
|
|
expect(equation(2, 4, 3)).to.equal(27);
|
|
|
|
});
|
|
|
|
});
|