def test_two_individuals_are_equal_with_same_lengths_and_genes(self): size = 10 i1 = ListIndividual() [i1.append(i) for i in range(size)] i2 = ListIndividual() [i2.append(i) for i in range(size)] self.assertEqual(i1, i2)
def test_two_individuals_are_different_when_have_different_genes(self): size = 10 i1 = ListIndividual() [i1.append(1) for _ in range(size)] i2 = ListIndividual() [i2.append(2) for _ in range(size)] self.assertNotEqual(i1, i2)
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)
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)
def test_two_individuals_are_equal_with_same_lengths_and_genes(self): size = 10 i1 = ListIndividual() [i1.append(i) for i in range(size)] i2 = ListIndividual() [i2.append(i) for i in range(size)] self.assertEqual(i1, i2)
def test_two_individuals_are_different_when_have_different_genes(self): size = 10 i1 = ListIndividual() [i1.append(1) for _ in range(size)] i2 = ListIndividual() [i2.append(2) for _ in range(size)] self.assertNotEqual(i1, i2)
def test_two_individuals_are_different_when_have_different_lengths(self): i1 = ListIndividual() [i1.append(i) for i in range(10)] i2 = ListIndividual() [i2.append(i) for i in range(100)] self.assertNotEqual(i1, i2)
def test_class_is_pickeable(self): """ Checks if it's pickeable by writing it into a temporary file. """ with TemporaryFile() as f: pickle.dump(ListIndividual(), f)
def test_a_cloned_list_individual_is_different_object_but_equal(self): i1 = ListIndividual() i2 = i1.clone() self.assertEquals(i1, i2) self.assertIsNot(i1, i2)
def test_two_individuals_are_different_when_have_different_lengths(self): i1 = ListIndividual() [i1.append(i) for i in range(10)] i2 = ListIndividual() [i2.append(i) for i in range(100)] self.assertNotEqual(i1, i2)
def test_a_cloned_list_individual_is_different_object_but_equal(self): i1 = ListIndividual() i2 = i1.clone() self.assertEquals(i1, i2) self.assertIsNot(i1, i2)