fix(core): a zero plan prints 0 every month, as the cent rule always has

The K-U5 review's probe compared 1.5 million plans as printed text,
legacy against new, and found one difference: a zero total's last month
printed -0 (the kernel's 0 - 0), where the old plan printed 0. A zero
total is never registered, so no journaled schedule is touched, but the
promise is that the same plan prints the same, so the zero plan now
prints a bare 0 every month; a test pins it (and fails without the fix).

Also from the review: the kernel's GOAL said no month is more than a
rounding from the rest, which the last month need not be (INVARIANT 4
bounds it); and WB-prepaid-2's Checked list lacked the fifth harness.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Opus 5.5 committed 2026-11-09 04:30:35 -07:00
1 parent 317c53fa00
commit d47bc47508
3 files changed
+29 -4

No files matched your search

+2 -1
View File
@@ -18,7 +18,8 @@ use super::{Amount, Rounding, plug_last, round_step};
/// ```text
/// GOAL: an equal-months schedule books exactly its total across its
/// months, each month a whole number of the currency's smallest
/// unit, and no month is ever more than a rounding from the rest.
/// unit: every month but the last the same rounded share, the
/// last what the others leave (INVARIANT 4 bounds how far it is).
/// SOURCE: BS-prepaid-1 (a schedule recognizes exactly its total over its
/// months, each month rounded to the currency's minor unit), BS-prepaid-2
/// (equal months is one of the two methods an engine picks),
+25 -2
View File
@@ -348,10 +348,15 @@ fn plan_in_places(
/// Values never change: every rescale below is
/// to or from trailing zeros, which the debug assertions check.
///
/// A zero total is never registered (validate_schedule_shape), and a
/// one-month plan is its total; both are left as the kernel gives them.
/// A one-month plan is its total, left as the kernel gives it. A zero
/// total is never registered (validate_schedule_shape), but the plan of
/// one prints as it always did: every month a bare 0 (the kernel's last
/// month is `0 - 0`, which `Decimal` prints as `-0`).
fn present_as_rounded(parts: &mut [Decimal], total: Decimal, places: u32) {
if total.is_zero() {
for part in parts.iter_mut() {
*part = Decimal::ZERO;
}
return;
}
let Some((last, rest)) = parts.split_last_mut() else {
@@ -834,6 +839,24 @@ mod tests {
NaiveDate::from_ymd_opt(y, m, day).unwrap()
}
/// A zero total's plan prints every month as a bare 0, as the cent
/// rule always has: never `-0` (the K-U5 review's probe found the last
/// month of a zero plan printed `-0`; a replayed month is compared as
/// text).
#[test]
fn a_zero_plan_prints_zero_every_month() {
for months in [1, 2, 3, 12] {
for scale in [0, 2, 5] {
let plan = amortization_plan(Decimal::new(0, scale), d(2026, 1, 1), months)
.expect("a zero total plans");
assert!(
plan.iter().all(|(_, a)| a.to_string() == "0"),
"{months} months at scale {scale}: {plan:?}"
);
}
}
}
#[test]
fn plans_sum_exactly_and_land_on_month_ends() {
let plan = amortization_plan(Decimal::new(100_000, 2), d(2026, 11, 15), 3).unwrap();
+2 -1
View File
@@ -85,4 +85,5 @@ refuses as newer books.
`an_unknown_rounding_is_newer_not_corrupt`,
`schedule_minor_unit_is_its_own_feature`, `even_parts_sum`,
`even_parts_all_but_last_equal`, `even_parts_last_absorbs`,
`even_parts_within_half_step`.
`even_parts_within_half_step`,
`even_parts_refuses_no_months_and_a_bad_step`.