55from MLC .Population .Population import Population
66from MLC .db .mlc_repository import MLCRepository
77from MLC .Population .Creation .IndividualSelection import IndividualSelection
8+ from MLC .Population .Creation .MixedRampedGauss import MixedRampedGauss
89from MLC .individual .Individual import Individual
910
1011
@@ -14,56 +15,28 @@ def setUpClass(cls):
1415 TestHelper .load_default_configuration ()
1516
1617 def test_add_one_individual (self ):
17- creator = IndividualSelection ({Individual ("1+1" ): [0 , 1 , 2 , 3 , 4 ]})
1818
19- self .__fill_and_assert (fill_creator = creator ,
20- expected_pop_indexes = [1 , 1 , 1 , 1 , 1 ],
21- expected_individuals = {1 : Individual ("1+1" )})
22-
23- def test_add_one_individual_incomplete_population (self ):
24- creator = IndividualSelection ({Individual ("1+1" ): [0 ]})
19+ base_creator = MixedRampedGauss ()
20+ creator = IndividualSelection ({Individual ("1+1" ): [0 , 1 , 2 , 3 , 4 ]}, base_creator )
2521
2622 self .__fill_and_assert (fill_creator = creator ,
2723 expected_pop_indexes = [1 , 1 , 1 , 1 , 1 ],
2824 expected_individuals = {1 : Individual ("1+1" )})
2925
30- def test_add_multiple_individuals (self ):
31- creator = IndividualSelection ({Individual ("1+1" ): [0 , 1 , 2 ],
32- Individual ("2+2" ): [3 , 4 ]})
33-
34- self .__fill_and_assert (fill_creator = creator ,
35- expected_pop_indexes = [1 , 1 , 1 , 2 , 2 ],
36- expected_individuals = {1 : Individual ("1+1" ),
37- 2 : Individual ("2+2" )})
38-
39- def test_add_more_individuals_than_the_gensize (self ):
40- creator = IndividualSelection ({Individual ("1+1" ): [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ]})
41-
42- self .__fill_and_assert (fill_creator = creator ,
43- expected_pop_indexes = [1 , 1 , 1 , 1 , 1 ],
44- expected_individuals = {1 : Individual ("1+1" )})
45-
46- def test_add_individuals_fill_empty_spaces (self ):
47- creator = IndividualSelection ({Individual ("1+1" ): [0 , 4 ],
48- Individual ("2+2" ): [2 ]})
49-
50- self .__fill_and_assert (fill_creator = creator ,
51- expected_pop_indexes = [1 , 1 , 2 , 2 , 1 ],
52- expected_individuals = {1 : Individual ("1+1" ),
53- 2 : Individual ("2+2" )})
54-
55- def test_add_individuals_out_of_gen_not_inserted (self ):
56- creator = IndividualSelection ({Individual ("1+1" ): [0 , 1 , 2 , 3 , 4 ],
57- Individual ("2+2" ): [5 , 6 , 7 ]})
26+ def test_add_one_individual_incomplete_population (self ):
27+ base_creator = MixedRampedGauss ()
28+ creator = IndividualSelection ({Individual ("1+1" ): [0 ]}, base_creator )
5829
5930 self .__fill_and_assert (fill_creator = creator ,
60- expected_pop_indexes = [1 , 1 , 1 , 1 , 1 ],
31+ expected_pop_indexes = [1 ],
6132 expected_individuals = {1 : Individual ("1+1" )})
6233
6334 def __fill_and_assert (self , fill_creator , expected_pop_indexes , expected_individuals ):
6435 with saved (Config .get_instance ()) as config :
6536 Config .get_instance ().set ("POPULATION" , "size" , "5" )
6637 Config .get_instance ().set ("BEHAVIOUR" , "save" , "false" )
38+ from MLC .Log .log import set_logger
39+ set_logger ('testing' )
6740
6841 population = Population (5 , 0 , Config .get_instance (), MLCRepository .make ("" ))
6942 population .fill (fill_creator )
@@ -72,9 +45,6 @@ def __fill_and_assert(self, fill_creator, expected_pop_indexes, expected_individ
7245 # Assert that one Population was added
7346 self .assertEqual (MLCRepository .get_instance ().count_population (), 1 )
7447
75- # Assert that all expected individuals were created
76- self .assertEqual (MLCRepository .get_instance ().count_individual (), len (expected_individuals ))
77-
7848 # Assert that the individuals are in the expected position inside the Population
7949 for position , i in enumerate (expected_pop_indexes ):
8050 expected_individual = expected_individuals [i ]
@@ -83,7 +53,3 @@ def __fill_and_assert(self, fill_creator, expected_pop_indexes, expected_individ
8353
8454 self .assertEqual (expected_individual .get_value (), inserted_individual .get_value ())
8555
86- # Assert all individuals are created
87- created_individuals = [MLCRepository .get_instance ().get_individual (i ).get_value () for i in range (1 , len (expected_individuals )+ 1 )]
88- for _ , individual in expected_individuals .items ():
89- self .assertIn (individual .get_value (), created_individuals )
0 commit comments