All source files · Download test_population_comparison_2025.py
"""Accounting and integration checks, with no network or document builds."""
import json
import unittest
import numpy as np
from calibration import load_population, ubi_weight
from income_demographics import build_model
from population_comparison_2025 import (
accounting_bridge, amount, build_population, family_scenarios, report,
)
class PopulationComparisonTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.historical = build_model()
cls.population = build_population(cls.historical)
def test_2025_population_and_age_weighted_payments(self):
p = self.population
ages = load_population()
self.assertEqual(p.calibration.population, sum(ages.values()))
self.assertAlmostEqual(p.weights @ p.household_ubi_weights,
sum(n*ubi_weight(a) for a, n in ages.items()), delta=.01)
self.assertAlmostEqual(p.weights @ p.ubi, p.calibration.ubi_pool, delta=1)
# Age weighting, rather than paying every child a full adult amount.
self.assertLess(p.calibration.total_weight, p.calibration.population)
def test_income_growth_is_not_counted_twice(self):
p = self.population
expected = self.historical.summary()["private"] * (
amount(p.controls, "household", "D") / amount(p.controls, "household", "D", "2019-20"))
self.assertAlmostEqual(p.weights @ p.private, expected, delta=1)
def test_australian_budget_and_household_identity(self):
p = self.population
t = p.totals()
self.assertAlmostEqual(t["private"]+t["benefits"]-t["tax"],
t["australia_buying_power"], delta=1)
b = accounting_bridge(p)
g = b["government"]
self.assertLessEqual(abs(g["published_rounding_residual"]), 2e6)
self.assertAlmostEqual(g["receipts_excluding_depreciation"]+g["net_borrowing"],
g["uses_excluding_depreciation"], delta=2e6)
sources = (b["australia_net_funding_from_modelled_household_cash"]
+ b["australia_remaining_receipts_after_modelled_tax"] + g["net_borrowing"])
self.assertAlmostEqual(sources, b["australia_other_public_uses_after_cash_benefits"], delta=2e6)
def test_no_missing_winners_or_unfunded_ubi(self):
p = self.population
t = p.totals()
b = accounting_bridge(p)
self.assertAlmostEqual(t["gains"]-t["losses"], t["difference"], delta=1)
self.assertAlmostEqual(t["vota_buying_power"]-t["australia_buying_power"],
t["difference"], delta=1)
self.assertAlmostEqual(-t["difference"]/1.1,
b["cash_boundary_gap_before_embedded_tax_adjustment"], delta=1)
self.assertAlmostEqual(b["vota_gross_consumption_tax"]-t["ubi"],
b["vota_services_pool"], delta=1)
def test_tax_allocation_bounds_and_calibration_are_explicit(self):
p = self.population
self.assertTrue(np.all(p.tax >= 0))
self.assertTrue(np.all(p.tax <= .5*np.maximum(p.private+p.benefits, 0)))
self.assertAlmostEqual(p.weights @ p.tax, amount(p.controls, "household", "AA"), delta=1)
self.assertIn("not a population statutory simulation", p.diagnostics["tax_benefit_basis"])
def test_profiles_and_income_bands_partition_population(self):
r = report(self.population, include_scenarios=False)
for groups in (r["profiles"], r["income_bands"]):
for field in ("households", "private", "benefits", "tax", "ubi", "difference", "gains", "losses"):
self.assertAlmostEqual(sum(g[field] for g in groups), r["totals"][field], delta=1)
json.dumps(r, allow_nan=False)
def test_family_rules_use_new_calibration_and_household_income(self):
rows = family_scenarios(self.population.calibration)
single = next(r for r in rows if r["parents"] == 1 and r["children"] == 0
and r["household_private_income"] == 0)
self.assertAlmostEqual(single["annual_ubi"], self.population.calibration.adult_ubi)
self.assertAlmostEqual(single["australia_buying_power"], 781.10*365/14)
self.assertAlmostEqual(single["vota_buying_power"], .528*single["annual_ubi"])
couples = [r for r in rows if r["parents"] == 2 and r["children"] == 0
and r["household_private_income"] == 120_000]
self.assertEqual(len(couples), 2)
self.assertEqual(couples[0]["vota_buying_power"], couples[1]["vota_buying_power"])
self.assertGreater(couples[1]["australia_buying_power"], couples[0]["australia_buying_power"])
def test_population_uplift_does_not_mutate_historical_fit(self):
baseline = self.historical.summary()
alternative = build_population(self.historical, income_multiplier=1.1)
self.assertEqual(self.historical.summary(), baseline)
self.assertAlmostEqual(alternative.calibration.adult_ubi,
1.1*self.population.calibration.adult_ubi, places=6)
self.assertEqual(self.historical.data["year"], "2019-20")
if __name__ == "__main__":
unittest.main()