コード例 #1
0
 def test_kill_prey(self):
     """
     Test kill prey. With a high fitness diff the carnivore will always kill the herbivore.
     """
     carn = Carnivore(age=5, weight=30)
     herb_list = [Herbivore(age=100, weight=50) for _ in range(100)]
     mock_sorted_list = [(herb, herb.fitness) for herb in herb_list]
     kill_count = 0
     for _ in mock_sorted_list:
         if carn.kill_prey(mock_sorted_list):
             kill_count += 1
     assert kill_count == 100
コード例 #2
0
 def test_weight_gain(self, reset_carnivore_params, reset_herbivore_params,
                      params):
     """
     Testing weight gain of carnivores. Assuming they have access to more fodder than they
     will eat. Making old heavy herbivores with low fitness. Carnivores should add beta * F
     weight
     Assuming fitness diff is larger than DeltaPhiMax such that the carnivore always kills
     the herbivore.
     """
     carn = Carnivore(age=5, weight=40)
     # number of herbivores
     N = 1000
     herb_list = [Herbivore(age=100, weight=200) for _ in range(N)]
     mock_sorted_list = [(herb, herb.fitness) for herb in herb_list]
     initial_weight = carn.weight
     _ = carn.kill_prey(mock_sorted_list)
     new_weight = carn.weight
     assert new_weight == initial_weight + carn.p["beta"] * carn.p["F"]