def test_incorrect_update_behavior(): with pytest.raises(ValueError): Behavior().update_behavior([]) with pytest.raises(ValueError): Behavior().update_behavior({2013: {'_BE_inc': [+0.2]}}) with pytest.raises(ValueError): Behavior().update_behavior({2013: {'_BE_sub': [-0.2]}}) with pytest.raises(ValueError): Behavior().update_behavior({2013: {'_BE_cg': [+0.8]}}) with pytest.raises(ValueError): Behavior().update_behavior({2013: {'_BE_xx': [0.0]}}) with pytest.raises(ValueError): Behavior().update_behavior({2013: {'_BE_xx_cpi': [True]}}) # year in update must be greater than or equal start year with pytest.raises(ValueError): Behavior(start_year=2014).update_behavior({2013: {'_BE_inc': [-0.2]}}) # year in update must be greater than or equal to current year with pytest.raises(ValueError): behv = Behavior(start_year=2014) behv.set_year(2015) behv.update_behavior({2014: {'_BE_inc': [-0.2]}}) # start year greater than start_year + DEFAULT_NUM_YEARS with pytest.raises(ValueError): Behavior().update_behavior({2040: {'_BE_inc': [-0.2]}}) # invalid start year with pytest.raises(ValueError): Behavior().update_behavior({'notayear': {'_BE_inc': [-0.2]}})
def test_correct_update_behavior(): beh = Behavior(start_year=2013) beh.update_behavior({ 2014: { '_BE_sub': [0.5] }, 2015: { '_BE_cg': [-1.2] }, 2016: { '_BE_charity': [[-0.5, -0.5, -0.5]] } }) should_be = np.full((Behavior.DEFAULT_NUM_YEARS, ), 0.5) should_be[0] = 0.0 assert np.allclose(beh._BE_sub, should_be, rtol=0.0) assert np.allclose(beh._BE_inc, np.zeros((Behavior.DEFAULT_NUM_YEARS, )), rtol=0.0) beh.set_year(2017) assert beh.current_year == 2017 assert beh.BE_sub == 0.5 assert beh.BE_inc == 0.0 assert beh.BE_cg == -1.2 assert beh.BE_charity.tolist() == [-0.5, -0.5, -0.5]
def test_future_update_behavior(): behv = Behavior() assert behv.current_year == behv.start_year assert behv.has_response() is False cyr = 2020 behv.set_year(cyr) behv.update_behavior({cyr: {'_BE_cg': [1.0]}}) assert behv.current_year == cyr assert behv.has_response() is True behv.set_year(cyr - 1) assert behv.has_response() is False
def test_future_update_behavior(): behv = Behavior() assert behv.current_year == behv.start_year assert behv.has_response() is False cyr = 2020 behv.set_year(cyr) behv.update_behavior({cyr: {'_BE_cg': [-1.0]}}) assert behv.current_year == cyr assert behv.has_response() is True behv.set_year(cyr - 1) assert behv.has_response() is False
def test_correct_update_behavior(): beh = Behavior(start_year=2013) beh.update_behavior({2014: {"_BE_sub": [0.5]}, 2015: {"_BE_cg": [-1.2]}}) should_be = np.full((Behavior.DEFAULT_NUM_YEARS,), 0.5) should_be[0] = 0.0 assert np.allclose(beh._BE_sub, should_be, rtol=0.0) assert np.allclose(beh._BE_inc, np.zeros((Behavior.DEFAULT_NUM_YEARS,)), rtol=0.0) beh.set_year(2015) assert beh.current_year == 2015 assert beh.BE_sub == 0.5 assert beh.BE_inc == 0.0 assert beh.BE_cg == -1.2
def test_update_behavior(): beh = Behavior(start_year=2013) beh.update_behavior({2014: {'_BE_sub': [0.5]}}) policy = Policy() should_be = np.full((Behavior.DEFAULT_NUM_YEARS,), 0.5) should_be[0] = 0.0 assert np.allclose(beh._BE_sub, should_be, rtol=0.0) assert np.allclose(beh._BE_inc, np.zeros((Behavior.DEFAULT_NUM_YEARS,)), rtol=0.0) beh.set_year(2015) assert beh.current_year == 2015 assert beh.BE_sub == 0.5 assert beh.BE_inc == 0.0
def test_update_behavior(): beh = Behavior(start_year=2013) beh.update_behavior({ 2014: { '_BE_sub': [0.5] }, 2015: { '_BE_CG_per': [1.2] } }) policy = Policy() should_be = np.full((Behavior.DEFAULT_NUM_YEARS, ), 0.5) should_be[0] = 0.0 assert np.allclose(beh._BE_sub, should_be, rtol=0.0) assert np.allclose(beh._BE_inc, np.zeros((Behavior.DEFAULT_NUM_YEARS, )), rtol=0.0) beh.set_year(2015) assert beh.current_year == 2015 assert beh.BE_sub == 0.5 assert beh.BE_inc == 0.0 assert beh.BE_CG_per == 1.2