Skip to content

Commit

Permalink
Updated test data.
Browse files Browse the repository at this point in the history
  • Loading branch information
demmings committed Dec 9, 2024
1 parent 73d5a72 commit 8a2be98
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 70 deletions.
71 changes: 36 additions & 35 deletions dist/CanadianTaxes.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@

const TestCantaxData = [
// Age,Net Income,"Expected Gross Taxable Income (2024). Age=59, Inflation=0",Dividends,Capital Gains,OAS,Calculated Gross Taxable from Net,Calculated Net from Gross,Calculated Gross Difference from Expected,Calculated Net Difference from Expected
[59, 180000.00, 300244.00, 5000.00, , , 300243.70, 180000.35, -0.30, 0.35],
[60, 57000.00, 70272.00, 0.00, , , 70271.74, 57000.22, -0.26, 0.22],
[61, 58000.00, 72833.00, 10200.00, , , 72833.04, 58000.14, 0.04, 0.14],
[62, 59000.00, 74277.00, 10450.00, , , 74277.23, 59000.02, 0.23, 0.02],
[63, 60000.00, 75712.00, 10600.00, , , 75712.35, 59999.96, 0.35, -0.04],
[64, 61000.00, 77191.00, 10800.00, , , 77190.78, 61000.20, -0.22, 0.20],
[65, 62000.00, 78368.00, 11000.00, , , 78368.48, 61999.84, 0.48, -0.16],
[66, 70000.00, 90663.00, 12000.00, , , 90662.85, 70000.21, -0.15, 0.21],
[67, 80000.00, 108254.00, 12800.00, , , 108254.04, 80000.05, 0.04, 0.05],
[68, 90000.00, 126016.00, 13000.00, , , 126014.68, 90000.88, -1.32, 0.88],
[69, 90000.00, 120185.00, 0.00, , , 120185.01, 90000.23, 0.01, 0.23],
[70, 120000.00, 173897.00, 0.00, , , 173896.61, 120000.33, -0.39, 0.33],
[70, 120000.00, 178565.00, 0.00, 10000.00, , 178565.03, 120000.09, 0.03, 0.09],
[70, 120000.00, 224492.00, 0.00, 100000.00, , 224491.27, 120000.47, -0.73, 0.47],
[70, 120000.00, 502868.00, 0.00, 500000.00, , 502868.57, 119999.80, 0.57, -0.20],
[70, 120000.00, 511335.00, 10000.00, 500000.00, , 511334.99, 120000.10, -0.01, 0.10],
[70, 120000.00, 319350.00, 10000.00, 249999.00, , 319350.03, 120000.08, 0.03, 0.08],
[70, 50000.00, 71924.00, 50000.00, 0.00, , 71923.93, 50000.17, -0.07, 0.17],
[70, 10000.00, 10796.00, 50000.00, 0.00, , 10795.85, 10000.32, -0.15, 0.32],
[70, 0.00, 600.00, 50000.00, 0.00, , 600.01, 0.00, 0.01, 0.00],
[70, 0.00, 621.00, 0.00, 50000.00, , 883.58, -209.88, 262.58, -209.88],
[70, 0.00, 621.00, 0.00, 49999.00, , 883.46, -209.78, 262.46, -209.78],
[70, 0.00, 621.00, 0.00, 50001.00, , 883.71, -209.98, 262.71, -209.98],
[70, 180000.00, 320505.00, 5000.00, 0.00, 9416.00, 320505.23, 179999.72, 0.23, -0.28],
[70, 80000.00, 118561.00, 5000.00, 0.00, 9416.00, 118561.07, 80000.07, 0.07, 0.07],
[70, 50000.00, 64187.00, 5000.00, 0.00, 9416.00, 64187.34, 49999.90, 0.34, -0.10]
];
const TestCantaxData =
[
[59, 180000.00, 300244.00, 5000.00, 0.00, 0.00, 0.00, 300243.70, 180000.35, -0.30, 0.35],
[60, 57000.00, 70272.00, 0.00, 0.00, 0.00, 0.00, 70271.74, 57000.22, -0.26, 0.22],
[61, 58000.00, 72833.00, 10200.00, 0.00, 0.00, 0.00, 72833.04, 58000.14, 0.04, 0.14],
[62, 59000.00, 74277.00, 10450.00, 0.00, 0.00, 0.00, 74277.23, 59000.02, 0.23, 0.02],
[63, 60000.00, 75712.00, 10600.00, 0.00, 0.00, 0.00, 75712.35, 59999.96, 0.35, -0.04],
[64, 61000.00, 77191.00, 10800.00, 0.00, 0.00, 0.00, 77190.78, 61000.20, -0.22, 0.20],
[65, 62000.00, 78368.00, 11000.00, 0.00, 0.00, 0.00, 78368.48, 61999.84, 0.48, -0.16],
[66, 70000.00, 90663.00, 12000.00, 0.00, 0.00, 0.00, 90662.85, 70000.21, -0.15, 0.21],
[67, 80000.00, 108254.00, 12800.00, 0.00, 0.00, 0.00, 108254.04, 80000.05, 0.04, 0.05],
[68, 90000.00, 126016.00, 13000.00, 0.00, 0.00, 0.00, 126014.68, 90000.88, -1.32, 0.88],
[69, 90000.00, 120185.00, 0.00, 0.00, 0.00, 0.00, 120185.01, 90000.23, 0.01, 0.23],
[70, 120000.00, 173897.00, 0.00, 0.00, 0.00, 0.00, 173896.61, 120000.33, -0.39, 0.33],
[70, 120000.00, 178565.00, 0.00, 10000.00, 0.00, 0.00, 178565.03, 120000.09, 0.03, 0.09],
[70, 120000.00, 224492.00, 0.00, 100000.00, 0.00, 0.00, 224491.27, 120000.47, -0.73, 0.47],
[70, 120000.00, 502868.00, 0.00, 500000.00, 0.00, 0.00, 502868.57, 119999.80, 0.57, -0.20],
[70, 120000.00, 511335.00, 10000.00, 500000.00, 0.00, 0.00, 511334.99, 120000.10, -0.01, 0.10],
[70, 120000.00, 319350.00, 10000.00, 249999.00, 0.00, 0.00, 319350.03, 120000.08, 0.03, 0.08],
[70, 50000.00, 71924.00, 50000.00, 0.00, 0.00, 0.00, 71923.93, 50000.17, -0.07, 0.17],
[70, 10000.00, 10796.00, 50000.00, 0.00, 0.00, 0.00, 10795.85, 10000.32, -0.15, 0.32],
[70, 0.00, 600.00, 50000.00, 0.00, 0.00, 0.00, 600.01, 0.00, 0.01, 0.00],
[70, 0.00, 621.00, 0.00, 50000.00, 0.00, 0.00, 883.58, -209.88, 262.58, -209.88],
[70, 0.00, 621.00, 0.00, 49999.00, 0.00, 0.00, 883.46, -209.78, 262.46, -209.78],
[70, 0.00, 621.00, 0.00, 50001.00, 0.00, 0.00, 883.71, -209.98, 262.71, -209.98],
[70, 180000.00, 320505.00, 5000.00, 0.00, 9416.00, 0.00, 320505.23, 179999.72, 0.23, -0.28],
[70, 80000.00, 118561.00, 5000.00, 0.00, 9416.00, 0.00, 118561.07, 80000.07, 0.07, 0.07],
[70, 50000.00, 64187.00, 5000.00, 0.00, 9416.00, 0.00, 64187.34, 49999.90, 0.34, -0.10],
[70, 50000.00, 63613.00, 5000.00, 0.00, 9416.00, 2000.00, 63613.38, 49999.91, 0.38, -0.09]
];

