1 #!/usr/bin/env python 2 3 class C: 4 def f(self): 5 return 1 6 7 class D: 8 def f(self): 9 return 2 10 11 def g(self): 12 return 3 13 14 class E: 15 def f(self): 16 return 4 17 18 def h(self): 19 return 5 20 21 def test_one(obj): 22 obj.f() # C, D, E -> D 23 return obj.g() # D 24 # obj: D 25 26 def test_two(obj, obj2): 27 if obj.f(): # C, D, E (f) 28 obj.g() # D (f, g) 29 # else: 30 # ... # obj: C, D, E (f) 31 # # (f, g) ^ (f) 32 return 2 33 # obj: C, D, E (f) 34 35 def test_new(obj, obj2): 36 if obj.f(): # C, D, E (f) 37 obj = obj2 38 obj.g() # D (g) 39 # else: 40 # ... # obj: C, D, E (f) 41 # # (g) ^ (f) 42 return obj.f() # C, D, E (f) 43 # obj: C, D, E (f) 44 45 def test_neither2(obj, obj2): 46 if 0: 47 obj.g() # D (g) 48 else: 49 obj.f() # C, D, E (f) 50 # # (g) ^ (f) 51 return 4 52 # obj: 53 54 def test_three(obj, obj2): 55 if obj.f(): # C, D, E (f) 56 obj = obj2 57 obj.g() # D (g) 58 else: 59 obj.h() # E (f, h) 60 # # (g) ^ (f, h) 61 return 5 62 # obj: 63 64 c = C() 65 d = D() 66 e = E() 67 result1_3 = test_one(d) 68 result1_2 = test_two(c, d) 69 result2_2 = test_new(c, d) 70 result1_4 = test_neither2(c, d) 71 result1_5 = test_three(e, d) 72 73 # vim: tabstop=4 expandtab shiftwidth=4