paul@269 | 1 | #!/usr/bin/env python |
paul@269 | 2 | |
paul@269 | 3 | class C: |
paul@269 | 4 | def f(self): |
paul@269 | 5 | return 1 |
paul@269 | 6 | |
paul@269 | 7 | class D: |
paul@269 | 8 | def f(self): |
paul@269 | 9 | return 2 |
paul@269 | 10 | |
paul@269 | 11 | def g(self): |
paul@269 | 12 | return 3 |
paul@269 | 13 | |
paul@275 | 14 | class E: |
paul@275 | 15 | def f(self): |
paul@275 | 16 | return 4 |
paul@275 | 17 | |
paul@275 | 18 | def h(self): |
paul@275 | 19 | return 5 |
paul@275 | 20 | |
paul@275 | 21 | def test_new(obj, obj2): |
paul@279 | 22 | # obj: C, D, E (f) |
paul@279 | 23 | # obj2: |
paul@275 | 24 | if obj.f(): # C, D, E (f) |
paul@279 | 25 | obj = obj2 # obj: D (g) |
paul@275 | 26 | obj.g() # D (g) |
paul@275 | 27 | # else: |
paul@275 | 28 | # ... # obj: C, D, E (f) |
paul@275 | 29 | # # (g) ^ (f) |
paul@275 | 30 | return obj.f() # C, D, E (f) |
paul@269 | 31 | |
paul@277 | 32 | def test_neither(obj, obj2): |
paul@279 | 33 | # obj: |
paul@279 | 34 | # obj2: |
paul@275 | 35 | if 0: |
paul@275 | 36 | obj.g() # D (g) |
paul@269 | 37 | else: |
paul@275 | 38 | obj.f() # C, D, E (f) |
paul@275 | 39 | # # (g) ^ (f) |
paul@269 | 40 | return 4 |
paul@279 | 41 | |
paul@279 | 42 | def test_new_conditional(obj, obj2): |
paul@275 | 43 | # obj: |
paul@279 | 44 | # obj2: |
paul@275 | 45 | if obj.f(): # C, D, E (f) |
paul@279 | 46 | obj = obj2 # obj: D (g) |
paul@275 | 47 | obj.g() # D (g) |
paul@275 | 48 | else: |
paul@275 | 49 | obj.h() # E (f, h) |
paul@275 | 50 | # # (g) ^ (f, h) |
paul@275 | 51 | return 5 |
paul@269 | 52 | |
paul@269 | 53 | c = C() |
paul@269 | 54 | d = D() |
paul@275 | 55 | e = E() |
paul@275 | 56 | result2_2 = test_new(c, d) |
paul@277 | 57 | result1_4 = test_neither(c, d) |
paul@279 | 58 | result1_5 = test_new_conditional(e, d) |
paul@269 | 59 | |
paul@269 | 60 | # vim: tabstop=4 expandtab shiftwidth=4 |