|
| 1 | +from policyengine_uk import Simulation |
| 2 | +import pytest |
| 3 | + |
| 4 | + |
| 5 | +def test_corporate_land_value_matches_aggregate_for_weighted_dataset(): |
| 6 | + sim = Simulation( |
| 7 | + situation={ |
| 8 | + "people": { |
| 9 | + "person_1": {"age": {2025: 40}}, |
| 10 | + "person_2": {"age": {2025: 50}}, |
| 11 | + }, |
| 12 | + "benunits": { |
| 13 | + "benunit_1": {"members": ["person_1"]}, |
| 14 | + "benunit_2": {"members": ["person_2"]}, |
| 15 | + }, |
| 16 | + "households": { |
| 17 | + "household_1": { |
| 18 | + "members": ["person_1"], |
| 19 | + "corporate_wealth": {2025: 100_000}, |
| 20 | + "household_weight": {2025: 2}, |
| 21 | + }, |
| 22 | + "household_2": { |
| 23 | + "members": ["person_2"], |
| 24 | + "corporate_wealth": {2025: 300_000}, |
| 25 | + "household_weight": {2025: 1}, |
| 26 | + }, |
| 27 | + }, |
| 28 | + } |
| 29 | + ) |
| 30 | + |
| 31 | + corporate_land_value = sim.calculate( |
| 32 | + "corporate_land_value", map_to="household", period=2025 |
| 33 | + ) |
| 34 | + household_weight = sim.calculate( |
| 35 | + "household_weight", map_to="household", period=2025 |
| 36 | + ) |
| 37 | + aggregate = sim.tax_benefit_system.parameters( |
| 38 | + "2025" |
| 39 | + ).household.wealth.land.value.aggregate_corporate_land_value |
| 40 | + |
| 41 | + assert corporate_land_value[0] == pytest.approx(aggregate * 0.2) |
| 42 | + assert corporate_land_value[1] == pytest.approx(aggregate * 0.6) |
| 43 | + assert (corporate_land_value * household_weight).sum() == pytest.approx(aggregate) |
| 44 | + |
| 45 | + |
| 46 | +def test_corporate_land_value_is_zero_without_corporate_wealth(): |
| 47 | + sim = Simulation( |
| 48 | + situation={ |
| 49 | + "people": {"person": {"age": {2025: 40}}}, |
| 50 | + "benunits": {"benunit": {"members": ["person"]}}, |
| 51 | + "households": { |
| 52 | + "household": { |
| 53 | + "members": ["person"], |
| 54 | + "corporate_wealth": {2025: 0}, |
| 55 | + "household_weight": {2025: 1}, |
| 56 | + } |
| 57 | + }, |
| 58 | + } |
| 59 | + ) |
| 60 | + |
| 61 | + corporate_land_value = sim.calculate( |
| 62 | + "corporate_land_value", map_to="household", period=2025 |
| 63 | + ) |
| 64 | + |
| 65 | + assert corporate_land_value[0] == 0 |
0 commit comments