Esempio n. 1
0
    def test_keep_new(self):
        """Make sure we always keep the new organism when specified.
        """
        mutator = SafeFitnessMutation(self.test_mutator, 1.0)

        self.test_mutator.type = "same"
        new_org = mutator.mutate(self.org)
        assert (new_org == self.org), \
               "Did not retain organism for same fitness."

        self.test_mutator.type = "lower"
        new_org = mutator.mutate(self.org)
        assert (new_org.fitness < self.org.fitness), \
               "Did not get new organism when it had lower fitness."

        self.test_mutator.type = "higher"
        new_org = mutator.mutate(self.org)
        assert (new_org.fitness > self.org.fitness), \
                "Did not get new organism under higher fitness conditions."
Esempio n. 2
0
    def test_keep_higher(self):
        """Make sure we always keep the higher fitness.
        """
        mutator = SafeFitnessMutation(self.test_mutator)

        self.test_mutator.type = "same"
        new_org = mutator.mutate(self.org)
        assert (new_org == self.org), \
               "Did not retain organism for same fitness."

        self.test_mutator.type = "lower"
        new_org = mutator.mutate(self.org)
        assert (new_org == self.org), \
               "Did not retain organism when crossover had lower fitness."

        self.test_mutator.type = "higher"
        new_org = mutator.mutate(self.org)
        assert (new_org.fitness > self.org.fitness), \
                "Did not get new organism when it had higher fitness."
Esempio n. 3
0
    def test_keep_new(self):
        """Make sure we always keep the new organism when specified.
        """
        mutator = SafeFitnessMutation(self.test_mutator, 1.0)

        self.test_mutator.type = "same"
        new_org = mutator.mutate(self.org)
        assert (new_org == self.org), \
               "Did not retain organism for same fitness."

        self.test_mutator.type = "lower"
        new_org = mutator.mutate(self.org)
        assert (new_org.fitness < self.org.fitness), \
               "Did not get new organism when it had lower fitness."

        self.test_mutator.type = "higher"
        new_org = mutator.mutate(self.org)
        assert (new_org.fitness > self.org.fitness), \
                "Did not get new organism under higher fitness conditions."
Esempio n. 4
0
    def test_keep_higher(self):
        """Make sure we always keep the higher fitness.
        """
        mutator = SafeFitnessMutation(self.test_mutator)

        self.test_mutator.type = "same"
        new_org = mutator.mutate(self.org)
        assert (new_org == self.org), \
               "Did not retain organism for same fitness."

        self.test_mutator.type = "lower"
        new_org = mutator.mutate(self.org)
        assert (new_org == self.org), \
               "Did not retain organism when crossover had lower fitness."

        self.test_mutator.type = "higher"
        new_org = mutator.mutate(self.org)
        assert (new_org.fitness > self.org.fitness), \
                "Did not get new organism when it had higher fitness."
Esempio n. 5
0
    def test_keep_new(self):
        """Make sure we always keep the new organism when specified.
        """
        mutator = SafeFitnessMutation(self.test_mutator, 1.0)

        self.test_mutator.type = "same"
        new_org = mutator.mutate(self.org)
        self.assertEqual(new_org, self.org,
                         "Did not retain organism for same fitness.")

        self.test_mutator.type = "lower"
        new_org = mutator.mutate(self.org)
        self.assertLess(new_org.fitness, self.org.fitness,
                        "Did not get new organism when it had lower fitness.")

        self.test_mutator.type = "higher"
        new_org = mutator.mutate(self.org)
        self.assertGreater(new_org.fitness, self.org.fitness,
                           "Did not get new organism under higher "
                           "fitness conditions.")
Esempio n. 6
0
    def test_keep_new(self):
        """Make sure we always keep the new organism when specified.
        """
        mutator = SafeFitnessMutation(self.test_mutator, 1.0)

        self.test_mutator.type = "same"
        new_org = mutator.mutate(self.org)
        self.assertEqual(new_org, self.org,
                         "Did not retain organism for same fitness.")

        self.test_mutator.type = "lower"
        new_org = mutator.mutate(self.org)
        self.assertLess(new_org.fitness, self.org.fitness,
                        "Did not get new organism when it had lower fitness.")

        self.test_mutator.type = "higher"
        new_org = mutator.mutate(self.org)
        self.assertGreater(
            new_org.fitness, self.org.fitness,
            "Did not get new organism under higher "
            "fitness conditions.")
Esempio n. 7
0
    def test_keep_higher(self):
        """Make sure we always keep the higher fitness.
        """
        mutator = SafeFitnessMutation(self.test_mutator)

        self.test_mutator.type = "same"
        new_org = mutator.mutate(self.org)
        self.assertEqual(new_org, self.org,
                         "Did not retain organism for same fitness.")

        self.test_mutator.type = "lower"
        new_org = mutator.mutate(self.org)
        self.assertEqual(new_org, self.org,
                         "Did not retain organism when crossover "
                         "had lower fitness.")

        self.test_mutator.type = "higher"
        new_org = mutator.mutate(self.org)
        self.assertGreater(new_org.fitness, self.org.fitness,
                           "Did not get new organism when it had "
                           "higher fitness.")
Esempio n. 8
0
    def test_keep_higher(self):
        """Make sure we always keep the higher fitness.
        """
        mutator = SafeFitnessMutation(self.test_mutator)

        self.test_mutator.type = "same"
        new_org = mutator.mutate(self.org)
        self.assertEqual(new_org, self.org,
                         "Did not retain organism for same fitness.")

        self.test_mutator.type = "lower"
        new_org = mutator.mutate(self.org)
        self.assertEqual(
            new_org, self.org, "Did not retain organism when crossover "
            "had lower fitness.")

        self.test_mutator.type = "higher"
        new_org = mutator.mutate(self.org)
        self.assertGreater(
            new_org.fitness, self.org.fitness,
            "Did not get new organism when it had "
            "higher fitness.")