コード例 #1
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]")
コード例 #2
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
コード例 #3
0
def test_feeding_birds_should_increase_weight():
    test = namedtuple('test', 'bird food expected_increase')
    tests = [
        test(Owl('buho', weight=3, wing_size=30),
             food=Meat(3),
             expected_increase=3 * 0.25),
        test(Hen('hencho', weight=2, wing_size=10),
             food=Seed(3),
             expected_increase=3 * 0.35)
    ]

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

        assert after - before == expected_increase, \
            f'{bird.__class__.__name__} with w:{before} ate {food.quantity} {food.__class__.__name__}'\
            f' should have gained {expected_increase}, but it gained {after - before}'
コード例 #4
0
def test_animals_repr():
    test = namedtuple('test', 'given that_eats expected_repr')
    tests = [
        test(
            given=Tiger('tincho', weight=1, living_region='Sudan'),
            that_eats=[Meat(1), Meat(2)],
            expected_repr='Tiger [tincho, 4, Sudan, 3]',
        ),
        test(
            given=Owl('buho', weight=1, wing_size=20),
            that_eats=[Meat(1), Meat(2)],
            expected_repr='Owl [buho, 20, 1.75, 3]',
        ),
    ]

    for animal, food_to_be_eaten, expected in tests:
        for f in food_to_be_eaten:
            animal.feed(f)
        assert repr(animal) == expected, \
            f'wanted "{expected}", got {repr(animal)}'
コード例 #5
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)
コード例 #6
0
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)
print(hen)
print(hen.make_sound())
hen.feed(veg)
hen.feed(fruit)
コード例 #7
0
def test_bird_sounds():
    tests = [(Owl('buho', weight=3, wing_size=30), 'Hoot Hoot'),
             (Hen('hencho', weight=2, wing_size=10), 'Cluck')]
    for bird, expected_sound in tests:
        assert bird.make_sound() == expected_sound, \
            f'({bird.__class__.__name__}) should "{expected_sound}" was "{bird.make_sound()}"'
コード例 #8
0
ファイル: main.py プロジェクト: LachezarKostov/SoftUni
    def test_can_initiate_bird():
        Owl("Buho", weight=2, wing_size=20)
        Hen("Hencho", weight=3, wing_size=30)

        print("test_can_initiate_bird passed")
コード例 #9
0
from project.food import Vegetable, Fruit, Meat, Seed
from project.animals.birds import Hen, Owl
from project.animals.mammals import Mouse, Cat, Dog, Tiger

hen = Hen("Heny", 2, 25)
owl = Owl("Owly", 2.25, 27)
mouse = Mouse("Mousy", 0.6, "basement")
cat = Cat("Catsy", 3.5, "house")
dog = Dog("Doggo", 5, "yard")
tiger = Tiger("Tigeria", 7, "woods")

# 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))