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@279 | 21 | def test_conditional(obj): |
paul@279 | 22 | # obj: C, D, E (f) |
paul@275 | 23 | if obj.f(): # C, D, E (f) |
paul@275 | 24 | obj.g() # D (f, g) |
paul@275 | 25 | # else: |
paul@275 | 26 | # ... # obj: C, D, E (f) |
paul@275 | 27 | # # (f, g) ^ (f) |
paul@275 | 28 | return 2 |
paul@275 | 29 | |
paul@275 | 30 | def test_new(obj, obj2): |
paul@279 | 31 | # obj: C, D, E (f) |
paul@279 | 32 | # obj2: |
paul@275 | 33 | if obj.f(): # C, D, E (f) |
paul@279 | 34 | obj = obj2 # obj: D (g) |
paul@275 | 35 | obj.g() # D (g) |
paul@275 | 36 | # else: |
paul@275 | 37 | # ... # obj: C, D, E (f) |
paul@275 | 38 | # # (g) ^ (f) |
paul@275 | 39 | return obj.f() # C, D, E (f) |
paul@269 | 40 | |
paul@277 | 41 | def test_neither(obj, obj2): |
paul@279 | 42 | # obj: |
paul@279 | 43 | # obj2: |
paul@275 | 44 | if 0: |
paul@275 | 45 | obj.g() # D (g) |
paul@269 | 46 | else: |
paul@275 | 47 | obj.f() # C, D, E (f) |
paul@275 | 48 | # # (g) ^ (f) |
paul@269 | 49 | return 4 |
paul@279 | 50 | |
paul@279 | 51 | def test_new_conditional(obj, obj2): |
paul@275 | 52 | # obj: |
paul@279 | 53 | # obj2: |
paul@275 | 54 | if obj.f(): # C, D, E (f) |
paul@279 | 55 | obj = obj2 # obj: D (g) |
paul@275 | 56 | obj.g() # D (g) |
paul@275 | 57 | else: |
paul@275 | 58 | obj.h() # E (f, h) |
paul@275 | 59 | # # (g) ^ (f, h) |
paul@275 | 60 | return 5 |
paul@269 | 61 | |
paul@269 | 62 | c = C() |
paul@269 | 63 | d = D() |
paul@275 | 64 | e = E() |
paul@279 | 65 | result1_2 = test_conditional(d) |
paul@275 | 66 | result2_2 = test_new(c, d) |
paul@277 | 67 | result1_4 = test_neither(c, d) |
paul@279 | 68 | result1_5 = test_new_conditional(e, d) |
paul@269 | 69 | |
paul@269 | 70 | # vim: tabstop=4 expandtab shiftwidth=4 |