Esempio n. 1
0
 def test_feed_herbivore(self, animal_list):
     test_jungle = Jungle()
     test_jungle.herbivores.append(Herbivore(5, 40))
     test_jungle.herbivores.append(Herbivore(50, 4))
     test_jungle.herbivores = (test_jungle.sort_by_fitness(
         test_jungle.herbivores))
     test_jungle.fodder = 15
     a_weight = test_jungle.herbivores[0].weight
     b_weight = test_jungle.herbivores[1].weight
     #  herbivore F is 10 and beta is 0.9
     #  b will eat 10 and gain 10*0.9 weight
     #  a will eat 5 and gain 5*0.9 weight
     a, b = test_jungle.herbivores
     test_jungle.feed_herbivores()
     assert test_jungle.fodder == 0
     #  b will be last because its fitness will be higher
     assert b.weight == b_weight + 10 * 0.9
     assert a.weight == a_weight + 5 * 0.9
Esempio n. 2
0
 def test_feed_herbivores(self):
     jungle = Jungle()
     jungle.herbivores.append(Herbivore())
     jungle.fodder = 1
     jungle.feed_herbivores()
     assert jungle.fodder == 0