|
| 1 | +import pytest |
| 2 | +import numpy as np |
| 3 | +from policyengine_uk import CountryTaxBenefitSystem |
| 4 | + |
| 5 | + |
| 6 | +def test_firm_turnover_variable(): |
| 7 | + """Test that firm_turnover variable exists and works correctly.""" |
| 8 | + system = CountryTaxBenefitSystem() |
| 9 | + |
| 10 | + # Check variable exists |
| 11 | + assert "firm_turnover" in system.variables |
| 12 | + |
| 13 | + variable = system.variables["firm_turnover"] |
| 14 | + assert variable.value_type == float |
| 15 | + assert variable.entity.key == "firm" |
| 16 | + assert variable.label == "Firm turnover" |
| 17 | + |
| 18 | + |
| 19 | +def test_firm_vat_registered_variable(): |
| 20 | + """Test that firm_vat_registered variable exists and calculates correctly.""" |
| 21 | + system = CountryTaxBenefitSystem() |
| 22 | + |
| 23 | + # Check variable exists |
| 24 | + assert "firm_vat_registered" in system.variables |
| 25 | + |
| 26 | + variable = system.variables["firm_vat_registered"] |
| 27 | + assert variable.value_type == bool |
| 28 | + assert variable.entity.key == "firm" |
| 29 | + |
| 30 | + |
| 31 | +def test_vat_registration_threshold(): |
| 32 | + """Test VAT registration threshold of £90,000.""" |
| 33 | + from policyengine_uk.simulation import Simulation |
| 34 | + |
| 35 | + # Test firm below threshold |
| 36 | + sim_below = Simulation( |
| 37 | + situation={ |
| 38 | + "firms": {"test_firm": {"firm_turnover": {"2024": 85_000}}}, |
| 39 | + "people": {"p": {}}, |
| 40 | + "benunits": {"b": {"members": ["p"]}}, |
| 41 | + "households": {"h": {"members": ["p"]}}, |
| 42 | + } |
| 43 | + ) |
| 44 | + vat_registered = sim_below.calculate("firm_vat_registered", "2024") |
| 45 | + assert vat_registered[0] == False |
| 46 | + |
| 47 | + # Test firm above threshold |
| 48 | + sim_above = Simulation( |
| 49 | + situation={ |
| 50 | + "firms": {"test_firm": {"firm_turnover": {"2024": 95_000}}}, |
| 51 | + "people": {"p": {}}, |
| 52 | + "benunits": {"b": {"members": ["p"]}}, |
| 53 | + "households": {"h": {"members": ["p"]}}, |
| 54 | + } |
| 55 | + ) |
| 56 | + vat_registered = sim_above.calculate("firm_vat_registered", "2024") |
| 57 | + assert vat_registered[0] == True |
| 58 | + |
| 59 | + |
| 60 | +def test_firm_vat_on_sales(): |
| 61 | + """Test VAT calculation on firm sales.""" |
| 62 | + from policyengine_uk.simulation import Simulation |
| 63 | + |
| 64 | + simulation = Simulation( |
| 65 | + situation={ |
| 66 | + "firms": { |
| 67 | + "firm_1": { |
| 68 | + "firm_turnover": {"2024": 100_000}, |
| 69 | + "firm_standard_rated_supplies": {"2024": 80_000}, |
| 70 | + "firm_reduced_rated_supplies": {"2024": 10_000}, |
| 71 | + "firm_zero_rated_supplies": {"2024": 10_000}, |
| 72 | + } |
| 73 | + }, |
| 74 | + "people": {"p": {}}, |
| 75 | + "benunits": {"b": {"members": ["p"]}}, |
| 76 | + "households": {"h": {"members": ["p"]}}, |
| 77 | + } |
| 78 | + ) |
| 79 | + |
| 80 | + vat_on_sales = simulation.calculate("firm_vat_on_sales", "2024") |
| 81 | + # Standard rate 20% on £80,000 = £16,000 |
| 82 | + # Reduced rate 5% on £10,000 = £500 |
| 83 | + # Zero rate 0% on £10,000 = £0 |
| 84 | + # Total = £16,500 |
| 85 | + expected = 16_500 |
| 86 | + assert np.isclose(vat_on_sales[0], expected, rtol=0.01) |
| 87 | + |
| 88 | + |
| 89 | +def test_firm_net_vat_liability(): |
| 90 | + """Test net VAT liability calculation (output VAT - input VAT).""" |
| 91 | + from policyengine_uk.simulation import Simulation |
| 92 | + |
| 93 | + simulation = Simulation( |
| 94 | + situation={ |
| 95 | + "firms": { |
| 96 | + "firm_1": { |
| 97 | + "firm_turnover": {"2024": 100_000}, |
| 98 | + "firm_standard_rated_supplies": {"2024": 100_000}, |
| 99 | + "firm_vat_on_purchases": {"2024": 5_000}, |
| 100 | + } |
| 101 | + }, |
| 102 | + "people": {"p": {}}, |
| 103 | + "benunits": {"b": {"members": ["p"]}}, |
| 104 | + "households": {"h": {"members": ["p"]}}, |
| 105 | + } |
| 106 | + ) |
| 107 | + |
| 108 | + net_vat = simulation.calculate("firm_net_vat_liability", "2024") |
| 109 | + # Output VAT: 20% of £100,000 = £20,000 |
| 110 | + # Input VAT: £5,000 |
| 111 | + # Net liability: £20,000 - £5,000 = £15,000 |
| 112 | + expected = 15_000 |
| 113 | + assert np.isclose(net_vat[0], expected, rtol=0.01) |
0 commit comments