Ejemplo n.º 1
0
def test_feeding_animals_food_that_they_dont_like():
    test = namedtuple('test', 'given tries_to_eat expected_complaint')
    tests = [
        test(given=Owl('buho', weight=2, wing_size=1),
             tries_to_eat=Seed(3),
             expected_complaint='Owl does not eat Seed!'),
        # no test for hens, they eat everything. Glutonous bunch ¯\_(ツ)_/¯
        test(
            given=Tiger('tincho', weight=1, living_region=''),
            tries_to_eat=Seed(3),
            expected_complaint='Tiger does not eat Seed!',
        ),
        test(
            given=Tiger('tincho', weight=1, living_region=''),
            tries_to_eat=Vegetable(3),
            expected_complaint='Tiger does not eat Vegetable!',
        ),
        test(
            given=Tiger('tincho', weight=1, living_region=''),
            tries_to_eat=Fruit(3),
            expected_complaint='Tiger does not eat Fruit!',
        ),
        test(
            given=Dog('kucho', weight=1, living_region=''),
            tries_to_eat=Seed(3),
            expected_complaint='Dog does not eat Seed!',
        ),
        test(
            given=Dog('kucho', weight=1, living_region=''),
            tries_to_eat=Vegetable(3),
            expected_complaint='Dog does not eat Vegetable!',
        ),
        test(
            given=Dog('kucho', weight=1, living_region=''),
            tries_to_eat=Fruit(3),
            expected_complaint='Dog does not eat Fruit!',
        ),
        test(
            given=Cat('malkokote', weight=1, living_region=''),
            tries_to_eat=Seed(3),
            expected_complaint='Cat does not eat Seed!',
        ),
        test(
            given=Cat('malkokote', weight=1, living_region=''),
            tries_to_eat=Fruit(3),
            expected_complaint='Cat does not eat Fruit!',
        ),
    ]

    for bird, food_that_it_doesnt_like, expected_complaint in tests:
        before = bird.weight
        response = bird.feed(food_that_it_doesnt_like)

        assert response == expected_complaint,\
            str(response) + f' for {bird.__class__.__name__} & {food_that_it_doesnt_like.__class__.__name__}'
        assert before == bird.weight
Ejemplo n.º 2
0
def test_feeding_mammals_should_increase_weight():
    test = namedtuple('test', 'given eats expected_weight_increase')
    tests = [
        test(given=Tiger('tincho', weight=3, living_region=''),
             eats=Meat(4),
             expected_weight_increase=4 * 1),
        test(given=Dog('kucho', weight=2, living_region=''),
             eats=Meat(4),
             expected_weight_increase=4 * 0.40),
        test(given=Cat('kotio', weight=2, living_region=''),
             eats=Vegetable(5),
             expected_weight_increase=5 * 0.30),
        test(given=Mouse('misho', weight=2, living_region=''),
             eats=Fruit(5),
             expected_weight_increase=5 * 0.10),
    ]

    for mammal, food, expected_increase in tests:
        before = mammal.weight
        mammal.feed(food)
        after = mammal.weight

        assert after - before == expected_increase, \
            f'{mammal.__class__.__name__} with weight:{before} ate {food.quantity} {food.__class__.__name__}'\
            f' should have gained {expected_increase}, but it gained {after - before}'
Ejemplo n.º 3
0
 def test_first_zero(self):
     owl = Owl("Pip", 10, 10)
     self.assertEqual(str(owl), "Owl [Pip, 10, 10, 0]")
     meat = Meat(4)
     self.assertEqual(owl.make_sound(), "Hoot Hoot")
     owl.feed(meat)
     veg = Vegetable(1)
     owl.feed(veg)
     self.assertEqual(owl.feed(veg), "Owl does not eat Vegetable!")
     self.assertEqual(str(owl), "Owl [Pip, 10, 11.0, 4]")
Ejemplo n.º 4
0
 def test_can_instatiate_birds():
     owl = Owl("Pip", 10, 10)
     print(owl)
     meat = Meat(4)
     print(owl.make_sound())
     owl.feed(meat)
     veg = Vegetable(1)
     print(owl.feed(veg))
     print(owl)
     hen = Hen("Harry", 10, 10)
     veg = Vegetable(3)
     fruit = Fruit(5)
     meat = Meat(1)
     print(hen)
     print(hen.make_sound())
     hen.feed(veg)
     hen.feed(fruit)
     hen.feed(meat)
     print(hen)
