merge: golden files for the date-range P&L, the balance sheet and trial balance as of a date, and the general ledger (branch t3/golden-pl-balance-trial-gl, c5824c4f; reviewed and recomputed independently)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Opus 5.5 committed 2026-11-07 10:05:13 -07:00
commit 805633ef7b
9 files changed
+873

No files matched your search

@@ -0,0 +1,43 @@
{
"as_of": "2026-01-31",
"assets": [
{
"code": "1000",
"name": "Cash",
"amount": "7200"
},
{
"code": "1200",
"name": "Accounts Receivable",
"amount": "2500"
},
{
"code": "1500",
"name": "Equipment",
"amount": "4000"
}
],
"liabilities": [
{
"code": "2000",
"name": "Accounts Payable",
"amount": "500"
}
],
"equity": [
{
"code": "3000",
"name": "Owner's Equity",
"amount": "10000"
},
{
"code": "3999",
"name": "Retained Earnings",
"amount": "3200"
}
],
"current_earnings": "0",
"total_assets": "13700",
"total_liabilities": "500",
"total_equity": "13200"
}
@@ -0,0 +1,238 @@
{
"start": "2026-01-01",
"end": "2026-01-31",
"accounts": [
{
"code": "1000",
"name": "Cash",
"account_type": "Asset",
"beginning_balance": "0",
"postings": [
{
"date": "2026-01-02",
"entry_id": 1,
"description": "Owner investment",
"split": "3000 Owner's Equity",
"debit": "10000",
"credit": "0",
"balance": "10000"
},
{
"date": "2026-01-05",
"entry_id": 2,
"description": "Buy equipment",
"split": "1500 Equipment",
"debit": "0",
"credit": "2500",
"balance": "7500"
},
{
"date": "2026-01-15",
"entry_id": 4,
"description": "January rent",
"split": "6000 Rent Expense",
"debit": "0",
"credit": "800",
"balance": "6700"
},
{
"date": "2026-01-20",
"entry_id": 5,
"description": "Client payment",
"split": "1200 Accounts Receivable",
"debit": "1500",
"credit": "0",
"balance": "8200"
},
{
"date": "2026-01-25",
"entry_id": 6,
"description": "Buy more equipment",
"split": "1500 Equipment",
"debit": "0",
"credit": "1000",
"balance": "7200"
}
],
"total_debits": "11500",
"total_credits": "4300",
"ending_balance": "7200"
},
{
"code": "1200",
"name": "Accounts Receivable",
"account_type": "Asset",
"beginning_balance": "0",
"postings": [
{
"date": "2026-01-10",
"entry_id": 3,
"description": "Invoice client",
"split": "4000 Service Revenue",
"debit": "4000",
"credit": "0",
"balance": "4000"
},
{
"date": "2026-01-20",
"entry_id": 5,
"description": "Client payment",
"split": "1000 Cash",
"debit": "0",
"credit": "1500",
"balance": "2500"
}
],
"total_debits": "4000",
"total_credits": "1500",
"ending_balance": "2500"
},
{
"code": "1500",
"name": "Equipment",
"account_type": "Asset",
"beginning_balance": "0",
"postings": [
{
"date": "2026-01-05",
"entry_id": 2,
"description": "Buy equipment",
"split": "1000 Cash",
"debit": "2500",
"credit": "0",
"balance": "2500"
},
{
"date": "2026-01-25",
"entry_id": 6,
"description": "Buy more equipment",
"split": "-Split-",
"debit": "1500",
"credit": "0",
"balance": "4000"
}
],
"total_debits": "4000",
"total_credits": "0",
"ending_balance": "4000"
},
{
"code": "2000",
"name": "Accounts Payable",
"account_type": "Liability",
"beginning_balance": "0",
"postings": [
{
"date": "2026-01-25",
"entry_id": 6,
"description": "Buy more equipment",
"split": "1500 Equipment",
"debit": "0",
"credit": "500",
"balance": "500"
}
],
"total_debits": "0",
"total_credits": "500",
"ending_balance": "500"
},
{
"code": "3000",
"name": "Owner's Equity",
"account_type": "Equity",
"beginning_balance": "0",
"postings": [
{
"date": "2026-01-02",
"entry_id": 1,
"description": "Owner investment",
"split": "1000 Cash",
"debit": "0",
"credit": "10000",
"balance": "10000"
}
],
"total_debits": "0",
"total_credits": "10000",
"ending_balance": "10000"
},
{
"code": "3999",
"name": "Retained Earnings",
"account_type": "Equity",
"beginning_balance": "0",
"postings": [
{
"date": "2026-01-31",
"entry_id": 7,
"description": "Close period 2026-01",
"split": "4000 Service Revenue",
"debit": "0",
"credit": "3200",
"balance": "3200"
}
],
"total_debits": "0",
"total_credits": "3200",
"ending_balance": "3200"
},
{
"code": "4000",
"name": "Service Revenue",
"account_type": "Revenue",
"beginning_balance": "0",
"postings": [
{
"date": "2026-01-10",
"entry_id": 3,
"description": "Invoice client",
"split": "1200 Accounts Receivable",
"debit": "0",
"credit": "4000",
"balance": "4000"
},
{
"date": "2026-01-31",
"entry_id": 7,
"description": "Close period 2026-01",
"split": "-Split-",
"debit": "4000",
"credit": "0",
"balance": "0"
}
],
"total_debits": "4000",
"total_credits": "4000",
"ending_balance": "0"
},
{
"code": "6000",
"name": "Rent Expense",
"account_type": "Expense",
"beginning_balance": "0",
"postings": [
{
"date": "2026-01-15",
"entry_id": 4,
"description": "January rent",
"split": "1000 Cash",
"debit": "800",
"credit": "0",
"balance": "800"
},
{
"date": "2026-01-31",
"entry_id": 7,
"description": "Close period 2026-01",
"split": "4000 Service Revenue",
"debit": "0",
"credit": "800",
"balance": "0"
}
],
"total_debits": "800",
"total_credits": "800",
"ending_balance": "0"
}
]
}
@@ -0,0 +1,20 @@
{
"start": "2026-01-01",
"end": "2026-01-31",
"revenue": [
{
"code": "4000",
"name": "Service Revenue",
"amount": "4000"
}
],
"expenses": [
{
"code": "6000",
"name": "Rent Expense",
"amount": "800"
}
],
"total_revenue": "4000",
"total_expenses": "800"
}
@@ -0,0 +1,42 @@
{
"lines": [
{
"code": "1000",
"name": "Cash",
"debit": "7200",
"credit": "0"
},
{
"code": "1200",
"name": "Accounts Receivable",
"debit": "2500",
"credit": "0"
},
{
"code": "1500",
"name": "Equipment",
"debit": "4000",
"credit": "0"
},
{
"code": "2000",
"name": "Accounts Payable",
"debit": "0",
"credit": "500"
},
{
"code": "3000",
"name": "Owner's Equity",
"debit": "0",
"credit": "10000"
},
{
"code": "3999",
"name": "Retained Earnings",
"debit": "0",
"credit": "3200"
}
],
"total_debits": "13700",
"total_credits": "13700"
}
+190
View File
@@ -0,0 +1,190 @@
//! Golden files for the report rows in `docs/parity.md` that had none:
//! profit and loss for a date range, balance sheet as of a date, trial
//! balance as of a date, and the general ledger by account.
//!
//! The fixture is an **extended copy** of the hand-verified
//! `fixture_company()` in `invariants.rs`. The original has no closing
//! entry, no entry dated after an as-of date, and no multi-leg entry, so it
//! cannot show the exclusions and the `-Split-` case these reports are
//! about. Entries 1–5 are the original fixture unchanged; entries 6–8 are
//! the extension. Every expected number is computed by hand in
//! `plan/golden-worksheets/`; see the worksheet named in each test.
use chrono::NaiveDate;
use ledger_core::reports::{
balance_sheet_as_of, general_ledger, profit_and_loss_for_period, trial_balance_as_of,
};
use ledger_core::{AccountId, AccountType, Currency, Ledger, Money, Side};
use rust_decimal::Decimal;
fn date(day: u32) -> NaiveDate {
NaiveDate::from_ymd_opt(2026, 1, day).unwrap()
}
fn february(day: u32) -> NaiveDate {
NaiveDate::from_ymd_opt(2026, 2, day).unwrap()
}
fn usd(amount: u64) -> Money {
Money::new(Decimal::from(amount), Currency::USD)
}
/// Post a balanced entry in one call. Fixtures must be valid by construction.
fn post(ledger: &mut Ledger, date: NaiveDate, description: &str, lines: &[(AccountId, Side, u64)]) {
// As replay posts it: this fixture holds hand lines on the receivable
// and payable control accounts (1200, 2000), which books an earlier
// version wrote still hold and every report must read; the control
// guard (rules.md B-38) refuses them as new work.
ledger_core::parties::replaying(|| {
let id = ledger.create_entry(date, description);
for (account, side, amount) in lines {
ledger.add_line(id, *account, *side, usd(*amount)).unwrap();
}
ledger.post_entry(id).unwrap();
})
}
/// The extended January 2026 fixture: the original five entries, then a
/// multi-leg equipment purchase (cash and payable), a January close, and a
/// February entry after every as-of date used here.
fn golden_company() -> Ledger {
let mut ledger = Ledger::new(Currency::USD);
let cash = ledger
.add_account("1000", "Cash", AccountType::Asset, None, false)
.unwrap();
let ar = ledger
.add_account(
"1200",
"Accounts Receivable",
AccountType::Asset,
None,
false,
)
.unwrap();
let equipment = ledger
.add_account("1500", "Equipment", AccountType::Asset, None, false)
.unwrap();
let ap = ledger
.add_account(
"2000",
"Accounts Payable",
AccountType::Liability,
None,
false,
)
.unwrap();
let equity = ledger
.add_account("3000", "Owner's Equity", AccountType::Equity, None, false)
.unwrap();
let revenue = ledger
.add_account("4000", "Service Revenue", AccountType::Revenue, None, false)
.unwrap();
let rent = ledger
.add_account("6000", "Rent Expense", AccountType::Expense, None, false)
.unwrap();
// 1. Owner invests $10,000 cash.
post(
&mut ledger,
date(2),
"Owner investment",
&[(cash, Side::Debit, 10_000), (equity, Side::Credit, 10_000)],
);
// 2. Buy equipment for $2,500 cash.
post(
&mut ledger,
date(5),
"Buy equipment",
&[(equipment, Side::Debit, 2_500), (cash, Side::Credit, 2_500)],
);
// 3. Bill a client $4,000.
post(
&mut ledger,
date(10),
"Invoice client",
&[(ar, Side::Debit, 4_000), (revenue, Side::Credit, 4_000)],
);
// 4. Pay January rent, $800.
post(
&mut ledger,
date(15),
"January rent",
&[(rent, Side::Debit, 800), (cash, Side::Credit, 800)],
);
// 5. Collect $1,500 of receivables.
post(
&mut ledger,
date(20),
"Client payment",
&[(cash, Side::Debit, 1_500), (ar, Side::Credit, 1_500)],
);
// 6. Buy more equipment: $1,000 cash and $500 on account (multi-leg, so
// its Equipment line's split is "-Split-").
post(
&mut ledger,
date(25),
"Buy more equipment",
&[
(equipment, Side::Debit, 1_500),
(cash, Side::Credit, 1_000),
(ap, Side::Credit, 500),
],
);
// 7. Close January: revenue 4,000 less rent 800 moves 3,200 to retained
// earnings, dated at the period end (2026-01-31).
let period = ledger.create_period("2026-01", date(1), date(31)).unwrap();
ledger.close_period(period).unwrap();
// 8. February revenue after every as-of date in these tests.
post(
&mut ledger,
february(5),
"February service",
&[(ar, Side::Debit, 600), (revenue, Side::Credit, 600)],
);
ledger
}
/// By-hand worksheet: `plan/golden-worksheets/profit-and-loss-period.md`.
#[test]
fn golden_profit_and_loss_period() {
let ledger = golden_company();
let report = profit_and_loss_for_period(&ledger, date(1), date(31), None).unwrap();
let got = serde_json::to_value(&report).unwrap();
let want: serde_json::Value =
serde_json::from_str(include_str!("golden/profit_and_loss_period.json")).unwrap();
assert_eq!(got, want);
}
/// By-hand worksheet: `plan/golden-worksheets/balance-sheet-as-of.md`.
#[test]
fn golden_balance_sheet_as_of() {
let ledger = golden_company();
let report = balance_sheet_as_of(&ledger, date(31)).unwrap();
let got = serde_json::to_value(&report).unwrap();
let want: serde_json::Value =
serde_json::from_str(include_str!("golden/balance_sheet_as_of.json")).unwrap();
assert_eq!(got, want);
}
/// By-hand worksheet: `plan/golden-worksheets/trial-balance-as-of.md`.
#[test]
fn golden_trial_balance_as_of() {
let ledger = golden_company();
let report = trial_balance_as_of(&ledger, date(31));
let got = serde_json::to_value(&report).unwrap();
let want: serde_json::Value =
serde_json::from_str(include_str!("golden/trial_balance_as_of.json")).unwrap();
assert_eq!(got, want);
}
/// By-hand worksheet: `plan/golden-worksheets/general-ledger.md`.
#[test]
fn golden_general_ledger() {
let ledger = golden_company();
let report = general_ledger(&ledger, date(1), date(31)).unwrap();
let got = serde_json::to_value(&report).unwrap();
let want: serde_json::Value =
serde_json::from_str(include_str!("golden/general_ledger.json")).unwrap();
assert_eq!(got, want);
}