def test_delivered_default(self): data = {"parents": ["Alice", "Bob"], "delivered": "October 1st, 2015"} self._set_data(data) b = Baby(self.url) out = b._announce() expected = '' self.assertEqual(out, expected)
def test_announce_due_date(self): data = {"parents": ["Alice", "Bob"], "due_date": "January 1st, 2015"} self._set_data(data) b = Baby(self.url) out = b._announce() expected = 'Alice and Bob are excited to announce ' \ 'the impending arrival of a baby, due on January 1st, 2015' self.assertEqual(out, expected)
def test_announce_name(self): data = {"parents": ["Alice", "Bob"], "name": "Claire"} self._set_data(data) b = Baby(self.url) out = b._announce() expected = 'Alice and Bob are excited to announce ' \ 'the impending arrival of a baby, Claire' self.assertEqual(out, expected)
def test_announce_default(self): data = {"parents": ["Alice", "Bob"]} self._set_data(data) b = Baby(self.url) out = b._announce() expected = 'Alice and Bob are excited to announce ' \ 'the impending arrival of a baby' self.assertEqual(out, expected)
def test_gurgle(self): data = {"parents": ["Alice", "Bob"]} self._set_data(data) b = Baby(self.url) out = b._gurgle() self.assertEqual(out, "gooo gooo")
def test_cry(self): data = {"parents": ["Alice", "Bob"]} self._set_data(data) b = Baby(self.url) out = b._cry() self.assertEqual(out, "waaaaaaaaaaah")
from party_wagon import Party_Wagon from mustang import Mustang from tesla import Tesla """ X- Define 5 of your favorite vehicles X- Move all common properties in your vehicles to a new Vehicle class. X- Create an instance of each vehicle. X- Define a different value for each vehicle's properties. X- Create a drive() method in the Vehicle class. X- Override the drive() method in all the other vehicle classes. Include the vehicle's color in the message (i.e. "The blue Ram drives past. RRrrrrrummbbble!"). X- Create a turn(self, direction) method, and a stop(self) method on Vehicle. Define a basic implementation of each. - Override all three of those methods on some of the vehicles. For example, the stop() method for a plane would be to output the message "The white Cessna rolls to a stop after rolling a mile down the runway." - Make your vehicle instances perform all three behaviors. """ deans_car = Baby("black", 6, "gasoline", "Chevy", "Impala", "Weapons depot in trunk.") wayne_tech = Batmobile("black", 2, "gasoline", "Chevy", "Batmobile", "All of them.") who_you_gonna_call = Ecto1("white", 4, "gasoline", "Futura Duplex", "Cadillac", "Gunner seat, y'all!") turtle_power = Party_Wagon("yellow", 8, "gasoline", "Volkswagen", "Bus", "Pizza launcher.") mustang_sally = Mustang("cherry red", 5, "gasoline", "Ford", "Mustang", 1965) starman = Tesla("red", 5, "electricity", "Tesla", "Roadster", "It's in friggin' space!")
def join(self, papa, on="good_genes", how="inner"): # genes_pairs = mama.genes.zip return Baby(mama.genes)
# inheritance # Class based inheritance lets you specify that one type will contain all of the properties and methods that are defined in another type, without having to duplicate the code in the two source code files. # the parent class is called super class or base class and the child class is called subclass or derived class. # Overriding methods # To override a method in the base class, sub class needs to define a method of same signature. (i.e same method name and same number of parameters as method in base class). from baby import Baby from cat import Cat human_baby = Baby("green", "brown", "weird") cat_baby = Cat("Grey", "brown", "normal") human_baby.about_me() cat_baby.about_me()
def __init__(self, eyeColor, hairColor, toes): Baby.__init__(self, eyeColor, hairColor, toes) self.type = "cat"
def main(): b = Baby(10000, 100, 90, 90) # def __init__(self, money, nice, work, sing): print(b.money) #print(b.sing) print(b.work)
from baby import Baby pinky = Baby("Haritha") pinky.laugh() # prints "ha..ha..ha" pinky.cry() # prints "I am crying" pinky.hi() # prints "Hello I am Haritha" mybaby = Baby()