/* * test/20_nj-st-75-2017.js - dmul, drhtz, drhfz tests using NJ ST-75 for 2017 * * @licstart The following is the entire license notice for the * JavaScript code in this file. * * Copyright (C) 2017 Libiquity LLC * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * As additional permission under GNU GPL version 3 section 7, you * may distribute non-source (e.g. minimized or compacted) forms of * this program without the copy of the GNU GPL normally required by * section 4, provided you include this license notice and a URL * through which recipients can access the Corresponding Source. * * @licend The above is the entire license notice * for the JavaScript code in this file. */ var assert = require("assert"); require("../lib/decmath.js"); describe("dmul(), drhtz(), and drhfz()", function() { /* * There are 1000 test amounts between 0.01 and 10.00. Six require * tie-breaking when rounding the calculated tax, but NJ's ST-75 appears * to use different tie-breaking rules for different amounts: * * Rate Amt Tax ST-75 Rule * ---------------------------------------- * 0.06875 * 0.80 = 0.055 0.06 Half up * 2.40 0.165 0.17 Half up * 4.00 0.275 0.27 Half down * 5.60 0.385 0.38 Half down * 7.20 0.495 0.49 Half down * 8.80 0.605 0.60 Half down * * So in the below two-dimensional array, we test both rounding * functions for all but these six anomalous amounts. This means we are * running 1000 * 2 - 6 tests. */ var tests = [ /*From To Tax Rounding fns*/ [0.01, 0.07, .00, drhtz, drhfz], [0.08, 0.21, .01, drhtz, drhfz], [0.22, 0.36, .02, drhtz, drhfz], [0.37, 0.50, .03, drhtz, drhfz], [0.51, 0.65, .04, drhtz, drhfz], [0.66, 0.79, .05, drhtz, drhfz], [0.80, 0.80, .06, drhfz], [0.81, 0.94, .06, drhtz, drhfz], [0.95, 1.09, .07, drhtz, drhfz], [1.10, 1.23, .08, drhtz, drhfz], [1.24, 1.38, .09, drhtz, drhfz], [1.39, 1.52, .10, drhtz, drhfz], [1.53, 1.67, .11, drhtz, drhfz], [1.68, 1.81, .12, drhtz, drhfz], [1.82, 1.96, .13, drhtz, drhfz], [1.97, 2.10, .14, drhtz, drhfz], [2.11, 2.25, .15, drhtz, drhfz], [2.26, 2.39, .16, drhtz, drhfz], [2.40, 2.40, .17, drhfz], [2.41, 2.54, .17, drhtz, drhfz], [2.55, 2.69, .18, drhtz, drhfz], [2.70, 2.83, .19, drhtz, drhfz], [2.84, 2.98, .20, drhtz, drhfz], [2.99, 3.12, .21, drhtz, drhfz], [3.13, 3.27, .22, drhtz, drhfz], [3.28, 3.41, .23, drhtz, drhfz], [3.42, 3.56, .24, drhtz, drhfz], [3.57, 3.70, .25, drhtz, drhfz], [3.71, 3.85, .26, drhtz, drhfz], [3.86, 3.99, .27, drhtz, drhfz], [4.00, 4.00, .27, drhtz ], [4.01, 4.14, .28, drhtz, drhfz], [4.15, 4.29, .29, drhtz, drhfz], [4.30, 4.43, .30, drhtz, drhfz], [4.44, 4.58, .31, drhtz, drhfz], [4.59, 4.72, .32, drhtz, drhfz], [4.73, 4.87, .33, drhtz, drhfz], [4.88, 5.01, .34, drhtz, drhfz], [5.02, 5.16, .35, drhtz, drhfz], [5.17, 5.30, .36, drhtz, drhfz], [5.31, 5.45, .37, drhtz, drhfz], [5.46, 5.59, .38, drhtz, drhfz], [5.60, 5.60, .38, drhtz ], [5.61, 5.74, .39, drhtz, drhfz], [5.75, 5.89, .40, drhtz, drhfz], [5.90, 6.03, .41, drhtz, drhfz], [6.04, 6.18, .42, drhtz, drhfz], [6.19, 6.32, .43, drhtz, drhfz], [6.33, 6.47, .44, drhtz, drhfz], [6.48, 6.61, .45, drhtz, drhfz], [6.62, 6.76, .46, drhtz, drhfz], [6.77, 6.90, .47, drhtz, drhfz], [6.91, 7.05, .48, drhtz, drhfz], [7.06, 7.19, .49, drhtz, drhfz], [7.20, 7.20, .49, drhtz ], [7.21, 7.34, .50, drhtz, drhfz], [7.35, 7.49, .51, drhtz, drhfz], [7.50, 7.63, .52, drhtz, drhfz], [7.64, 7.78, .53, drhtz, drhfz], [7.79, 7.92, .54, drhtz, drhfz], [7.93, 8.07, .55, drhtz, drhfz], [8.08, 8.21, .56, drhtz, drhfz], [8.22, 8.36, .57, drhtz, drhfz], [8.37, 8.50, .58, drhtz, drhfz], [8.51, 8.65, .59, drhtz, drhfz], [8.66, 8.79, .60, drhtz, drhfz], [8.80, 8.80, .60, drhtz ], [8.81, 8.94, .61, drhtz, drhfz], [8.95, 9.09, .62, drhtz, drhfz], [9.10, 9.23, .63, drhtz, drhfz], [9.24, 9.38, .64, drhtz, drhfz], [9.39, 9.52, .65, drhtz, drhfz], [9.53, 9.67, .66, drhtz, drhfz], [9.68, 9.81, .67, drhtz, drhfz], [9.82, 9.96, .68, drhtz, drhfz], [9.97, 10.00, .69, drhtz, drhfz], ]; tests.forEach(function(test) { for (var i = test[0]; i <= test[1]; i = dadd(i, "0.01")) { test.slice(3).forEach(function(f) { var rule; switch (f) { case drhtz: rule = "toward zero"; break; case drhfz: rule = "away from zero"; break; } var t = f(dmul(i, "0.06875"), 2); it("correctly multiply " + i + " by 0.06875 and round " + rule + " to " + test[2], function() { assert.equal(t, test[2]); }); }); } }); });