Functional Weave
Code in Python

finance.aged-debt@1.0.0

vectors.json

7,733 bytes · view raw

[
  {"name": "a ledger across every bucket, each boundary on its edge, with a credit", "args": [[{"reference": "A", "dueDate": "2026-07-15", "outstanding": {"minor": 100000, "currency": "GBP"}}, {"reference": "B", "dueDate": "2026-06-30", "outstanding": {"minor": 5000, "currency": "GBP"}}, {"reference": "C", "dueDate": "2026-06-29", "outstanding": {"minor": 2000, "currency": "GBP"}}, {"reference": "D", "dueDate": "2026-05-31", "outstanding": {"minor": 3000, "currency": "GBP"}}, {"reference": "E", "dueDate": "2026-05-30", "outstanding": {"minor": 4000, "currency": "GBP"}}, {"reference": "F", "dueDate": "2026-04-01", "outstanding": {"minor": 7000, "currency": "GBP"}}, {"reference": "G", "dueDate": "2026-03-31", "outstanding": {"minor": 1100, "currency": "GBP"}}, {"reference": "H", "dueDate": "2026-05-15", "outstanding": {"minor": -500, "currency": "GBP"}}], "2026-06-30", [30, 60, 90], "GBP"], "expect": {"asAt": "2026-06-30", "buckets": [{"label": "current", "fromDays": null, "toDays": 0, "total": {"minor": 105000, "currency": "GBP"}, "references": ["A", "B"]}, {"label": "1-30", "fromDays": 1, "toDays": 30, "total": {"minor": 5000, "currency": "GBP"}, "references": ["C", "D"]}, {"label": "31-60", "fromDays": 31, "toDays": 60, "total": {"minor": 3500, "currency": "GBP"}, "references": ["E", "H"]}, {"label": "61-90", "fromDays": 61, "toDays": 90, "total": {"minor": 7000, "currency": "GBP"}, "references": ["F"]}, {"label": "90+", "fromDays": 91, "toDays": null, "total": {"minor": 1100, "currency": "GBP"}, "references": ["G"]}], "total": {"minor": 121600, "currency": "GBP"}}},
  {"name": "an empty ledger still has every bucket, in the given currency", "args": [[], "2026-06-30", [30, 60, 90], "EUR"], "expect": {"asAt": "2026-06-30", "buckets": [{"label": "current", "fromDays": null, "toDays": 0, "total": {"minor": 0, "currency": "EUR"}, "references": []}, {"label": "1-30", "fromDays": 1, "toDays": 30, "total": {"minor": 0, "currency": "EUR"}, "references": []}, {"label": "31-60", "fromDays": 31, "toDays": 60, "total": {"minor": 0, "currency": "EUR"}, "references": []}, {"label": "61-90", "fromDays": 61, "toDays": 90, "total": {"minor": 0, "currency": "EUR"}, "references": []}, {"label": "90+", "fromDays": 91, "toDays": null, "total": {"minor": 0, "currency": "EUR"}, "references": []}], "total": {"minor": 0, "currency": "EUR"}}},
  {"name": "leap year: due 31 December 2023 is 91 days overdue on 31 March 2024", "args": [[{"reference": "X", "dueDate": "2023-12-31", "outstanding": {"minor": 1000, "currency": "GBP"}}], "2024-03-31", [30, 60, 90], "GBP"], "expect": {"asAt": "2024-03-31", "buckets": [{"label": "current", "fromDays": null, "toDays": 0, "total": {"minor": 0, "currency": "GBP"}, "references": []}, {"label": "1-30", "fromDays": 1, "toDays": 30, "total": {"minor": 0, "currency": "GBP"}, "references": []}, {"label": "31-60", "fromDays": 31, "toDays": 60, "total": {"minor": 0, "currency": "GBP"}, "references": []}, {"label": "61-90", "fromDays": 61, "toDays": 90, "total": {"minor": 0, "currency": "GBP"}, "references": []}, {"label": "90+", "fromDays": 91, "toDays": null, "total": {"minor": 1000, "currency": "GBP"}, "references": ["X"]}], "total": {"minor": 1000, "currency": "GBP"}}},
  {"name": "the same invoice a non-leap year later is 90 days overdue, still 61-90", "args": [[{"reference": "X", "dueDate": "2025-12-31", "outstanding": {"minor": 1000, "currency": "GBP"}}], "2026-03-31", [30, 60, 90], "GBP"], "expect": {"asAt": "2026-03-31", "buckets": [{"label": "current", "fromDays": null, "toDays": 0, "total": {"minor": 0, "currency": "GBP"}, "references": []}, {"label": "1-30", "fromDays": 1, "toDays": 30, "total": {"minor": 0, "currency": "GBP"}, "references": []}, {"label": "31-60", "fromDays": 31, "toDays": 60, "total": {"minor": 0, "currency": "GBP"}, "references": []}, {"label": "61-90", "fromDays": 61, "toDays": 90, "total": {"minor": 1000, "currency": "GBP"}, "references": ["X"]}, {"label": "90+", "fromDays": 91, "toDays": null, "total": {"minor": 0, "currency": "GBP"}, "references": []}], "total": {"minor": 1000, "currency": "GBP"}}},
  {"name": "weekly buckets", "args": [[{"reference": "P", "dueDate": "2026-06-25", "outstanding": {"minor": 100, "currency": "GBP"}}, {"reference": "Q", "dueDate": "2026-06-22", "outstanding": {"minor": 200, "currency": "GBP"}}, {"reference": "R", "dueDate": "2026-06-16", "outstanding": {"minor": 300, "currency": "GBP"}}, {"reference": "S", "dueDate": "2026-06-15", "outstanding": {"minor": 400, "currency": "GBP"}}], "2026-06-30", [7, 14], "GBP"], "expect": {"asAt": "2026-06-30", "buckets": [{"label": "current", "fromDays": null, "toDays": 0, "total": {"minor": 0, "currency": "GBP"}, "references": []}, {"label": "1-7", "fromDays": 1, "toDays": 7, "total": {"minor": 100, "currency": "GBP"}, "references": ["P"]}, {"label": "8-14", "fromDays": 8, "toDays": 14, "total": {"minor": 500, "currency": "GBP"}, "references": ["Q", "R"]}, {"label": "14+", "fromDays": 15, "toDays": null, "total": {"minor": 400, "currency": "GBP"}, "references": ["S"]}], "total": {"minor": 1000, "currency": "GBP"}}},
  {"name": "a single boundary", "args": [[{"reference": "P", "dueDate": "2026-05-30", "outstanding": {"minor": 100, "currency": "GBP"}}, {"reference": "Q", "dueDate": "2026-07-01", "outstanding": {"minor": 50, "currency": "GBP"}}], "2026-06-30", [30], "GBP"], "expect": {"asAt": "2026-06-30", "buckets": [{"label": "current", "fromDays": null, "toDays": 0, "total": {"minor": 50, "currency": "GBP"}, "references": ["Q"]}, {"label": "1-30", "fromDays": 1, "toDays": 30, "total": {"minor": 0, "currency": "GBP"}, "references": []}, {"label": "30+", "fromDays": 31, "toDays": null, "total": {"minor": 100, "currency": "GBP"}, "references": ["P"]}], "total": {"minor": 150, "currency": "GBP"}}},
  {"name": "invoices due in the future are current", "args": [[{"reference": "F1", "dueDate": "2027-01-01", "outstanding": {"minor": 999, "currency": "GBP"}}], "2026-06-30", [30, 60, 90], "GBP"], "expect": {"asAt": "2026-06-30", "buckets": [{"label": "current", "fromDays": null, "toDays": 0, "total": {"minor": 999, "currency": "GBP"}, "references": ["F1"]}, {"label": "1-30", "fromDays": 1, "toDays": 30, "total": {"minor": 0, "currency": "GBP"}, "references": []}, {"label": "31-60", "fromDays": 31, "toDays": 60, "total": {"minor": 0, "currency": "GBP"}, "references": []}, {"label": "61-90", "fromDays": 61, "toDays": 90, "total": {"minor": 0, "currency": "GBP"}, "references": []}, {"label": "90+", "fromDays": 91, "toDays": null, "total": {"minor": 0, "currency": "GBP"}, "references": []}], "total": {"minor": 999, "currency": "GBP"}}},
  {"name": "no boundaries is refused", "args": [[], "2026-06-30", [], "GBP"], "expectError": "bucketDays needs at least one boundary"},
  {"name": "a zero boundary is refused", "args": [[], "2026-06-30", [0, 30], "GBP"], "expectError": "bucketDays must be whole days, ascending, from 1"},
  {"name": "repeated boundaries are refused", "args": [[], "2026-06-30", [30, 30], "GBP"], "expectError": "bucketDays must be whole days, ascending, from 1"},
  {"name": "descending boundaries are refused", "args": [[], "2026-06-30", [60, 30], "GBP"], "expectError": "bucketDays must be whole days, ascending, from 1"},
  {"name": "an invoice in another currency is refused", "args": [[{"reference": "A", "dueDate": "2026-06-01", "outstanding": {"minor": 100, "currency": "EUR"}}], "2026-06-30", [30, 60, 90], "GBP"], "expectError": "currency mismatch"},
  {"name": "an impossible due date is refused", "args": [[{"reference": "A", "dueDate": "2026-02-30", "outstanding": {"minor": 100, "currency": "GBP"}}], "2026-06-30", [30, 60, 90], "GBP"], "expectError": "not a real calendar date"}
]