The pedagogy test suite (tests/pedagogy/) bridges the gap between Derek Stone’s intuitive YouTube explanation of Pacioli’s double-entry bookkeeping and the formal mathematical framework in this repository.
Purpose: Make the framework’s rigor accessible to students and practitioners by showing how classical accounting concepts map to graph theory, conservation laws, and the discrete Reynolds Transport Theorem.
# Run all pedagogy tests
pytest tests/pedagogy/ -v
# Run with verbose output (shows ASCII diagrams)
pytest tests/pedagogy/ -v -s
# Run property-based tests thoroughly (300 examples each)
HYPOTHESIS_PROFILE=thorough pytest tests/pedagogy/property_based/ -v
# Run a specific test file
pytest tests/pedagogy/test_pacioli_worksheet.py -v -s
tests/pedagogy/
├── conftest.py # Shared fixtures (Ledger, JournalEntry, etc.)
├── test_pacioli_worksheet.py # Derek Stone's "Robbie" examples
├── test_kirchhoff_pedagogy.py # Why balance sheets balance
└── property_based/
├── conftest.py # Hypothesis configuration
└── test_pacioli_invariants.py # Universal properties (Hypothesis)
test_pacioli_worksheet.py - Derek Stone’s Robbie ExamplesPurpose: Demonstrate all three frameworks using Derek’s narrative.
What it tests:
Three views of same transactions:
1ᵀ·B = 0ΔE_parent = (NI + OCI) + Owner + Meas - ΔNCIExample output:
╔═══════════════════════════════════════════════════════════╗
║ ROBBIE'S WORKSHEET (Period 1) ║
╠═══════════════════════════════════════════════════════════╣
║ Assets & Expenses │ Liabilities, Equity, Revenue ║
║ Cash 775 │ Capital -1,000 ║
║ Inventory 250 │ Revenue -225 ║
║ COGS Expense 150 │ ║
║ Wages Expense 50 │ ║
╠════════════════════════╧══════════════════════════════════╣
║ Net: 1,225 + (-1,225) = 0 ✓ BALANCED ║
╚═══════════════════════════════════════════════════════════╝
Derek Stone video timestamps referenced in tests:
test_kirchhoff_pedagogy.py - Balance Sheet ConservationPurpose: Answer the #1 student question: “Does A=L+E break if I’m gifted a building?”
What it tests:
Key theorem proved:
Theorem 1 (Kirchhoff’s Accounting Theorem):
If every journal entry satisfies Axiom 1 (Σ postings = 0), then Σ all balances = 0, which is equivalent to A = L + E.
Student FAQ coverage:
property_based/test_pacioli_invariants.py - Universal PropertiesPurpose: Use Hypothesis to prove laws hold for ALL possible transactions.
What it tests:
Hypothesis strategies:
balanced_entry_strategy(): Generate valid journal entriesentry_sequence_strategy(): Generate 1-10 random entriesposting_strategy(): Generate (account, amount) pairsRun profiles:
# Quick check (25 examples)
HYPOTHESIS_PROFILE=dev pytest tests/pedagogy/property_based/ -v
# CI/CD (75 examples)
HYPOTHESIS_PROFILE=ci pytest tests/pedagogy/property_based/ -v
# Thorough (300 examples)
HYPOTHESIS_PROFILE=thorough pytest tests/pedagogy/property_based/ -v
Pedagogical value:
| Derek Stone Video Timestamp | Concept | Test Location |
|---|---|---|
| 0:01-2:22 | Pacioli: rules without proof | docs/pedagogy/MATHEMATICAL_FOUNDATIONS_HISTORY.md |
| 4:06-5:38 | Separate entity (owner is liability) | test_pacioli_worksheet.py::test_robbie_t1_owner_invests_cash |
| 5:38-6:03 | Buy inventory (asset-to-asset) | test_pacioli_worksheet.py::test_robbie_t2_buy_inventory_cash |
| 6:03-8:08 | First sale (revenue, COGS, matching) | test_pacioli_worksheet.py::test_robbie_t3_cash_sale_with_cogs |
| 8:16-9:09 | Credit sales (A/R, A/P) | test_pacioli_worksheet.py::test_robbie_credit_sales_scenario |
| 9:09-11:18 | “Subtract RHS” → self-balancing | test_kirchhoff_pedagogy.py::test_kirchhoff_law_incidence_matrix |
| 13:05-14:20 | Two columns (debits/credits) | test_kirchhoff_pedagogy.py::test_derek_stone_debits_equal_credits_proof |
| 16:04-17:50 | Debits/credits = disguised +/− | conftest.py::Posting (documented in docstring) |
| 18:22-19:42 | “Hot/cold air” (debit effect varies) | property_based/test_pacioli_invariants.py::test_property_debit_effect_depends_on_account_type |
| 19:50-22:08 | Extract P&L, cash flow, balance sheet | test_pacioli_worksheet.py::test_robbie_complete_cash_scenario_three_views |
| Derek’s Concept | Framework Theorem | Proof Location |
|---|---|---|
| “Self-balancing rows” | Axiom 1: Σ P_{i,j} = 0 | docs/proofs/EQUITY_BRIDGE_PROOF.md |
| “Worksheet without equals sign” | 1ᵀ·B = 0 (Kirchhoff) | docs/proofs/KIRCHHOFF_ACCOUNTING_THEOREM.md |
| “Assets = Liabilities + Equity” | Theorem 1 (follows from Axiom 1) | docs/proofs/KIRCHHOFF_ACCOUNTING_THEOREM.md |
| “Profit & loss from worksheet” | ΔE_parent = (NI + OCI) + … | docs/proofs/EQUITY_BRIDGE_PROOF.md |
| “Multi-year planning” | Discrete RTT recurrence | docs/proofs/DISCRETE_RTT_THEOREM.md |
Posting(account, amount):
is_debit, is_creditJournalEntry(description, postings):
is_balanced (checks Axiom 1)total_debits, total_creditsLedger():
post(), balance(), trial_balance_sum()is_balanced() (checks A = L + E)robbie_chart_of_accounts:
pacioli_worksheet:
incidence_matrix_builder:
ascii_worksheet_formatter:
pytest tests/pedagogy/test_pacioli_worksheet.py::test_robbie_complete_cash_scenario_three_views -v -s
Shows:
pytest tests/pedagogy/test_kirchhoff_pedagogy.py::test_gifted_building_shareholder_contribution -v -s
Shows:
HYPOTHESIS_PROFILE=thorough pytest tests/pedagogy/property_based/ -v -s
Shows:
test_pacioli_worksheet.py::test_robbie_t1_owner_invests_cash
test_robbie_t2_buy_inventory_cash
test_robbie_t3_cash_sale_with_cogs
test_robbie_complete_cash_scenario_three_views
test_robbie_credit_sales_scenario
test_kirchhoff_pedagogy.py::test_kirchhoff_law_incidence_matrixtest_kirchhoff_pedagogy.py::test_gifted_building_shareholder_contributionproperty_based/test_pacioli_invariants.pyascii_worksheet_formatter up to datetest_pacioli_worksheet.pytest_kirchhoff_pedagogy.py docstringproperty_based/test_pacioli_invariants.py@given test with clear docstringthorough profile to verifydef test_my_scenario(...):
# (a) Worksheet view
entry = JournalEntry(...)
for posting in entry.postings:
ledger.post(posting.account, posting.amount)
worksheet = pacioli_worksheet(ledger)
print(ascii_worksheet_formatter(worksheet, "My Scenario"))
# (b) Incidence matrix view
accounts, matrix = incidence_matrix_builder([entry])
assert all(sum(row[j]) == 0 for j in range(len(entries))) # Kirchhoff
# (c) Equity bridge view
result = compute_equity_bridge(EquityBridgeInputs(...))
assert result.passed
def test_my_conservation_claim():
ledger = Ledger()
# ... post transactions ...
# Verify A = L + E
assert ledger.is_balanced()
# Or compute explicitly
assets = ...
liabilities = ...
equity = ...
assert abs(assets - (liabilities + equity)) < 1e-9
@given(my_strategy=...)
def test_property_my_invariant(my_strategy):
"""Property: [Universal claim]"""
# ... perform operations ...
assert [invariant holds]
Cause: Python path not set correctly.
Fix: The conftest.py in tests/pedagogy/ sets up the path. Run from repo root:
cd /path/to/accounting-conservation-framework
pytest tests/pedagogy/ -v
Cause: Balances don’t sum to exactly zero due to floating-point arithmetic.
Fix: Always use tolerance in assertions:
assert abs(value - expected) < 1e-9 # NOT: assert value == expected
Cause: Hypothesis found a failing example but can’t reproduce.
Fix: Hypothesis saves examples in .hypothesis/ database. Run again to replay.
Author: Nirvan Chitnis (with Claude Code assistance) Date: 2025-11-20
To contribute new pedagogy tests:
pytest tests/pedagogy/ -vHYPOTHESIS_PROFILE=thoroughGoal: Make rigorous accounting theory accessible to students worldwide.