Exemplo n.º 1
0
def test_evolve_bad_parent(monkeypatch, capsys):
    org = BadFakeOrganism()
    # noinspection PyTypeChecker
    assert evolve.Evolution(4)._eval_and_print(org, None, None) is None
    assert org.dead is True
    captured = capsys.readouterr()
    assert "Удаляю - ModelError" in captured.out
Exemplo n.º 2
0
def test_setup_needed(monkeypatch):
    params = (None, None, None, None)
    organisms_params = [params, params]
    new_organisms_params = [params, params, params, params]
    fake_population = FakePopulation(organisms_params, new_organisms_params)
    monkeypatch.setattr(evolve, "population", fake_population)
    ev = evolve.Evolution(5)
    assert fake_population.count() == 2
    ev._setup()
    assert fake_population.count() == 5
Exemplo n.º 3
0
def test_setup_needed(mocker):
    """Создается необходимое количество организмов."""
    fake_population = mocker.patch.object(evolve, "population")
    fake_population.count.return_value = 1

    ev = evolve.Evolution(max_population=4)

    ev._setup()

    fake_population.count.assert_called_once_with()
    assert fake_population.create_new_organism.call_count == 3
Exemplo n.º 4
0
def test_setup_not_needed(mocker):
    """Если организмов достаточно, то они не создаются."""
    fake_population = mocker.patch.object(evolve, "population")
    fake_population.count.return_value = 4

    ev = evolve.Evolution(max_population=4)

    ev._setup()

    fake_population.count.assert_called_once_with()
    assert not fake_population.create_new_organism.called
Exemplo n.º 5
0
def test_evolve_parent_win(monkeypatch):
    organisms_params = [(4, 1, 3, 2), (4, 1, 3, 2), (5, 1, 4, 2), (4, 1, 3, 2)]
    new_organisms_params = []
    fake_population = FakePopulation(organisms_params, new_organisms_params)
    monkeypatch.setattr(evolve, "population", fake_population)
    population_ids = list(fake_population._organisms)
    ev = evolve.Evolution(4)
    assert fake_population.count() == 4
    port = Portfolio(pd.Timestamp("2020-04-19"), 0, dict(AKRN=0))
    ev.evolve(port)
    assert fake_population.count() == 4
    assert list(fake_population._organisms) == population_ids