From 6f2e2cf1ebf12c27399fd2be604064fc11e62bbb Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Sun, 8 Nov 2026 21:54:01 -0700 Subject: [PATCH] test(core): bridge the party direction, part weight and reverse_target Three properties the traceability gate can see as calls, not mentions: - `reverse_target_agrees`: the earlier party bridge only passed `reverse_target` to `and_then`, which proves nothing about the `i64` and `Decimal` instantiations agreeing; the property now calls both. - `direction_of_agrees`: `Direction::of` classifies the same sign at both types, each case keeping its meaning. - `part_weight_agrees`: `part_weight` is the same weight at `i32`, `i64` and `i128`, and `None` exactly for a part no month has. Co-Authored-By: DeepSeek V4.1 Flash --- .../tests/kernel_bridge/entries.rs | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/crates/ledger-core/tests/kernel_bridge/entries.rs b/crates/ledger-core/tests/kernel_bridge/entries.rs index 08d6c671..40bcf6a9 100644 --- a/crates/ledger-core/tests/kernel_bridge/entries.rs +++ b/crates/ledger-core/tests/kernel_bridge/entries.rs @@ -31,6 +31,14 @@ fn to_dec(lines: &[(Flow, Side, i64)]) -> Vec<(Flow, Side, rust_decimal::Decimal lines.iter().map(|&(f, s, a)| (f, s, dec(a))).collect() } +fn arb_direction() -> impl Strategy { + prop_oneof![ + Just(kernel::Direction::Paid), + Just(kernel::Direction::Received), + Just(kernel::Direction::Neither), + ] +} + proptest! { #![proptest_config(ProptestConfig::with_cases(1000))] @@ -95,4 +103,73 @@ proptest! { kernel::unrecovered_cost(dec(revenue), dec(expenses)) ); } + + /// `kernel::Direction::of` classifies the same sign at both types, and + /// each case keeps its meaning (law 23). + #[test] + fn direction_of_agrees(cents in arb_cents()) { + let i = kernel::Direction::of(cents); + let d = kernel::Direction::of(dec(cents)); + prop_assert_eq!(i, d); + if cents > 0 { + prop_assert_eq!(i, kernel::Direction::Paid); + } else if cents < 0 { + prop_assert_eq!(i, kernel::Direction::Received); + } else { + prop_assert_eq!(i, kernel::Direction::Neither); + } + } + + /// `kernel::reverse_target` is the exact opposite at both types, and + /// each refuses the same out-of-range inputs (law 24). + #[test] + fn reverse_target_agrees( + amount in arb_cents(), + cash in arb_cents(), + in_kind in arb_cents(), + direction in arb_direction(), + ) { + let t = kernel::PartyTarget { + amount, + direction, + cash, + in_kind, + }; + let d = kernel::PartyTarget { + amount: dec(amount), + direction, + cash: dec(cash), + in_kind: dec(in_kind), + }; + let as_dec = |r: kernel::PartyTarget| kernel::PartyTarget { + amount: dec(r.amount), + direction: r.direction, + cash: dec(r.cash), + in_kind: dec(r.in_kind), + }; + prop_assert_eq!( + kernel::reverse_target(t).map(as_dec), + kernel::reverse_target(d) + ); + } + + /// `kernel::part_weight` is the same weight at i32, i64 and i128, and + /// `None` exactly for a part no calendar month has (laws 26-28). + #[test] + fn part_weight_agrees(month_days in 0u32..=40, days in 0u32..=40) { + let part = kernel::MonthPart { days, month_days }; + let w32: Option = kernel::part_weight(part); + let w64: Option = kernel::part_weight(part); + let w128: Option = kernel::part_weight(part); + prop_assert_eq!(w64, w32.map(i64::from)); + prop_assert_eq!(w128, w64.map(i128::from)); + if part.is_valid() { + prop_assert_eq!( + w64, + Some(i64::from(days) * i64::from(kernel::MONTH_L / month_days)) + ); + } else { + prop_assert_eq!(w64, None); + } + } }