def test_container_equality(self): dna1 = get_a_dna_with_some_structure() dna2 = get_a_dna_with_some_structure() self.assertNotEqual(dna1, dna2) container1 = Container(dna1, 5) container2 = Container(dna2, 5) self.assertEquals(container1, container2) self.assertEquals(container1.__hash__(), container2.__hash__())
def test_container_for_crossover(self): DNA.mutate_percentage = 50 dna_1 = get_a_dna_with_some_structure() dna_2 = get_a_dna_with_some_structure() random.shuffle(dna_2.structure) self.assertNotEqual(dna_1, dna_2) container_1 = Container(dna=dna_1, number_of_buckets=5) container_2 = Container(dna=dna_2, number_of_buckets=5) child_container_1, child_container_2 = container_1.crossover( container_2) self.assertFalse(container_1.__eq__(child_container_1)) self.assertFalse(container_2.__eq__(child_container_2)) self.assertFalse(child_container_1.__eq__(child_container_2))
def test_given_nucleotide_should_create_population_of_requires_size(self): dna = get_a_dna_with_some_structure() nucleotide = Nucleotide(dna.structure) initializer = PopulationInitializer(nucleotide, number_of_buckets_per_container=5) population = initializer.initialize(size=150) self.assertEquals(len(population.containers), 150)
def test_container_to_calculate_fitness(self): dna = get_a_dna_with_some_structure() container = Container(dna, 5) self.assertEquals(container.fitness(), -3200)
def test_container_to_create_buckets(self): dna = get_a_dna_with_some_structure() container = Container(dna=dna, number_of_buckets=5) self.assertEquals(5, len(container.buckets))
def test_dna_mutation_with_hundred_percent_gives_mutated_dna(self): DNA.mutate_percentage = 100 original = get_a_dna_with_some_structure() mutated = original.mutate() self.assertNotEqual(original, mutated)
def test_dna_mutation_with_zero_percent_gives_same_dna(self): DNA.mutate_percentage = 0 original = get_a_dna_with_some_structure() mutated = original.mutate() self.assertEqual(original, mutated)
def test_dna_crossover_to_get_two_children(self): dna1 = get_a_dna_with_some_structure() dna2 = get_a_dna_with_some_structure() random.shuffle(dna2.structure) child_1, child_2 = dna1.crossover(dna2) self.assertNotEqual(child_1, child_2)
def test_dna_crossover_with_itself_gives_same_two_children(self): dna = get_a_dna_with_some_structure() child_1, child_2 = dna.crossover(dna) self.assertEquals(child_1, child_2)
def test_should_create_nucleotide_from_given_jsonfile(self): configure = Configure('test.json') dna = get_a_dna_with_some_structure() nucleotide = Nucleotide(dna.structure) self.assertEquals(configure.nucleotide, nucleotide)
def test_nucleotide_create_n_random_dna(self): dna = get_a_dna_with_some_structure() nucleotide = Nucleotide(score_cards=dna.structure) dnas = nucleotide.create(size=10) self.assertEquals(len(dnas), 10)