Пример #1
0
def test_add_axis_distributes_memberships(persons, households):
    simulation_builder = SimulationBuilder()
    simulation_builder.add_person_entity(persons, {'Alicia': {}, 'Javier': {}, 'Tom': {}})
    simulation_builder.add_group_entity('persons', ['Alicia', 'Javier', 'Tom'], households, {
        'housea': {'parents': ['Alicia']},
        'houseb': {'parents': ['Tom'], 'children': ['Javier']},
        })
    simulation_builder.register_variable('rent', households)
    simulation_builder.add_parallel_axis({'count': 2, 'name': 'rent', 'min': 0, 'max': 3000, 'period': '2018-11'})
    simulation_builder.expand_axes()
    assert simulation_builder.get_memberships('households') == [0, 1, 1, 2, 3, 3]
Пример #2
0
def test_add_axis_on_persons_distributes_roles(persons, households):
    simulation_builder = SimulationBuilder()
    simulation_builder.add_person_entity(persons, {'Alicia': {}, 'Javier': {}, 'Tom': {}})
    simulation_builder.add_group_entity('persons', ['Alicia', 'Javier', 'Tom'], households, {
        'housea': {'parents': ['Alicia']},
        'houseb': {'parents': ['Tom'], 'children': ['Javier']},
        })
    simulation_builder.register_variable('salary', persons)
    simulation_builder.add_parallel_axis({'count': 2, 'name': 'salary', 'min': 0, 'max': 3000, 'period': '2018-11'})
    simulation_builder.expand_axes()
    assert [role.key for role in simulation_builder.get_roles('households')] == ['parent', 'child', 'parent', 'parent', 'child', 'parent']
Пример #3
0
def test_add_axis_on_households(persons, households):
    simulation_builder = SimulationBuilder()
    simulation_builder.add_person_entity(persons, {'Alicia': {}, 'Javier': {}, 'Tom': {}})
    simulation_builder.add_group_entity('persons', ['Alicia', 'Javier', 'Tom'], households, {
        'housea': {'parents': ['Alicia', 'Javier']},
        'houseb': {'parents': ['Tom']},
        })
    simulation_builder.register_variable('rent', households)
    simulation_builder.add_parallel_axis({'count': 2, 'name': 'rent', 'min': 0, 'max': 3000, 'period': '2018-11'})
    simulation_builder.expand_axes()
    assert simulation_builder.get_count('households') == 4
    assert simulation_builder.get_ids('households') == ['housea0', 'houseb1', 'housea2', 'houseb3']
    assert simulation_builder.get_input('rent', '2018-11') == pytest.approx([0, 0, 3000, 0])
Пример #4
0
def test_finalize_households(tax_benefit_system):
    simulation = Simulation(tax_benefit_system,
                            tax_benefit_system.instantiate_entities())
    simulation_builder = SimulationBuilder()
    simulation_builder.add_group_entity(
        'persons', ['Alicia', 'Javier', 'Sarah', 'Tom'],
        simulation.household.entity, {
            'Household_1': {
                'parents': ['Alicia', 'Javier']
            },
            'Household_2': {
                'parents': ['Tom'],
                'children': ['Sarah']
            },
        })
    simulation_builder.finalize_variables_init(simulation.household)
    tools.assert_near(simulation.household.members_entity_id, [0, 0, 1, 1])
    tools.assert_near(simulation.persons.has_role(entities.Household.PARENT),
                      [True, True, False, True])
Пример #5
0
def test_add_group_entity_loose_syntax(households):
    simulation_builder = SimulationBuilder()
    simulation_builder.add_group_entity(
        'persons', ['Alicia', 'Javier', 'Sarah', '1'], households, {
            'Household_1': {
                'parents': ['Alicia', 'Javier']
            },
            'Household_2': {
                'parents': 1,
                'children': 'Sarah'
            },
        })
    assert simulation_builder.get_count('households') == 2
    assert simulation_builder.get_ids('households') == [
        'Household_1', 'Household_2'
    ]
    assert simulation_builder.get_memberships('households') == [0, 0, 1, 1]
    assert [role.key for role in simulation_builder.get_roles('households')
            ] == ['parent', 'parent', 'child', 'parent']