示例#1
0
    def test_reproduce_mut0():
        """Test reproduce method when mutation_prob is 0"""

        problem = ContinuousOpt(5, OneMax(), maximize=True,
                                min_val=0, max_val=1, step=1)
        father = np.array([0, 0, 0, 0, 0])
        mother = np.array([1, 1, 1, 1, 1])

        child = problem.reproduce(father, mother, mutation_prob=0)

        assert (len(child) == 5 and sum(child) > 0 and sum(child) < 5)
示例#2
0
    def test_reproduce_mut1_range_gt_step():
        """Test reproduce method when mutation_prob is 1 and range is
        greater than step size"""

        problem = ContinuousOpt(5, OneMax(), maximize=True,
                                min_val=0, max_val=2, step=1)
        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)