test(core): golden file for the statement of changes in members' equity
Golden for the two-member 50/50 fixture (statements.rs partnership()), January and February, with and without January's close. Every number was recomputed by hand from the entries (plan/golden-worksheets/ members_equity_two_member.md) before the engine's output was compared: January: NI 1000.00 - 333.33 = 666.67 = 66667 cents; half is 33333.5, so largest remainder with the tie to Alice (listed first, B-13 CHOICE) gives Alice 333.34, Bob 333.33. Alice 0 + 600 + 333.34 = 933.34; Bob 0 + 400 + 333.33 = 733.33; Total 1666.67 = balance-sheet equity. February: undistributed earnings to date 666.67 + 100.01 = 766.68 split cumulatively is 383.34 each, so Alice earns 383.34 - 333.34 = 50.00 and Bob 383.34 - 333.33 = 50.01 (sum 100.01). Alice 933.34 + 50.00 = 983.34; Bob 733.33 + 50.01 - 100.00 = 683.34; Total 1666.68 = equity (1000 + 766.68 - 100). Ending of January = beginning of February (B-13 3a). "Other" is 0 in both. Same numbers whether or not January is closed (B-13 3c). Decimals compare by value (normalized), as the existing snapshot golden writes them; no existing golden or assertion changed. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d075235559
commit
5c7055123d
3 files changed
+272
No files matched your search
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"january": {
|
||||
"start": "2026-01-01",
|
||||
"end": "2026-01-31",
|
||||
"members": [
|
||||
{
|
||||
"name": "Alice",
|
||||
"beginning": "0",
|
||||
"contributions": "600",
|
||||
"net_income": "333.34",
|
||||
"distributions": "0",
|
||||
"other": "0",
|
||||
"ending": "933.34"
|
||||
},
|
||||
{
|
||||
"name": "Bob",
|
||||
"beginning": "0",
|
||||
"contributions": "400",
|
||||
"net_income": "333.33",
|
||||
"distributions": "0",
|
||||
"other": "0",
|
||||
"ending": "733.33"
|
||||
}
|
||||
],
|
||||
"total": {
|
||||
"name": "Total",
|
||||
"beginning": "0",
|
||||
"contributions": "1000",
|
||||
"net_income": "666.67",
|
||||
"distributions": "0",
|
||||
"other": "0",
|
||||
"ending": "1666.67"
|
||||
},
|
||||
"balance_sheet_equity": "1666.67"
|
||||
},
|
||||
"february": {
|
||||
"start": "2026-02-01",
|
||||
"end": "2026-02-28",
|
||||
"members": [
|
||||
{
|
||||
"name": "Alice",
|
||||
"beginning": "933.34",
|
||||
"contributions": "0",
|
||||
"net_income": "50",
|
||||
"distributions": "0",
|
||||
"other": "0",
|
||||
"ending": "983.34"
|
||||
},
|
||||
{
|
||||
"name": "Bob",
|
||||
"beginning": "733.33",
|
||||
"contributions": "0",
|
||||
"net_income": "50.01",
|
||||
"distributions": "100",
|
||||
"other": "0",
|
||||
"ending": "683.34"
|
||||
}
|
||||
],
|
||||
"total": {
|
||||
"name": "Total",
|
||||
"beginning": "1666.67",
|
||||
"contributions": "0",
|
||||
"net_income": "100.01",
|
||||
"distributions": "100",
|
||||
"other": "0",
|
||||
"ending": "1666.68"
|
||||
},
|
||||
"balance_sheet_equity": "1666.68"
|
||||
}
|
||||
}
|
||||
@@ -512,6 +512,67 @@ fn members_equity_rolls_capital_forward_and_ties_to_the_balance_sheet() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Every decimal string in `v`, by value (`"50.00"` and `"50"` are one
|
||||
/// number), as `snapshot` writes them. Both sides of a golden comparison go
|
||||
/// through it, so a harmless difference of written scale is no failure and
|
||||
/// every value must still agree exactly.
|
||||
fn by_value(v: &mut serde_json::Value) {
|
||||
match v {
|
||||
serde_json::Value::String(s) => {
|
||||
if let Ok(x) = Decimal::from_str(s) {
|
||||
*s = x.normalize().to_string();
|
||||
}
|
||||
}
|
||||
serde_json::Value::Array(items) => items.iter_mut().for_each(by_value),
|
||||
serde_json::Value::Object(map) => map.values_mut().for_each(by_value),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// The statement as JSON, with the balance sheet's total equity beside it.
|
||||
fn statement_json(
|
||||
l: &Ledger,
|
||||
start: NaiveDate,
|
||||
end: NaiveDate,
|
||||
members: &[MemberCapital],
|
||||
) -> serde_json::Value {
|
||||
let st = members_equity(l, start, end, members).unwrap();
|
||||
let mut v = serde_json::to_value(&st).unwrap();
|
||||
v["balance_sheet_equity"] =
|
||||
serde_json::to_value(balance_sheet_as_of(l, end).unwrap().total_equity).unwrap();
|
||||
by_value(&mut v);
|
||||
v
|
||||
}
|
||||
|
||||
/// The golden: every number in `golden/members_equity_two_member.json` was
|
||||
/// computed by hand, from the entries, in
|
||||
/// `plan/golden-worksheets/members_equity_two_member.md`, before the engine's
|
||||
/// output was looked at. Rules: B-13 (capital account = contributions +
|
||||
/// allocated income − distributions; cent rounding by largest remainder, the
|
||||
/// odd cent to the member listed first; unclosed earnings split cumulatively)
|
||||
/// and B-7 (the Total ties to balance-sheet equity). The same numbers hold
|
||||
/// whether or not January is closed (B-13: a member's capital on a date never
|
||||
/// moves when its period closes).
|
||||
#[test]
|
||||
fn golden_members_equity_two_member() {
|
||||
let mut golden: serde_json::Value =
|
||||
serde_json::from_str(include_str!("golden/members_equity_two_member.json")).unwrap();
|
||||
by_value(&mut golden);
|
||||
for close in [false, true] {
|
||||
let (l, members) = partnership(close);
|
||||
assert_eq!(
|
||||
statement_json(&l, d(1, 1), d(1, 31), &members),
|
||||
golden["january"],
|
||||
"January, close={close}"
|
||||
);
|
||||
assert_eq!(
|
||||
statement_json(&l, d(2, 1), d(2, 28), &members),
|
||||
golden["february"],
|
||||
"February, close={close}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn members_must_be_configured_correctly() {
|
||||
let (l, mut members) = partnership(false);
|
||||
|
||||
Reference in new issue
Block a user