def testChromosome(self): """Test basic functions of a chromosome. """ c = Chromosome() #Append method c.append(1) c.append(2) #Test string generator self.assertEquals(c.getOrderedElements(), [1, 2]) self.assertEqual(str(c), "1 2") #Test get reverse d = c.getReverse() self.assertEqual(str(c), "1 2") self.assertEqual(str(d), "-2 -1") #Test fuse e = c.fuse(d) self.assertEqual(str(c), "1 2") self.assertEqual(str(d), "-2 -1") self.assertEqual(str(e), "1 2 -2 -1") #Test fuse of null chromosome e = e.fuse(Chromosome()) self.assertEquals(e.getOrderedElements(), [1, 2, -2, -1]) self.assertEqual(str(e), "1 2 -2 -1") #Test random breakpoint for i in xrange(10): f, g = e.getRandomBreakpoint() self.assertEqual(str(f.fuse(g)), "1 2 -2 -1") self.assertEqual(str(d), str(d.clone()))
def testChromosome(self): """Test basic functions of a chromosome. """ c = Chromosome() #Append method c.append(1) c.append(2) #Test string generator self.assertEquals(c.getOrderedElements(), [ 1, 2 ]) self.assertEqual(str(c), "1 2") #Test get reverse d = c.getReverse() self.assertEqual(str(c), "1 2") self.assertEqual(str(d), "-2 -1") #Test fuse e = c.fuse(d) self.assertEqual(str(c), "1 2") self.assertEqual(str(d), "-2 -1") self.assertEqual(str(e), "1 2 -2 -1") #Test fuse of null chromosome e = e.fuse(Chromosome()) self.assertEquals(e.getOrderedElements(), [ 1, 2, -2, -1 ]) self.assertEqual(str(e), "1 2 -2 -1") #Test random breakpoint for i in xrange(10): f, g = e.getRandomBreakpoint() self.assertEqual(str(f.fuse(g)), "1 2 -2 -1") self.assertEqual(str(d), str(d.clone()))