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)
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])
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)
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()))
def testShortInversion(self): # 5: Makes sure inversion works with head length=1 i = Computation.generate(1, 1).next() self.assertEqual(i, i.invert())
def setUp(self): gen = Computation.generate(5, 3) self.chromosome1 = gen.next() self.chromosome2 = gen.next()
def setUp(self): self.chromosome = Computation.generate(self.head, self.genes).next()
def setUp(self): self.gene = KarvaGene([z, z, "y", 3, 4], 1) self.chromosome = Computation([self.gene], 2)
def setUp(self): self.gene = KarvaGene([z,z,'y',3,4], 1) self.chromosome = Computation([self.gene], 2)
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))