WIP: math parser
This commit is contained in:
24
2kyu/evaluate-mathematical-expression/tests.ts
Normal file
24
2kyu/evaluate-mathematical-expression/tests.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { calc } from './solution';
|
||||
import { expect } from "chai";
|
||||
|
||||
var tests: [string, number][] = [
|
||||
['1+1', 2],
|
||||
['1 - 1', 0],
|
||||
['1* 1', 1],
|
||||
['1 /1', 1],
|
||||
['-123', -123],
|
||||
['123', 123],
|
||||
['2 /2+3 * 4.75- -6', 21.25],
|
||||
['12* 123', 1476],
|
||||
['2 / (2 + 3) * 4.33 - -6', 7.732],
|
||||
];
|
||||
|
||||
describe("calc", function() {
|
||||
it("should evaluate correctly", () => {
|
||||
tests.forEach(function(m) {
|
||||
var x = calc(m[0]);
|
||||
var y = m[1];
|
||||
expect(x).to.equal(y, 'Expected: "' + m[0] + '" to be ' + y + ' but got ' + x);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user