Exemplo n.º 1
0
 def test_reset_data_checks_validity(self, values):
     dna = ga.FloatDNA([])
     with pytest.raises(ValueError):
         dna.reset(values)
Exemplo n.º 2
0
 def test_subscription_setter(self):
     dna = ga.FloatDNA([0.0] * 20)
     dna[-3:] = [0.1, 0.2, 0.3]
     assert len(dna) == 20
     assert dna[-3:] == pytest.approx([0.1, 0.2, 0.3])
     assert sum(dna) == pytest.approx(0.6)
Exemplo n.º 3
0
 def test_reset_data(self):
     dna = ga.FloatDNA([0.0] * 20)
     dna.reset([0.5] * 20)
     assert len(dna) == 20
     assert dna[7] == 0.5
Exemplo n.º 4
0
 def test_iter(self):
     dna = ga.FloatDNA([1.0] * 20)
     assert len(list(dna)) == 20
Exemplo n.º 5
0
 def test_flip_mutate_at(self):
     dna = ga.FloatDNA([0, 0.1, 0.2, 0.3, 0.4])
     for index in range(5):
         dna.flip_mutate_at(index)
     assert list(dna) == pytest.approx([1.0, 0.9, 0.8, 0.7, 0.6])
Exemplo n.º 6
0
 def test_init_value_is_valid(self, value):
     with pytest.raises(ValueError):
         ga.FloatDNA([value] * 20)
Exemplo n.º 7
0
 def test_init_value(self):
     dna = ga.FloatDNA([1.0] * 20)
     assert all(v == 1.0 for v in dna) is True