Exemple #1
0
def test_pension_env_step_payout_action(do_pay_out):
    env = pension_env.PensionEnv()
    env.reset()
    payout_action = 1
    env.step(payout_action)
    # do_pay_out.assert_called_once()
    assert do_pay_out.call_count == 1
Exemple #2
0
def test_pension_env_step_new_years(mocker):
    # _leave_cdf, _death_cdf, _new_cdf, live_one_year, run_company):
    """Given N Clients, env.year will advance with every Nth step(),
    InsuranceCompany.run_company will be called once per year and
    Client.live_one_year will be called once for each step.
    """
    # Patch Client object to never leave nor join nor die
    mocker.patch.object(pension_env.Client, "_leave_cdf", return_value=1.0)
    mocker.patch.object(pension_env.Client, "_death_cdf", return_value=0.0)
    mocker.patch.object(pension_env.Client, "_new_cdf", return_value=0.0)

    run_company = mocker.patch.object(pension_env.InsuranceCompany,
                                      "run_company")

    env = pension_env.PensionEnv()
    env.reset()
    first_client = env.humans[0]
    second_client = pension_env.Client.maybe_make_client(env, force=True)
    env.humans.append(second_client)
    num_clients = len(env.humans)  # There are 2 clients
    print("num_clients", num_clients)
    mocker.spy(first_client, "live_one_year")
    mocker.spy(second_client, "live_one_year")
    steps = 10
    y0 = env.year  # probably 0
    debit_action = 0
    for _ in range(steps):
        env.step(debit_action)
    y5 = env.year
    expected_year_changes = floor(steps / num_clients)
    #       0 + floor(10 / 2)         ==  5
    assert y0 + expected_year_changes == y5
    assert run_company.call_count == y0 + expected_year_changes
    assert first_client.live_one_year.call_count == steps / num_clients
    assert second_client.live_one_year.call_count == steps / num_clients
Exemple #3
0
def test_pension_env_seed():
    env = pension_env.PensionEnv()
    env.seed(0)
    r1 = pension_env.np_random.choice(range(1000))
    env.seed(0)
    r2 = pension_env.np_random.choice(range(1000))
    assert r1 == r2
Exemple #4
0
def test_pension_env_step_debit_action(do_debit_premium):
    env = pension_env.PensionEnv()
    env.reset()
    debit_action = 0
    env.step(debit_action)
    # do_debit_premium.assert_called_once()
    assert do_debit_premium.call_count == 1
Exemple #5
0
def test_pension_env_reset():
    env = pension_env.PensionEnv()
    env.seed(0)  # PensionEnv start state is currently deterministic, but still
    s1 = env.reset()
    for _ in range(100):
        env.step(env.action_space.sample())
    env.seed(0)
    s2 = env.reset()
    assert (s1 == s2).all()
Exemple #6
0
def test_pension_env_step_before_reset():
    env = pension_env.PensionEnv()
    with pytest.raises(pension_env.PensionEnvError, match="before reset"):
        env.step(env.action_space.sample())
Exemple #7
0
def test_pension_env_close():
    env = pension_env.PensionEnv()
    env.close()
Exemple #8
0
def test_pension_env_render():
    env = pension_env.PensionEnv()
    env.render()
Exemple #9
0
def test_pension_env_observation_shape():
    env = pension_env.PensionEnv()
    s = env.reset()
    assert s.shape[0] == env.observation_space.low.shape[0]
Exemple #10
0
def test_pension_env_companies():
    env = pension_env.PensionEnv()
    assert len(env.companies) == 0
    env.reset()
    assert len(env.companies) > 0
Exemple #11
0
def test_pension_env_init():
    assert pension_env.PensionEnv()