Esempio n. 1
0
class MutationTest(unittest.TestCase):
    """Verifies effects of mutation per allele"""

    def setUp(self):
        self.gene = KarvaGene([z, z, "y", 3, 4], 1)
        self.chromosome = Computation([self.gene], 2)

    def testAllMutate(self):
        newchr = self.chromosome.mutate(1.1)
        for allele in newchr:
            self.assertTrue(allele not in [z, z, "y", 3, 4])
        self.assertNotEqual(self.chromosome.id, newchr.id)

    def testNoMutate(self):
        newchr = self.chromosome.mutate(0)
        self.assertEqual(newchr.genes[0], self.gene)
        self.assertEqual(self.chromosome.id, newchr.id)
Esempio n. 2
0
    def testNormalInversion(self):
        x = Computation.generate(2, 1).next()
        y = x.invert()

        # Heads should be switched, tails unaffected
        self.assertEqual(x.genes[0][2:], y.genes[0][2:])
        self.assertEqual(x.genes[0][0], y.genes[0][1])
        self.assertEqual(x.genes[0][1], y.genes[0][0])
Esempio n. 3
0
 def testNormalInversion(self):
     x = Computation.generate(2, 1).next()
     y = x.invert()
     
     # Heads should be switched, tails unaffected
     self.assertEqual(x.genes[0][2:], y.genes[0][2:])
     self.assertEqual(x.genes[0][0],  y.genes[0][1])
     self.assertEqual(x.genes[0][1],  y.genes[0][0])
Esempio n. 4
0
class MutationTest(unittest.TestCase):
    '''Verifies effects of mutation per allele'''
    def setUp(self):
        self.gene = KarvaGene([z,z,'y',3,4], 1)
        self.chromosome = Computation([self.gene], 2)


    def testAllMutate(self):
        newchr = self.chromosome.mutate(1.1)
        for allele in newchr:
            self.assertTrue(allele not in [z,z,'y',3,4])
        self.assertNotEqual(self.chromosome.id, newchr.id)


    def testNoMutate(self):
        newchr = self.chromosome.mutate(0)
        self.assertEqual(newchr.genes[0], self.gene)
        self.assertEqual(self.chromosome.id, newchr.id)
Esempio n. 5
0
    def testMultigenic(self):
        class Foo(object):
            a = b = c = d = e = f = 1

        # Representation
        g1 = KarvaGene(['a', 'b', 'c'], 1)
        g2 = KarvaGene(['d', 'e', 'f'], 1)
        c = Computation([g1, g2], 1)
        self.assertEqual('abcdef', repr(c))

        # Evaluation
        self.assertEqual((1, 1), c(Foo()))
Esempio n. 6
0
 def testShortInversion(self):
     # 5: Makes sure inversion works with head length=1
     i = Computation.generate(1, 1).next()
     self.assertEqual(i, i.invert())
Esempio n. 7
0
 def setUp(self):
     gen = Computation.generate(5, 3)
     self.chromosome1 = gen.next()
     self.chromosome2 = gen.next()
Esempio n. 8
0
 def setUp(self):
     self.chromosome = Computation.generate(self.head, self.genes).next()
Esempio n. 9
0
 def setUp(self):
     self.chromosome = Computation.generate(self.head, self.genes).next()
Esempio n. 10
0
 def setUp(self):
     self.gene = KarvaGene([z, z, "y", 3, 4], 1)
     self.chromosome = Computation([self.gene], 2)
Esempio n. 11
0
 def testShortInversion(self):
     # 5: Makes sure inversion works with head length=1
     i = Computation.generate(1, 1).next()
     self.assertEqual(i, i.invert())
Esempio n. 12
0
 def setUp(self):
     self.gene = KarvaGene([z,z,'y',3,4], 1)
     self.chromosome = Computation([self.gene], 2)
Esempio n. 13
0
 def setUp(self):
     gen = Computation.generate(5, 3)
     self.chromosome1 = gen.next()
     self.chromosome2 = gen.next()
Esempio n. 14
0
 def testShortIS(self):
     # 5: IS transposition should do nothing if head length=1
     i = Computation.generate(1, 1).next()
     self.assertEqual(i, i.transpose_is(1))