Skip to content

Commit

Permalink
Add tests for campaign effects
Browse files Browse the repository at this point in the history
  • Loading branch information
charlotte-avery committed Nov 20, 2024
1 parent 10b360f commit fa4b6f2
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions simulation/tests/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,81 @@ def test_household_ability_to_choose_heat_pump_as_option_depends_on_model_heat_p

assert all(heat_pump in heating_system_options for heat_pump in HEAT_PUMPS)

def test_heat_pump_awareness_updated_after_successful_campaign(
self,
):

model = model_factory(
start_datetime=datetime.datetime(2025, 1, 1),
step_interval=relativedelta(months=1),
interventions=[InterventionType.HEAT_PUMP_CAMPAIGN],
heat_pump_awareness_campaign_date=datetime.datetime(2025, 3, 1),
campaign_target_heat_pump_awareness=1.0,
)
agent = household_factory(is_heat_pump_aware=False)
model.add_agents([agent])

agent_awarness_before_campaign = agent.is_heat_pump_aware
model_awarness_before_campaign = model.heat_pump_awareness_at_timestep

# Expect heat pump awareness to be 0 for first two timesteps, increasing to 1 after campaign date
assert not agent_awarness_before_campaign
assert pytest.approx(model_awarness_before_campaign) == 0.0

model.increment_timestep()
agent.make_decisions(model)
agent_awarness_before_campaign = agent.is_heat_pump_aware
model_awarness_before_campaign = model.heat_pump_awareness_at_timestep

assert not agent_awarness_before_campaign
assert pytest.approx(model_awarness_before_campaign) == 0.0

model.increment_timestep()
agent.make_decisions(model)
agent_awarness_after_campaign = agent.is_heat_pump_aware
model_awarness_after_campaign = model.heat_pump_awareness_at_timestep

assert agent_awarness_after_campaign
assert pytest.approx(model_awarness_after_campaign) == 1.0

# Check agent stays aware for another timestep...
model.increment_timestep()
agent.make_decisions(model)
agent_awarness_after_campaign = agent.is_heat_pump_aware
model_awarness_after_campaign = model.heat_pump_awareness_at_timestep

assert agent_awarness_after_campaign
assert pytest.approx(model_awarness_after_campaign) == 1.0

def test_heat_pump_awareness_does_not_increase_when_campaign_target_is_same_as_current_awareness(
self,
):

model = model_factory(
start_datetime=datetime.datetime(2025, 1, 1),
step_interval=relativedelta(months=1),
interventions=[InterventionType.HEAT_PUMP_CAMPAIGN],
heat_pump_awareness_campaign_date=datetime.datetime(2025, 2, 1),
heat_pump_awareness=0.5,
campaign_target_heat_pump_awareness=0.5,
)
agent = household_factory(is_heat_pump_aware=False)
model.add_agents([agent])

agent_awarness_before_campaign = agent.is_heat_pump_aware
model_awarness_before_campaign = model.heat_pump_awareness_at_timestep

assert not agent_awarness_before_campaign
assert pytest.approx(model_awarness_before_campaign) == 0.0

model.increment_timestep()
agent.make_decisions(model)
agent_awarness_after_campaign = agent.is_heat_pump_aware
model_awarness_after_campaign = model.heat_pump_awareness_at_timestep

assert not agent_awarness_after_campaign
assert pytest.approx(model_awarness_after_campaign) == 0.0


class TestAgentsWithBoilerBan:
def test_households_increasingly_likely_to_rule_out_heating_systems_that_will_be_banned_as_time_to_ban_decreases(
Expand Down

0 comments on commit fa4b6f2

Please sign in to comment.