]>
git.scottworley.com Git - inverse-tax/blob - tax.test.js
192eac0cbf9c4edf142fc4acc2b99c65fd2feb31
3 var assert
= require('assert');
5 function test(description
, f
) {
9 function near(a
, b
, epsilon
= 1e-6) {
10 return Math
.abs(a
- b
) < epsilon
;
13 test("parse tax table", () => {
14 const parsed
= parse_tax_table(' 1 2\n10 4\n');
15 assert
.strictEqual(parsed
.length
, 2);
16 assert
.deepStrictEqual(parsed
[0], [1, 10, .02]);
17 assert
.deepStrictEqual(parsed
[1], [10, Infinity
, .04]);
21 assert
.strictEqual(sum([]), 0);
22 assert
.strictEqual(sum([7]), 7);
23 assert
.strictEqual(sum([100, 1, 10]), 111);
27 assert
.strictEqual(tax([[10, 100, .01], [100, Infinity
, .1]], 150), 5.9);
28 assert
.ok(near(tax([[10, 100, .01], [100, Infinity
, .1]], 150), 5.9));