def test_reproduce_mut1_max2(): """Test reproduce method when mutation_prob is 1 and max_val is 2""" problem = DiscreteOpt(5, OneMax(), maximize=True) father = np.array([0, 0, 0, 0, 0]) mother = np.array([1, 1, 1, 1, 1]) child = problem.reproduce(father, mother, mutation_prob=1) assert (len(child) == 5 and sum(child) > 0 and sum(child) <= 5)
def test_reproduce_mut1_max_gt2(): """Test reproduce method when mutation_prob is 1 and max_val is greater than 2""" problem = DiscreteOpt(5, OneMax(), maximize=True, max_val=3) problem._crossover = OnePointCrossOver(problem) father = np.array([0, 0, 0, 0, 0]) mother = np.array([2, 2, 2, 2, 2]) child = problem.reproduce(father, mother, mutation_prob=1) assert (len(child) == 5 and sum(child) > 0 and sum(child) < 10)