Exemple #1
0
from duck import Duck
from quack_behavior import SimpleQuacking, AdvancedQuacking, NoQuacking
from fly_behavior import SimpleFlying, JetFlying, NoFlying

if __name__ == "__main__":
    wild_duck = Duck(SimpleFlying, AdvancedQuacking)
    city_duck = Duck(JetFlying, SimpleQuacking)
    rubber_duck = Duck(NoFlying, NoQuacking)

    wild_duck.fly()
    city_duck.fly()
    rubber_duck.fly()
    wild_duck.quack()
    city_duck.quack()
    rubber_duck.quack()
 def test_duckCanQuack(self):
     test_duck = Duck(feathers='green')
     self.assertEqual('Quaaack!', test_duck.quack())
Exemple #3
0
from duck import Duck
from behaviors import quackQuietly, FlyMoon

donald = Duck()

donald.quack()
donald.fly()

donald.setFlyBehavior(FlyMoon)
donald.setQuackBehavior(quackQuietly)

donald.quack()
donald.fly()