def test_creating_an_empty_population_and_adding_attributes_later_should_be_possible(
):

    # empty population
    a = Population(circus=None, size=0)
    assert a.ids.shape[0] == 0

    # empty attributes
    a.create_attribute("att1")
    a.create_attribute("att2")

    dynamically_created = pd.DataFrame(
        {
            "att1": [1, 2, 3],
            "att2": [11, 12, 13],
        },
        index=["ac1", "ac2", "ac3"])

    a.update(dynamically_created)

    assert a.ids.tolist() == ["ac1", "ac2", "ac3"]
    assert a.get_attribute_values("att1",
                                  ["ac1", "ac2", "ac3"]).tolist() == [1, 2, 3]
    assert a.get_attribute_values(
        "att2", ["ac1", "ac2", "ac3"]).tolist() == [11, 12, 13]
def test_insert_poppulation_value_for_existing_populations_should_update_all_values(
):

    # copy of dummy population that will be updated
    tested_population = Population(circus=None,
                                   size=10,
                                   ids_gen=SequencialGenerator(max_length=1,
                                                               prefix="a_"))
    ages = [10, 20, 40, 10, 100, 98, 12, 39, 76, 23]
    tested_population.create_attribute("age", init_values=ages)
    city = ["a", "b", "b", "a", "d", "e", "r", "a", "z", "c"]
    tested_population.create_attribute("city", init_values=city)

    current = tested_population.get_attribute_values("age",
                                                     ["a_0", "a_7", "a_9"])
    assert current.tolist() == [10, 39, 23]

    update = pd.DataFrame({
        "age": [139, 123],
        "city": ["city_7", "city_9"]
    },
                          index=["a_7", "a_9"])

    tested_population.update(update)

    # we should have the same number of populations
    assert tested_population.ids.shape[0] == 10

    updated_age = tested_population.get_attribute_values(
        "age", ["a_0", "a_7", "a_9"])
    updated_city = tested_population.get_attribute_values(
        "city", ["a_0", "a_7", "a_9"])

    assert updated_age.tolist() == [10, 139, 123]
    assert updated_city.tolist() == ["a", "city_7", "city_9"]