def test_get_oldest_animal_cat_and_dogs(): dog1 = dogs.Dog('Honey', 2) dog2 = dogs.Dog('Cody', 12) dog3 = dogs.Dog('Katie', 12) dog4 = dogs.Dog('Gracie', 1) cat1 = cats.Cat('Fonzi', 15) assert 15 == animal_functions.get_oldest_animal( dog1, dog2, dog3, dog4, cat1 ), "The get_oldest_animal function did not return the oldest animal"
def test_get_oldest_animal_float_and_int(): dog1 = dogs.Dog('Honey', 2.3) dog2 = dogs.Dog('Cody', 12) dog3 = dogs.Dog('Katie', 12.1) dog4 = dogs.Dog('Gracie', 1) cat1 = cats.Cat('Fonzi', 3.4) assert 12.1 == animal_functions.get_oldest_animal( dog1, dog2, dog3, dog4, cat1 ), "The get_oldest_animal function had an issue with mixed floats and integers"
def getDogs(): the_dogs = [] # array of Dog objects # the object that we'll use to iterate through the array dgs = db.child("dogs").get() for dog in dgs.each(): one_dog = dogs.Dog() one_dog.setBasics(dog.val()['name'], dog.val()['weight'], dog.val()['breed'], dog.val()['DOB'], dog.key()) for dep in dog.val()['internal_depar']: if dep['name'] == 'NEXT': dep_int_next = dep else: dep_int_last = dep one_dog.setDeparInt(dep_int_last, dep_int_next) for dep in dog.val()['external_depar']: if dep['name'] == 'NEXT': dep_ext_next = dep else: dep_ext_last = dep one_dog.setDeparExt(dep_ext_last, dep_ext_next) for vac in dog.val()['vaccines']: if vac['name'] == 'NEXT': vac_next = vac else: vac_last = vac one_dog.setVaccine(vac_last, vac_next) the_dogs.append(one_dog) return the_dogs
import bosses import dogs your_dog = dogs.Dog ('Wraff') # Instantiate dog, provide sound "Wraff" to constructor his_dog = dogs.Dog ('Howl') # Instantiate dog, provide sound "Howl" to constructor you = bosses.NatureLover () # Create yourself your_friend = bosses.CouchPotato () # Create your friend you.walk (your_dog) # Interface: walk dog, implementation: going out together your_friend.walk (his_dog) # Interface: walk dog, implementation: sending dog out
import random # One of Python's many standard modules import bosses import dogs # Create a list of random bosses humanBeings = [] # Create an emptpy list for index in range (10): # Repeat the following 10 times, index running from 0 to 9 humanBeings.append ( # Append a random HumanBeing to the list by random.choice ((bosses.NatureLover, bosses.CouchPotato)) () # randomly selecting its class ) # and calling its contructor # Let them all walk a new dog with an random sound for humanBeing in humanBeings: # Repeat the following for every humanBeing in the list humanBeing.walk ( # Call implementation of walk method for that type of humanBeing dogs.Dog ( # Construct a new dog as parameter to the walk method random.choice ( # Pick a random sound ('Wraff', 'Wooff', 'Howl', 'Kaii', 'Shreek') # fom this tuple of sounds ) ) )
def test_get_oldest_animal_one_animal_float(): dog1 = dogs.Dog('Honey', 2.1) assert 2.1 == animal_functions.get_oldest_animal( dog1), "The get_oldest_animal function had an issue with a float"
a=getFood() print (a[0].name) print (a[0].type) print (a[0].quantity) print (a[0].company) ''' ''' testing the add functions ''' # test dogs #test dog 1 dog_test = dogs.Dog() dog_test.setBasics("Test-dog", "30", "GermanDog Arlechin", "12/12/2016") vaccine1_last = {"date": "12/01/2017", "name": "blabla"} vaccine1_next = {"date": "12/09/2017", "name": "next"} dog_test.setVaccine(vaccine1_last, vaccine1_next) depint1_last = {"date": "12/04/2017", "name": "blabla"} depint1_next = {"date": "12/07/2017", "name": "next"} depext1_last = {"date": "12/09/2017", "name": "blabla"} depext1_next = {"date": "12/10/2017", "name": "next"} dog_test.setDeparInt(depint1_last, depint1_next) dog_test.setDeparExt(depext1_last, depext1_next)
import dogs import food import alerts ''' asignam date ''' Ino = dogs.Dog() Isi = dogs.Dog() Food_can = food.Food() Food_dry = food.Food() def set_food(): Food_can.setBasics("Hills", "ZD", "can", "1080") Food_dry.setBasics("Hills", "ZD", "dry", "17000") # update the quantity - if the third argument!=0 => total quantity = third argument :) Food_can.updateQuantity(3, 360, 1080) Food_dry.updateQuantity(1, 10000, 17000) set_food() dry_days, dry_estim = food.days_estimator(Food_dry) can_days, can_estim = food.days_estimator(Food_can) Alert_food_canned = alerts.Alert() Alert_food_dry = alerts.Alert() Alert_vaccine_Ino = alerts.Alert() Alert_vaccine_Isi = alerts.Alert()