/**
* Basic sanity check.
* @returns {any[]}
* @customfunction
*/
function TEST_CANTAX() {
const output = [["Age", "Net Income", "Dividends", "Eligible Capital Gains", "OAS", "Gross Income (calculated)", "Expected Gross", "Gross Diff. (calc-expected)", "Pass/Fail", "Net Income (calculated)", "Gross Diff. (calc-expected)", "Pass/Fail"]];
const output = [["Age", "Net Income", "Dividends", "Eligible Capital Gains", "OAS", "Pension Credit Eligible Income", "Gross Income (calculated)", "Expected Gross", "Gross Diff. (calc-expected)", "Pass/Fail", "Net Income (calculated)", "Gross Diff. (calc-expected)", "Pass/Fail"]];
for (const testItem of TestCantaxData) {
const grossIncome = GET_GROSS_INCOMES_V2(testItem[1], testItem[0], 59, 0, 2024, testItem[4], testItem[3], testItem[5], 0);
const netIncome = GET_NET_INCOMES_V2(testItem[2], testItem[0], 59, 0, 2024, testItem[4], testItem[3], testItem[5], 0);
const grossIncome = GET_GROSS_INCOMES_V2(testItem[1], testItem[0], 59, 0, 2024, testItem[4], testItem[3], testItem[5], testItem[6]);
const netIncome = GET_NET_INCOMES_V2(testItem[2], testItem[0], 59, 0, 2024, testItem[4], testItem[3], testItem[5], testItem[6]);

const grossDiff = Math.round(grossIncome[0][0]) - testItem[2];
const netDiff = Math.round(netIncome[0][0]) - testItem[1];
// @ts-ignore
output.push([testItem[0], testItem[1], testItem[3], testItem[4], testItem[5], Math.round(grossIncome[0][0]), testItem[2], grossDiff, Math.abs(grossDiff) <= 1.0 ? "Pass" : "** FAIL **", Math.round(netIncome[0][0]), netDiff, Math.abs(netDiff) <= 1.0 ? "Pass" : "** FAIL **"]);
output.push([testItem[0], testItem[1], testItem[3], testItem[4], testItem[5], testItem[6], Math.round(grossIncome[0][0]), testItem[2], grossDiff, Math.abs(grossDiff) <= 1.0 ? "Pass" : "** FAIL **", Math.round(netIncome[0][0]), netDiff, Math.abs(netDiff) <= 1.0 ? "Pass" : "** FAIL **"]);
}

return output;
Expand Down Expand Up @@ -100,7 +101,7 @@ class CanadianTaxRates {

class OntarioTaxRates {
constructor() {

this.taxYear = 2024;
this.provEligibleDividendTaxCreditRate = 0.10;
this.ontBasicPersonAmount = 12399.00;
Expand Down Expand Up @@ -510,7 +511,7 @@ class CanadianIncomeTax {
return;
}

this.fedTaxRates = new FederalTaxes(taxableYear, taxData.inflation);
this.fedTaxRates = new FederalTaxes(taxableYear, taxData.inflation);
this.provTaxRates = new OntarioTaxes(taxableYear, taxData.inflation);
}

Expand Down
71 changes: 36 additions & 35 deletions src/CanadianTaxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,52 @@ function getNet() {
// *** DEBUG END ***/

const TestCantaxData = [
// Age,Net Income,"Expected Gross Taxable Income (2024). Age=59, Inflation=0",Dividends,Capital Gains,OAS,Calculated Gross Taxable from Net,Calculated Net from Gross,Calculated Gross Difference from Expected,Calculated Net Difference from Expected
[59, 180000.00, 300244.00, 5000.00, , , 300243.70, 180000.35, -0.30, 0.35],
[60, 57000.00, 70272.00, 0.00, , , 70271.74, 57000.22, -0.26, 0.22],
[61, 58000.00, 72833.00, 10200.00, , , 72833.04, 58000.14, 0.04, 0.14],
[62, 59000.00, 74277.00, 10450.00, , , 74277.23, 59000.02, 0.23, 0.02],
[63, 60000.00, 75712.00, 10600.00, , , 75712.35, 59999.96, 0.35, -0.04],
[64, 61000.00, 77191.00, 10800.00, , , 77190.78, 61000.20, -0.22, 0.20],
[65, 62000.00, 78368.00, 11000.00, , , 78368.48, 61999.84, 0.48, -0.16],
[66, 70000.00, 90663.00, 12000.00, , , 90662.85, 70000.21, -0.15, 0.21],
[67, 80000.00, 108254.00, 12800.00, , , 108254.04, 80000.05, 0.04, 0.05],
[68, 90000.00, 126016.00, 13000.00, , , 126014.68, 90000.88, -1.32, 0.88],
[69, 90000.00, 120185.00, 0.00, , , 120185.01, 90000.23, 0.01, 0.23],
[70, 120000.00, 173897.00, 0.00, , , 173896.61, 120000.33, -0.39, 0.33],
[70, 120000.00, 178565.00, 0.00, 10000.00, , 178565.03, 120000.09, 0.03, 0.09],
[70, 120000.00, 224492.00, 0.00, 100000.00, , 224491.27, 120000.47, -0.73, 0.47],
[70, 120000.00, 502868.00, 0.00, 500000.00, , 502868.57, 119999.80, 0.57, -0.20],
[70, 120000.00, 511335.00, 10000.00, 500000.00, , 511334.99, 120000.10, -0.01, 0.10],
[70, 120000.00, 319350.00, 10000.00, 249999.00, , 319350.03, 120000.08, 0.03, 0.08],
[70, 50000.00, 71924.00, 50000.00, 0.00, , 71923.93, 50000.17, -0.07, 0.17],
[70, 10000.00, 10796.00, 50000.00, 0.00, , 10795.85, 10000.32, -0.15, 0.32],
[70, 0.00, 600.00, 50000.00, 0.00, , 600.01, 0.00, 0.01, 0.00],
[70, 0.00, 621.00, 0.00, 50000.00, , 883.58, -209.88, 262.58, -209.88],
[70, 0.00, 621.00, 0.00, 49999.00, , 883.46, -209.78, 262.46, -209.78],
[70, 0.00, 621.00, 0.00, 50001.00, , 883.71, -209.98, 262.71, -209.98],
[70, 180000.00, 320505.00, 5000.00, 0.00, 9416.00, 320505.23, 179999.72, 0.23, -0.28],
[70, 80000.00, 118561.00, 5000.00, 0.00, 9416.00, 118561.07, 80000.07, 0.07, 0.07],
[70, 50000.00, 64187.00, 5000.00, 0.00, 9416.00, 64187.34, 49999.90, 0.34, -0.10]
];
const TestCantaxData =
[
[59, 180000.00, 300244.00, 5000.00, 0.00, 0.00, 0.00, 300243.70, 180000.35, -0.30, 0.35],
[60, 57000.00, 70272.00, 0.00, 0.00, 0.00, 0.00, 70271.74, 57000.22, -0.26, 0.22],
[61, 58000.00, 72833.00, 10200.00, 0.00, 0.00, 0.00, 72833.04, 58000.14, 0.04, 0.14],
[62, 59000.00, 74277.00, 10450.00, 0.00, 0.00, 0.00, 74277.23, 59000.02, 0.23, 0.02],
[63, 60000.00, 75712.00, 10600.00, 0.00, 0.00, 0.00, 75712.35, 59999.96, 0.35, -0.04],
[64, 61000.00, 77191.00, 10800.00, 0.00, 0.00, 0.00, 77190.78, 61000.20, -0.22, 0.20],
[65, 62000.00, 78368.00, 11000.00, 0.00, 0.00, 0.00, 78368.48, 61999.84, 0.48, -0.16],
[66, 70000.00, 90663.00, 12000.00, 0.00, 0.00, 0.00, 90662.85, 70000.21, -0.15, 0.21],
[67, 80000.00, 108254.00, 12800.00, 0.00, 0.00, 0.00, 108254.04, 80000.05, 0.04, 0.05],
[68, 90000.00, 126016.00, 13000.00, 0.00, 0.00, 0.00, 126014.68, 90000.88, -1.32, 0.88],
[69, 90000.00, 120185.00, 0.00, 0.00, 0.00, 0.00, 120185.01, 90000.23, 0.01, 0.23],
[70, 120000.00, 173897.00, 0.00, 0.00, 0.00, 0.00, 173896.61, 120000.33, -0.39, 0.33],
[70, 120000.00, 178565.00, 0.00, 10000.00, 0.00, 0.00, 178565.03, 120000.09, 0.03, 0.09],
[70, 120000.00, 224492.00, 0.00, 100000.00, 0.00, 0.00, 224491.27, 120000.47, -0.73, 0.47],
[70, 120000.00, 502868.00, 0.00, 500000.00, 0.00, 0.00, 502868.57, 119999.80, 0.57, -0.20],
[70, 120000.00, 511335.00, 10000.00, 500000.00, 0.00, 0.00, 511334.99, 120000.10, -0.01, 0.10],
[70, 120000.00, 319350.00, 10000.00, 249999.00, 0.00, 0.00, 319350.03, 120000.08, 0.03, 0.08],
[70, 50000.00, 71924.00, 50000.00, 0.00, 0.00, 0.00, 71923.93, 50000.17, -0.07, 0.17],
[70, 10000.00, 10796.00, 50000.00, 0.00, 0.00, 0.00, 10795.85, 10000.32, -0.15, 0.32],
[70, 0.00, 600.00, 50000.00, 0.00, 0.00, 0.00, 600.01, 0.00, 0.01, 0.00],
[70, 0.00, 621.00, 0.00, 50000.00, 0.00, 0.00, 883.58, -209.88, 262.58, -209.88],
[70, 0.00, 621.00, 0.00, 49999.00, 0.00, 0.00, 883.46, -209.78, 262.46, -209.78],
[70, 0.00, 621.00, 0.00, 50001.00, 0.00, 0.00, 883.71, -209.98, 262.71, -209.98],
[70, 180000.00, 320505.00, 5000.00, 0.00, 9416.00, 0.00, 320505.23, 179999.72, 0.23, -0.28],
[70, 80000.00, 118561.00, 5000.00, 0.00, 9416.00, 0.00, 118561.07, 80000.07, 0.07, 0.07],
[70, 50000.00, 64187.00, 5000.00, 0.00, 9416.00, 0.00, 64187.34, 49999.90, 0.34, -0.10],
[70, 50000.00, 63613.00, 5000.00, 0.00, 9416.00, 2000.00, 63613.38, 49999.91, 0.38, -0.09]
];

/**
* Basic sanity check.
* @returns {any[]}
* @customfunction
*/
function TEST_CANTAX() {
const output = [["Age", "Net Income", "Dividends", "Eligible Capital Gains", "OAS", "Gross Income (calculated)", "Expected Gross", "Gross Diff. (calc-expected)", "Pass/Fail", "Net Income (calculated)", "Gross Diff. (calc-expected)", "Pass/Fail"]];
const output = [["Age", "Net Income", "Dividends", "Eligible Capital Gains", "OAS", "Pension Credit Eligible Income", "Gross Income (calculated)", "Expected Gross", "Gross Diff. (calc-expected)", "Pass/Fail", "Net Income (calculated)", "Gross Diff. (calc-expected)", "Pass/Fail"]];
for (const testItem of TestCantaxData) {
const grossIncome = GET_GROSS_INCOMES_V2(testItem[1], testItem[0], 59, 0, 2024, testItem[4], testItem[3], testItem[5], 0);
const netIncome = GET_NET_INCOMES_V2(testItem[2], testItem[0], 59, 0, 2024, testItem[4], testItem[3], testItem[5], 0);
const grossIncome = GET_GROSS_INCOMES_V2(testItem[1], testItem[0], 59, 0, 2024, testItem[4], testItem[3], testItem[5], testItem[6]);
const netIncome = GET_NET_INCOMES_V2(testItem[2], testItem[0], 59, 0, 2024, testItem[4], testItem[3], testItem[5], testItem[6]);

const grossDiff = Math.round(grossIncome[0][0]) - testItem[2];
const netDiff = Math.round(netIncome[0][0]) - testItem[1];
// @ts-ignore
output.push([testItem[0], testItem[1], testItem[3], testItem[4], testItem[5], Math.round(grossIncome[0][0]), testItem[2], grossDiff, Math.abs(grossDiff) <= 1.0 ? "Pass" : "** FAIL **", Math.round(netIncome[0][0]), netDiff, Math.abs(netDiff) <= 1.0 ? "Pass" : "** FAIL **"]);
output.push([testItem[0], testItem[1], testItem[3], testItem[4], testItem[5], testItem[6], Math.round(grossIncome[0][0]), testItem[2], grossDiff, Math.abs(grossDiff) <= 1.0 ? "Pass" : "** FAIL **", Math.round(netIncome[0][0]), netDiff, Math.abs(netDiff) <= 1.0 ? "Pass" : "** FAIL **"]);
}

return output;
Expand Down Expand Up @@ -119,7 +120,7 @@ class CanadianTaxRates {

class OntarioTaxRates {
constructor() {

this.taxYear = 2024;
this.provEligibleDividendTaxCreditRate = 0.10;
this.ontBasicPersonAmount = 12399.00;
Expand Down Expand Up @@ -529,7 +530,7 @@ class CanadianIncomeTax {
return;
}

this.fedTaxRates = new FederalTaxes(taxableYear, taxData.inflation);
this.fedTaxRates = new FederalTaxes(taxableYear, taxData.inflation);
this.provTaxRates = new OntarioTaxes(taxableYear, taxData.inflation);
}

Expand Down

0 comments on commit 8a2be98

Please sign in to comment.