Esempio n. 1
0
    def test_check_genes_are_swapped(self):
        """ Checks that the genes of the individual are swapped.

        For this purpose, two checks are performed. First, the method checks if
        there are the same genes in the mutated individual. Second, it checks
        that only two genes has been moved from their positions.
        """
        genes = '0123456789'
        individual = ListIndividual()
        individual.extend(genes)

        mutated = SwapGenes()(individual, p=1)
        # Are all the genes in the individual?
        [self.assertIn(i, mutated) for i in genes]
        # Are only two misplaced genes?
        different_genes = [i for i, j in zip(mutated, individual) if i != j]
        self.assertEquals(len(different_genes), 2)
Esempio n. 2
0
    def test_check_genes_are_swapped(self):
        """ Checks that the genes of the individual are swapped.

        For this purpose, two checks are performed. First, the method checks if
        there are the same genes in the mutated individual. Second, it checks
        that only two genes has been moved from their positions.
        """
        genes = '0123456789'
        individual = ListIndividual()
        individual.extend(genes)

        mutated = SwapGenes()(individual, p=1)
        # Are all the genes in the individual?
        [self.assertIn(i, mutated) for i in genes]
        # Are only two misplaced genes?
        different_genes = [i for i, j in zip(mutated, individual) if i != j]
        self.assertEquals(len(different_genes), 2)