Beispiel #1
0
	def test_crossover_returns_two_dna_objects(self):
		d1 = ListDna()
		d2 = ListDna()
		d11, d12 = ListDna.crossover(d1, d2)
		self.assertEqual(type(d11), ListDna)
		self.assertEqual(type(d12), ListDna)
Beispiel #2
0
	def test_crossover_on_itself(self):
		d = ListDna()
		d1, d2 = ListDna.crossover(d,d)
		self.assertEqual([gene.data for gene in d1],
					 	 [gene.data for gene in d2])
Beispiel #3
0
	def test_has_fitness_default_function_attribute(self):
		"""test that by default fitness_function counts sum of True in dna"""
		d = ListDna(data=[True, False, True])
		self.assertNotEqual(d.fitness_function, None)
		self.assertEqual(d.fitness_function(d), 2)
Beispiel #4
0
	def test_crossover_with_one_crossing_point(self):
		d1 = ListDna(data=[1, 1, 1, 1, 1])
		d2 = ListDna(data=[0, 0, 0, 0, 0])
		d11, d12 = ListDna.crossover(d1, d2, [3])
		self.assertEqual([gene.data for gene in d11], [1, 1, 1, 0, 0])
		self.assertEqual([gene.data for gene in d12], [0, 0, 0, 1, 1])