Functional Weave
Code in Rust

fleet.vehicle-depreciation@1.0.0

vectors.json

4,979 bytes · view raw

[
  {"name": "three years and 30,000 miles: 0.8 x 0.85 x 0.88 x 0.97^3 of 20,000.00", "args": [{"minor": 2000000, "currency": "GBP"}, 36, 30000, [8000, 8500, 8800], 9700, "half-up"], "expect": {"value": {"minor": 1092287, "currency": "GBP"}, "depreciation": {"minor": 907713, "currency": "GBP"}, "retainedBasisPoints": 5461}},
  {"name": "the same, rounded up", "args": [{"minor": 2000000, "currency": "GBP"}, 36, 30000, [8000, 8500, 8800], 9700, "up"], "expect": {"value": {"minor": 1092288, "currency": "GBP"}, "depreciation": {"minor": 907712, "currency": "GBP"}, "retainedBasisPoints": 5461}},
  {"name": "brand new with no miles keeps its whole value", "args": [{"minor": 2000000, "currency": "GBP"}, 0, 0, [8000, 8500], 9700, "half-up"], "expect": {"value": {"minor": 2000000, "currency": "GBP"}, "depreciation": {"minor": 0, "currency": "GBP"}, "retainedBasisPoints": 10000}},
  {"name": "six months into a year that keeps 80% keeps 90%", "args": [{"minor": 1000000, "currency": "GBP"}, 6, 0, [8000], 10000, "half-up"], "expect": {"value": {"minor": 900000, "currency": "GBP"}, "depreciation": {"minor": 100000, "currency": "GBP"}, "retainedBasisPoints": 9000}},
  {"name": "past the end of the curve the last year repeats: 0.8 x 0.85^4", "args": [{"minor": 1500000, "currency": "GBP"}, 60, 0, [8000, 8500], 10000, "half-up"], "expect": {"value": {"minor": 626408, "currency": "GBP"}, "depreciation": {"minor": 873592, "currency": "GBP"}, "retainedBasisPoints": 4176}},
  {"name": "the same 6264.075 rounded down", "args": [{"minor": 1500000, "currency": "GBP"}, 60, 0, [8000, 8500], 10000, "down"], "expect": {"value": {"minor": 626407, "currency": "GBP"}, "depreciation": {"minor": 873593, "currency": "GBP"}, "retainedBasisPoints": 4176}},
  {"name": "15,000 miles is one whole band and half of the next: 0.9 x 0.95", "args": [{"minor": 1000000, "currency": "GBP"}, 0, 15000, [8000], 9000, "half-up"], "expect": {"value": {"minor": 855000, "currency": "GBP"}, "depreciation": {"minor": 145000, "currency": "GBP"}, "retainedBasisPoints": 8550}},
  {"name": "18 months and 25,000 miles: 0.8 x 0.95 x 0.95^2 x 0.975, with a retained share of 6687.525 bp rounding up", "args": [{"minor": 2500000, "currency": "GBP"}, 18, 25000, [8000, 9000], 9500, "half-up"], "expect": {"value": {"minor": 1671881, "currency": "GBP"}, "depreciation": {"minor": 828119, "currency": "GBP"}, "retainedBasisPoints": 6688}},
  {"name": "a vehicle written off to nothing", "args": [{"minor": 1200000, "currency": "GBP"}, 12, 0, [0], 9700, "half-up"], "expect": {"value": {"minor": 0, "currency": "GBP"}, "depreciation": {"minor": 1200000, "currency": "GBP"}, "retainedBasisPoints": 0}},
  {"name": "euro cents, ten years on a flat 85% curve", "args": [{"minor": 3000000, "currency": "EUR"}, 120, 0, [8500], 10000, "half-up"], "expect": {"value": {"minor": 590623, "currency": "EUR"}, "depreciation": {"minor": 2409377, "currency": "EUR"}, "retainedBasisPoints": 1969}},
  {"name": "a long-lived van: 0.9^50 x 0.99^200 of 50,000.00 is 34.525 and still divides exactly", "args": [{"minor": 5000000, "currency": "GBP"}, 600, 2000000, [9000], 9900, "half-up"], "expect": {"value": {"minor": 3453, "currency": "GBP"}, "depreciation": {"minor": 4996547, "currency": "GBP"}, "retainedBasisPoints": 7}},
  {"name": "an empty curve is an error", "args": [{"minor": 1000000, "currency": "GBP"}, 12, 0, [], 9700, "half-up"], "expectError": "retainedPerYearBasisPoints must have at least one year"},
  {"name": "a retention above 100% is an error", "args": [{"minor": 1000000, "currency": "GBP"}, 12, 0, [10001], 9700, "half-up"], "expectError": "a retention rate must be a whole number from 0 to 10000"},
  {"name": "a negative mileage retention is an error", "args": [{"minor": 1000000, "currency": "GBP"}, 12, 0, [8000], -1, "half-up"], "expectError": "a retention rate must be a whole number from 0 to 10000"},
  {"name": "a negative age is an error", "args": [{"minor": 1000000, "currency": "GBP"}, -1, 0, [8000], 9700, "half-up"], "expectError": "ageMonths must be a whole number from 0 to 600"},
  {"name": "an age over 50 years is an error", "args": [{"minor": 1000000, "currency": "GBP"}, 601, 0, [8000], 9700, "half-up"], "expectError": "ageMonths must be a whole number from 0 to 600"},
  {"name": "a fractional age is an error", "args": [{"minor": 1000000, "currency": "GBP"}, 6.5, 0, [8000], 9700, "half-up"], "expectError": "ageMonths must be a whole number"},
  {"name": "a negative mileage is an error", "args": [{"minor": 1000000, "currency": "GBP"}, 12, -5, [8000], 9700, "half-up"], "expectError": "mileage must be a whole number from 0 to 2000000"},
  {"name": "a negative cost is an error", "args": [{"minor": -1, "currency": "GBP"}, 12, 0, [8000], 9700, "half-up"], "expectError": "cost must not be negative"},
  {"name": "an unknown rounding mode is an error", "args": [{"minor": 1000000, "currency": "GBP"}, 12, 0, [8000], 9700, "nearest"], "expectError": "unknown rounding mode"}
]