def test_add_axis_on_persons(persons): simulation_builder = SimulationBuilder() simulation_builder.add_person_entity(persons, {'Alicia': {}}) simulation_builder.register_variable('salary', persons) simulation_builder.add_parallel_axis({'count': 3, 'name': 'salary', 'min': 0, 'max': 3000, 'period': '2018-11'}) simulation_builder.expand_axes() assert simulation_builder.get_input('salary', '2018-11') == pytest.approx([0, 1500, 3000]) assert simulation_builder.get_count('persons') == 3 assert simulation_builder.get_ids('persons') == ['Alicia0', 'Alicia1', 'Alicia2']
def test_add_axis_with_group(persons): simulation_builder = SimulationBuilder() simulation_builder.add_person_entity(persons, {'Alicia': {}, '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.add_parallel_axis({'count': 2, 'name': 'salary', 'min': 0, 'max': 3000, 'period': '2018-11', 'index': 1}) simulation_builder.expand_axes() assert simulation_builder.get_count('persons') == 4 assert simulation_builder.get_ids('persons') == ['Alicia0', 'Javier1', 'Alicia2', 'Javier3'] assert simulation_builder.get_input('salary', '2018-11') == pytest.approx([0, 0, 3000, 3000])
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])
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']
def test_numeric_ids(persons): persons_json = {1: {'salary': {}}, 2: {}} simulation_builder = SimulationBuilder() simulation_builder.add_person_entity(persons, persons_json) assert simulation_builder.get_count('persons') == 2 assert simulation_builder.get_ids('persons') == ['1', '2']
def test_add_person_entity(persons): persons_json = {'Alicia': {'salary': {}}, 'Javier': {}} simulation_builder = SimulationBuilder() simulation_builder.add_person_entity(persons, persons_json) assert simulation_builder.get_count('persons') == 2 assert simulation_builder.get_ids('persons') == ['Alicia', 'Javier']