Exemplo n.º 1
0
def test_SimpleProbability_p_always_returns_same_level_p():
    prob = probability_samplers.SimpleProbability(0.45)
    assert prob.p('alfjhlfhlwkhf') == 0.45
    assert prob.p(None) == 0.45
    assert prob.p(Household(1)) == 0.45
    assert prob.p(Person(1)) == 0.45
    assert prob.p(Activity(1)) == 0.45
Exemplo n.º 2
0
def test_HouseholdPolicy_apply_to_delegates_to_modifier_policy_apply_to_for_list_of_probabilities(
        mocker, SmithHousehold):
    mocker.patch.object(modifiers.RemoveActivity, 'apply_to')

    policy = policies.HouseholdPolicy(modifiers.RemoveActivity(
        ['']), [1., probability_samplers.SimpleProbability(1.)])
    household = SmithHousehold

    policy.apply_to(household)

    modifiers.RemoveActivity.apply_to.assert_called_once_with(household)
Exemplo n.º 3
0
def test_verify_probability_check_list_of_probabilities():
    p_list = [
        probability_samplers.HouseholdProbability(0.5),
        probability_samplers.ActivityProbability([''], 0.5),
        probability_samplers.SimpleProbability(0.5), 0.2
    ]
    verified_p_list = probability_samplers.verify_probability(p_list)

    assert p_list[:-1] == verified_p_list[:-1]
    assert isinstance(verified_p_list[-1],
                      probability_samplers.SimpleProbability)
    assert verified_p_list[-1].p(None) == 0.2
Exemplo n.º 4
0
def test_HouseholdPolicy_does_nothing_if_not_selected_for_list_of_probabilities(
        mocker, SmithHousehold):
    mocker.patch.object(modifiers.RemoveActivity, 'apply_to')
    mocker.patch.object(random, 'random', return_value=0.5)

    policy = policies.HouseholdPolicy(modifiers.RemoveActivity(
        ['']), [0.5, probability_samplers.SimpleProbability(0.5)])
    household = SmithHousehold

    policy.apply_to(household)

    assert not modifiers.RemoveActivity.apply_to.called, 'method should not have been called'
Exemplo n.º 5
0
def test_ActivityPolicy_apply_to_delegates_to_modifier_policy_apply_to_for_list_of_probabilities(
        mocker, SmithHousehold):
    mocker.patch.object(modifiers.RemoveActivity, 'apply_to')
    mocker.patch.object(probability_samplers.SimpleProbability,
                        'p',
                        return_value=1)

    policy = policies.ActivityPolicy(modifiers.RemoveActivity(
        ['']), [1., probability_samplers.SimpleProbability(1.)])
    household = SmithHousehold

    policy.apply_to(household)

    assert modifiers.RemoveActivity.apply_to.call_count == 4
Exemplo n.º 6
0
def test_PersonPolicy_apply_to_delegates_to_modifier_policy_apply_to_for_single_probability(
        mocker, SmithHousehold):
    mocker.patch.object(modifiers.RemoveActivity, 'apply_to')
    mocker.patch.object(probability_samplers.SimpleProbability,
                        'sample',
                        return_value=True)

    policy = policies.PersonPolicy(modifiers.RemoveActivity(['']),
                                   probability_samplers.SimpleProbability(1.))
    household = SmithHousehold

    policy.apply_to(household)

    assert modifiers.RemoveActivity.apply_to.call_count == 4