]> git.scottworley.com Git - inverse-tax/blob - tax.test.js
192eac0cbf9c4edf142fc4acc2b99c65fd2feb31
[inverse-tax] / tax.test.js
1 "use strict";
2
3 var assert = require('assert');
4
5 function test(description, f) {
6 f();
7 }
8
9 function near(a, b, epsilon = 1e-6) {
10 return Math.abs(a - b) < epsilon;
11 }
12
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]);
18 });
19
20 test("sum", () => {
21 assert.strictEqual(sum([]), 0);
22 assert.strictEqual(sum([7]), 7);
23 assert.strictEqual(sum([100, 1, 10]), 111);
24 });
25
26 test("tax", () => {
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));
29 });