class TestDog(unittest.TestCase): def setUp(self): self.name = "Bobik" self.dog = Dog(self.name) def test_dog_actions(self): self.dog.fly() self.assertEqual(100, self.dog.get_energy(), "Dog energy after fly should not change") self.dog.run() self.assertEqual(90, self.dog.get_energy(), "Dog energy after 1 run should be 90") self.dog.swim() self.assertEqual(60, self.dog.get_energy(), "Dog energy after 1 swim should be 60")
def setUp(self): self.animal = Dog("Bobik", run_energy=10, swim_energy=30)
from Cats import Cat from dogs import Dog Baron = Cat("Baron","Man",2) Sem = Cat("Sam","Man",2) Felix = Dog("Felix","Man",2) Linda = Dog("Linda","Girl",2) Muhtar= Dog("Muhtar","Man",0) print("Cats:\n") print(Baron.get_name(),Baron.get_gender(),Baron.get_age()) print(Sem.get_name(),Sem.get_gender(), Sem.get_age()) print("\n------------------------------\n") print("Dogs:\n") print(Felix.get_name(),Felix.get_gender(),Felix.get_age()) print(Linda.get_name(),Linda.get_gender(), Linda.get_age()) print(Muhtar.get_name(),Muhtar.get_gender(), Muhtar.get_age())
from dogs import Dog, English_Dog, Japanese_Dog Dog.description() dog = Dog("犬") print(dog.name) dog.bark() English_Dog.description() buddy = English_Dog() print(buddy.name) buddy.bark() jake = English_Dog("Jake") print(jake.name) jake.bark() Japanese_Dog.description() pochi = Japanese_Dog() print(pochi.name) pochi.bark() shiro = Japanese_Dog("シロ") print(shiro.name) shiro.bark()
from cats import Tiger from dogs import Dog dog_name = "Bobik" dog = Dog(dog_name) dog.say() dog_energy = dog.get_energy() assert dog_energy == 100, "Bad start energy for Bobik" dog.run() dog_energy_after_run = dog.get_energy() assert dog_energy_after_run == 90, "Bad after run energy for Bobik" dog.swim() dog_energy_after_swim = dog.get_energy() assert dog_energy_after_swim == 60, "Bad after swim energy for Bobik" dog.fly() dog_energy_after_fly = dog.get_energy() assert dog_energy_after_fly == 60, "Bad after fly energy for Bobik" tiger_name = "Barsik" tiger = Tiger(tiger_name) tiger.say() tiger_energy = tiger.get_energy() assert tiger_energy == 200, "Bad start energy for Barsik" tiger.run() tiger_energy_after_run = tiger.get_energy() assert tiger_energy_after_run == 180, "Bad after run energy for Barsik" tiger.swim() tiger_energy_after_swim = tiger.get_energy() assert tiger_energy_after_swim == 140, "Bad after swim energy for Barsik" tiger.fly() tiger_energy_after_fly = tiger.get_energy()
def setUp(self): self.name = "Bobik" self.dog = Dog(self.name)
if self.dogs.size() == 0: return self.dequeue_cats() elif self.cats.size() == 0: return self.dequeue_dogs() if self.dogs.peek().value.is_older_than(self.cats.peek().value): return self.dequeue_dogs() else: return self.dequeue_cats() def dequeue_dogs(self): return self.dogs.remove_head() def dequeue_cats(self): return self.cats.remove_head() x = AnimalQueue() x.enqueue(Dog('Dog1')) x.enqueue(Cat('Cat1')) x.enqueue(Cat('Cat2')) x.enqueue(Dog('Dog2')) x.enqueue(Dog('Dog3')) x.enqueue(Dog('Dog4')) x.enqueue(Cat('Cat3')) x.enqueue(Cat('Cat4')) x.enqueue(Dog('Dog5')) print(x.dequeue_cats().value.name) print(x.dequeue().value.name) print(x.dequeue_dogs().value.name)
pound = AnimalShelter() done = False print('Welcome to the animal shelter!') while not done: print('1 - view dogs') print('2 - adopt a dog') print('3 - drop off a found dog') print('4 - exit') choice = input('Choose an option: ') if choice == '1': # view dogs pound.introduce_all_dogs() elif choice == '2': # adopt a dog name = input('Which dog would you like to adopt? (name) ') pound.adopt_dog(name) elif choice == '3': # drop off dog name = input("what is the dog's name?") age = int(input("what is the dog's age?")) color = input("what is the dog's color?") dog = Dog(name, age, color) pound.add_dog(dog) elif choice == '4': done = True else: print('Not a valid option.')