Ejemplo n.º 5
0
# first zero test
import unittest
from project.animals.birds import Owl, Hen
from project.animals.mammals import Mouse, Dog, Cat, Tiger
from project.food import Vegetable, Fruit, Meat, Seed

miki = Mouse("Miki", 10, "pakistan")
print(miki)
kartof = Vegetable(3)
meso = Meat(5)
miki.feed(kartof)
print(miki.feed(meso))
print(miki)
gosheto = Dog("goshe", 20, "gruzia")
print(gosheto)
print(gosheto.feed(kartof))
gosheto.feed(meso)
print(gosheto)

owl = Owl("Pip", 10, 10)
print(owl)
meat = Meat(4)
print(owl.make_sound())
owl.feed(meat)
veg = Vegetable(1)
print(owl.feed(veg))
print(owl)
hen = Hen("Harry", 10, 10)
veg = Vegetable(3)
fruit = Fruit(5)
meat = Meat(1)
Ejemplo n.º 6
0
from project.animals.animal import Mammal, Bird, Animal
from project.animals.birds import Hen, Owl
from project.animals.mammals import Mouse, Cat, Dog, Tiger
from project.food import Food, Meat, Vegetable, Fruit, Seed

owl = Mouse("Pip", 10, 10)
print(owl)
meat = Meat(4)
print(owl.make_sound())
print(owl.feed(meat))
veg = Vegetable(3)
fruit = Fruit(4)
seed = Seed(1)
print(owl.feed(veg))
print(owl.feed(seed))
print(owl.feed(fruit))
print(owl)

print("-" * 25)

hen = Hen("Harry", 10, 10)
veg = Vegetable(3)
fruit = Fruit(4)
seed = Seed(1)
meat = Meat(1)
print(hen)
print(hen.make_sound())
hen.feed(veg)
hen.feed(fruit)
hen.feed(seed)
hen.feed(meat)
Ejemplo n.º 7
0
    def make_sound(self):
        return "ROAR!!!"

    def feed(self, food):
        if isinstance(food, Meat):
            self.weight += 1 * food.quantity
            self.food_eaten += food.quantity
            return
        return f"{self.__class__.__name__} does not eat {food.__class__.__name__}!"


owl = Owl("Pip", 10, 10)
print(owl)
meat = Meat(4)
print(owl.make_sound())
owl.feed(meat)
veg = Vegetable(1)
print(owl.feed(veg))
print(owl)
hen = Hen("Harry", 10, 10)
veg = Vegetable(3)
fruit = Fruit(5)
meat = Meat(1)
print(hen)
print(hen.make_sound())
hen.feed(veg)
hen.feed(fruit)
hen.feed(meat)
print(hen)
Ejemplo n.º 8
0
    def __repr__(self):
        return super().__repr__()


class Hen(Bird):

    food_eaten = 0

    def __init__(self, name: str, weight: float, wing_size):
        super().__init__(name, weight, wing_size)

    def make_sound(self):
        return "Cluck"

    def feed(self, food):
        self.food_eaten += food.quantity
        self.weight += food.quantity * 0.35

    def __repr__(self):
        return super().__repr__()


owl = Owl("Pip", 10, 10)
print(owl)
meat = Meat(4)
# print(meat.__class__.__name__)
print(owl.make_sound())
owl.feed(meat)
veg = Vegetable(1)
print(owl.feed(veg))
print(owl)
Ejemplo n.º 9
0
# print(hen)
# print(owl)
# print(mouse)
# print(cat)
# print(dog)
# print(tiger)
#
# print(hen.make_sound())
# print(owl.make_sound())
# print(mouse.make_sound())
# print(cat.make_sound())
# print(dog.make_sound())
# print(tiger.make_sound())
#
veg = Vegetable(5)
meat = Meat(3)
fruit = Fruit(6)
seed = Seed(10)
#
# print(owl.feed(fruit))
# print(mouse.feed(seed))
# print(cat.feed(fruit))
# print(dog.feed(veg))
# print(tiger.feed(seed))
#
# hen.feed(seed)
# owl.feed(meat)
# mouse.feed(fruit)
# cat.feed(veg)
# dog.feed(meat)