test(spec): cover balanceMatchesAddedSum single, sum-match, over, under cases

Pins the sum-based predicate: a single new row matching delta and two new
rows summing to delta both hold; two-row over-sum (double-submit) and
under-sum cases both violate.
This commit is contained in:
pj committed 2026-05-31 15:49:55 +05:30
1 parent b88b6c239d
commit 37079a0d84
1 file changed
+42
@@ -0,0 +1,42 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import {
balanceMatchesAddedSum,
type LedgerRow,
} from "../../../examples/folio/sanderling/predicates.ts";
function row(key: string, signed: number): LedgerRow {
return { key, signed };
}
test("single new row whose signed amount matches the balance delta holds", () => {
const previous: LedgerRow[] = [row("a", 100)];
const current: LedgerRow[] = [row("a", 100), row("b", 500)];
assert.equal(balanceMatchesAddedSum(previous, current, 100, 600), true);
});
test("two new rows whose sum matches the balance delta holds", () => {
const previous: LedgerRow[] = [];
const current: LedgerRow[] = [row("a", 500), row("b", 300)];
assert.equal(balanceMatchesAddedSum(previous, current, 0, 800), true);
});
test("double-submit case: two identical rows with sum exceeding the delta violates", () => {
const previous: LedgerRow[] = [];
const current: LedgerRow[] = [row("a", 500), row("b", 500)];
assert.equal(balanceMatchesAddedSum(previous, current, 0, 500), false);
});
test("partial-credit case: two new rows whose sum falls short of the delta violates", () => {
const previous: LedgerRow[] = [];
const current: LedgerRow[] = [row("a", 200), row("b", 100)];
assert.equal(balanceMatchesAddedSum(previous, current, 0, 500), false);
});
test("no new rows holds vacuously regardless of balance delta", () => {
const previous: LedgerRow[] = [row("a", 100)];
const current: LedgerRow[] = [row("a", 100)];
assert.equal(balanceMatchesAddedSum(previous, current, 100, 100), true);
assert.equal(balanceMatchesAddedSum(previous, current, 100, 999), true);
});