Functional Weave
Code in TypeScript

finance.depreciation-reducing-balance@1.0.0

vectors.json

7,096 bytes · view raw

[
  {"name": "25% over four years, the final year writing off down to the residual value", "args": [{"minor": 1000000, "currency": "GBP"}, {"minor": 100000, "currency": "GBP"}, 2500, 4], "expect": [{"year": 1, "openingValue": {"minor": 1000000, "currency": "GBP"}, "charge": {"minor": 250000, "currency": "GBP"}, "closingValue": {"minor": 750000, "currency": "GBP"}}, {"year": 2, "openingValue": {"minor": 750000, "currency": "GBP"}, "charge": {"minor": 187500, "currency": "GBP"}, "closingValue": {"minor": 562500, "currency": "GBP"}}, {"year": 3, "openingValue": {"minor": 562500, "currency": "GBP"}, "charge": {"minor": 140625, "currency": "GBP"}, "closingValue": {"minor": 421875, "currency": "GBP"}}, {"year": 4, "openingValue": {"minor": 421875, "currency": "GBP"}, "charge": {"minor": 321875, "currency": "GBP"}, "closingValue": {"minor": 100000, "currency": "GBP"}}]},
  {"name": "each year's charge is rounded half-up once, on that year's opening value", "args": [{"minor": 99999, "currency": "GBP"}, {"minor": 0, "currency": "GBP"}, 3000, 3], "expect": [{"year": 1, "openingValue": {"minor": 99999, "currency": "GBP"}, "charge": {"minor": 30000, "currency": "GBP"}, "closingValue": {"minor": 69999, "currency": "GBP"}}, {"year": 2, "openingValue": {"minor": 69999, "currency": "GBP"}, "charge": {"minor": 21000, "currency": "GBP"}, "closingValue": {"minor": 48999, "currency": "GBP"}}, {"year": 3, "openingValue": {"minor": 48999, "currency": "GBP"}, "charge": {"minor": 48999, "currency": "GBP"}, "closingValue": {"minor": 0, "currency": "GBP"}}]},
  {"name": "an exact half penny rounds up", "args": [{"minor": 10, "currency": "GBP"}, {"minor": 0, "currency": "GBP"}, 2500, 2], "expect": [{"year": 1, "openingValue": {"minor": 10, "currency": "GBP"}, "charge": {"minor": 3, "currency": "GBP"}, "closingValue": {"minor": 7, "currency": "GBP"}}, {"year": 2, "openingValue": {"minor": 7, "currency": "GBP"}, "charge": {"minor": 7, "currency": "GBP"}, "closingValue": {"minor": 0, "currency": "GBP"}}]},
  {"name": "a high rate reaching the residual value early is capped there, and later years charge nothing", "args": [{"minor": 100000, "currency": "GBP"}, {"minor": 60000, "currency": "GBP"}, 5000, 3], "expect": [{"year": 1, "openingValue": {"minor": 100000, "currency": "GBP"}, "charge": {"minor": 40000, "currency": "GBP"}, "closingValue": {"minor": 60000, "currency": "GBP"}}, {"year": 2, "openingValue": {"minor": 60000, "currency": "GBP"}, "charge": {"minor": 0, "currency": "GBP"}, "closingValue": {"minor": 60000, "currency": "GBP"}}, {"year": 3, "openingValue": {"minor": 60000, "currency": "GBP"}, "charge": {"minor": 0, "currency": "GBP"}, "closingValue": {"minor": 60000, "currency": "GBP"}}]},
  {"name": "a 100% rate writes down to the residual value in the first year", "args": [{"minor": 10000, "currency": "GBP"}, {"minor": 1000, "currency": "GBP"}, 10000, 2], "expect": [{"year": 1, "openingValue": {"minor": 10000, "currency": "GBP"}, "charge": {"minor": 9000, "currency": "GBP"}, "closingValue": {"minor": 1000, "currency": "GBP"}}, {"year": 2, "openingValue": {"minor": 1000, "currency": "GBP"}, "charge": {"minor": 0, "currency": "GBP"}, "closingValue": {"minor": 1000, "currency": "GBP"}}]},
  {"name": "a one-year life writes off everything but the residual value", "args": [{"minor": 50000, "currency": "GBP"}, {"minor": 5000, "currency": "GBP"}, 2000, 1], "expect": [{"year": 1, "openingValue": {"minor": 50000, "currency": "GBP"}, "charge": {"minor": 45000, "currency": "GBP"}, "closingValue": {"minor": 5000, "currency": "GBP"}}]},
  {"name": "a zero rate leaves the whole write-off to the final year", "args": [{"minor": 30000, "currency": "GBP"}, {"minor": 0, "currency": "GBP"}, 0, 2], "expect": [{"year": 1, "openingValue": {"minor": 30000, "currency": "GBP"}, "charge": {"minor": 0, "currency": "GBP"}, "closingValue": {"minor": 30000, "currency": "GBP"}}, {"year": 2, "openingValue": {"minor": 30000, "currency": "GBP"}, "charge": {"minor": 30000, "currency": "GBP"}, "closingValue": {"minor": 0, "currency": "GBP"}}]},
  {"name": "a zero-cost asset has a schedule of zeros", "args": [{"minor": 0, "currency": "GBP"}, {"minor": 0, "currency": "GBP"}, 2500, 2], "expect": [{"year": 1, "openingValue": {"minor": 0, "currency": "GBP"}, "charge": {"minor": 0, "currency": "GBP"}, "closingValue": {"minor": 0, "currency": "GBP"}}, {"year": 2, "openingValue": {"minor": 0, "currency": "GBP"}, "charge": {"minor": 0, "currency": "GBP"}, "closingValue": {"minor": 0, "currency": "GBP"}}]},
  {"name": "residual value equal to cost: nothing to depreciate", "args": [{"minor": 5000, "currency": "GBP"}, {"minor": 5000, "currency": "GBP"}, 2500, 3], "expect": [{"year": 1, "openingValue": {"minor": 5000, "currency": "GBP"}, "charge": {"minor": 0, "currency": "GBP"}, "closingValue": {"minor": 5000, "currency": "GBP"}}, {"year": 2, "openingValue": {"minor": 5000, "currency": "GBP"}, "charge": {"minor": 0, "currency": "GBP"}, "closingValue": {"minor": 5000, "currency": "GBP"}}, {"year": 3, "openingValue": {"minor": 5000, "currency": "GBP"}, "charge": {"minor": 0, "currency": "GBP"}, "closingValue": {"minor": 5000, "currency": "GBP"}}]},
  {"name": "yen: whole units only", "args": [{"minor": 1000000, "currency": "JPY"}, {"minor": 0, "currency": "JPY"}, 3333, 3], "expect": [{"year": 1, "openingValue": {"minor": 1000000, "currency": "JPY"}, "charge": {"minor": 333300, "currency": "JPY"}, "closingValue": {"minor": 666700, "currency": "JPY"}}, {"year": 2, "openingValue": {"minor": 666700, "currency": "JPY"}, "charge": {"minor": 222211, "currency": "JPY"}, "closingValue": {"minor": 444489, "currency": "JPY"}}, {"year": 3, "openingValue": {"minor": 444489, "currency": "JPY"}, "charge": {"minor": 444489, "currency": "JPY"}, "closingValue": {"minor": 0, "currency": "JPY"}}]},
  {"name": "zero years is refused", "args": [{"minor": 1000, "currency": "GBP"}, {"minor": 0, "currency": "GBP"}, 2500, 0], "expectError": "years must be at least 1"},
  {"name": "a rate over 100% is refused", "args": [{"minor": 1000, "currency": "GBP"}, {"minor": 0, "currency": "GBP"}, 10001, 3], "expectError": "rate must be 0 to 10000 basis points"},
  {"name": "a negative rate is refused", "args": [{"minor": 1000, "currency": "GBP"}, {"minor": 0, "currency": "GBP"}, -1, 3], "expectError": "rate must be 0 to 10000 basis points"},
  {"name": "a negative cost is refused", "args": [{"minor": -1000, "currency": "GBP"}, {"minor": 0, "currency": "GBP"}, 2500, 3], "expectError": "cost must not be negative"},
  {"name": "a negative residual value is refused", "args": [{"minor": 1000, "currency": "GBP"}, {"minor": -1, "currency": "GBP"}, 2500, 3], "expectError": "residual value must not be negative"},
  {"name": "a residual value above cost is refused", "args": [{"minor": 1000, "currency": "GBP"}, {"minor": 1001, "currency": "GBP"}, 2500, 3], "expectError": "residual value must not exceed cost"},
  {"name": "mixed currencies are refused", "args": [{"minor": 1000, "currency": "GBP"}, {"minor": 0, "currency": "EUR"}, 2500, 3], "expectError": "currency mismatch"}
]