예제 #1
0
 def test_inheritance(self):
     ins_cat = Cat();
     ins_horse = Horse();
     
     ins_cat.run()
     ins_horse.run()
     
     ins_cat.eat()
     ins_horse.eat()
예제 #2
0
 def test_instance(self):
     test_a = list()
     test_b = Cat()
     test_c = Horse()
     test_d = Animal()
     
     if isinstance(test_a, list):
         print "test_a is the list type!"
     else:
         print "test_a is not the list type!"
     
     if isinstance(test_b, Cat):
         print "test_is the Cat type!"
     else:
         print "test_b is not the Cat type!"
         
     if isinstance(test_c, Horse):
         print "test_c is the Horse type!"
     else:
         print "test_c is not the Horse type!"
     
     if isinstance(test_d, Animal):
         print "test_d the Animal type!"
     else:
         print "test_d is not the Animal type!"
     
     if isinstance(test_d, Horse):
         print "test_d is the Horse"
     else:
         print "test_d is not the Horse type!"
     
     #Testing the polymorphic
     run_twice(test_b)
     run_twice(test_c)
     run_twice(test_d)
     
     #Like __**__() function just have sepcial use in the python
     #We can mock __len__() function
     #Let the sys know our class have length
     print  test_d.__len__()
     print  test_c.__len__()
     print  test_b.__len__()
     
     #dir()
     #This function will show the all methods and attributes 
     print dir(test_d)