import numpy as np

from pybalance.genetic import GeneticMatcher
from pybalance.sim import generate_toy_dataset


def test_noduplicates():
    # test that no patient is duplicated in candidate populations generated by generate_offspring()

    m = generate_toy_dataset()
    matcher = GeneticMatcher(m, objective="beta")
    matcher._init_first_generation()
    matcher._check_stopping_conditions()
    for generation in range(3):
        matcher._generate_offspring()
        for pop in matcher.candidate_populations:
            assert len(pop) == len(np.unique(pop))
