def test_mutate(self): """ Should perform mutation on a subset of the population """ ind0 = np.asarray([1., 2., 3., 4.]) pop = Population(individuals=ind0, fitness=ind0) # should change some values pop.mutate(p=1.) count = 0 for f0, f1 in zip(ind0, pop.individuals): if f0 != f1: count += 1 self.assertGreater(count, 0) # should set fitness for changed individuals to nan self.assertGreater(len(pop.inew), 0) # should handle > 1d ind0 = np.random.rand(50, 10) pop = Population(individuals=ind0, fitness=range(50)) pop.mutate(p=1.) self.assertGreater(len(pop.inew), 0) # should not change shape of individuals self.assertEqual(pop.individuals.shape, ind0.shape)