def test_predator_eat_snail(self): predator = PredatorFish(PredatorFishPositive.FISH_NAME, PredatorFishPositive.WEIGHT) init_predator_weight = predator.weight snail = Snail('test snail', 1.0) self.assertIs(predator.eat(snail), None) self.assertNotIn(snail, predator.eated) self.assertEqual(predator.weight, init_predator_weight)
def test_predator_eat_water_plant(self): predator = PredatorFish(PredatorFishPositive.FISH_NAME, PredatorFishPositive.WEIGHT) init_predator_weight = predator.weight plant = WaterPlant('test plant', 1.0) self.assertIs(predator.eat(plant), None) self.assertNotIn(plant, predator.eated) self.assertEqual(predator.weight, init_predator_weight)
def test_predator_eat_fish(self): predator = PredatorFish(PredatorFishPositive.FISH_NAME, PredatorFishPositive.WEIGHT) init_predator_weight = predator.weight prey_fish = PreyFish('test fish', 2.0) self.assertIs(predator.eat(prey_fish), prey_fish) self.assertIn(prey_fish, predator.eated) self.assertEqual(predator.weight, init_predator_weight + prey_fish.weight)
def test_predator_eat_predator(self): predator = PredatorFish(PredatorFishPositive.FISH_NAME, PredatorFishPositive.WEIGHT) other_predator = PredatorFish('other predator', 10.0) init_predator_weight = predator.weight self.assertIs(predator.eat(other_predator), None) self.assertNotIn(other_predator, predator.eated) self.assertEqual(predator.weight, init_predator_weight)
def test_snail_eat_predator(self): snail = Snail(SnailPositive.SNAIL_NAME, SnailPositive.MAX_WEIGHT) init_snail_weight = snail.weight predator = PredatorFish('test predator', 10.0) self.assertIs(snail.eat(predator), None) self.assertNotIn(predator, snail.eated) self.assertEqual(snail.weight, init_snail_weight)
def test_fish_eat_predator(self): prey_fish = PreyFish(PreyFishPositive.FISH_NAME, PreyFishPositive.MIN_WEIGHT) init_prey_weight = prey_fish.weight predator_fish = PredatorFish('test predator', 10.0) init_predator_weight = predator_fish.weight self.assertIs(prey_fish.eat(predator_fish), prey_fish) self.assertNotIn(predator_fish, prey_fish.eated) self.assertEqual(prey_fish.weight, init_prey_weight) self.assertIn(prey_fish, predator_fish.eated) self.assertEqual(predator_fish.weight, init_predator_weight + prey_fish.weight)
def test_plant_do_not_eat_inhabitants(self): plant = WaterPlant(WaterPlantPositive.PLANT_NAME, WaterPlantPositive.MIN_WEIGHT) init_plant_weight = plant.weight inhabitants = [ WaterPlant('other plant', WaterPlantPositive.MAX_WEIGHT), PreyFish('test fish', 2.0), PredatorFish('test predator', 10.0), Snail('test snail', 1.0) ] [ self.assertIs(plant.eat(inhabitant), None) for inhabitant in inhabitants ] self.assertEqual(plant.eated, []) self.assertEqual(plant.weight, init_plant_weight)
def test_weight(self): predator_fish = PredatorFish(PredatorFishPositive.FISH_NAME, PredatorFishPositive.WEIGHT) self.assertEqual(predator_fish.weight, PredatorFishPositive.WEIGHT)