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@269 | 14 | def test_one(obj): |
paul@269 | 15 | obj.f() |
paul@269 | 16 | return obj.g() |
paul@269 | 17 | |
paul@269 | 18 | def test_neither(obj, obj2): |
paul@269 | 19 | if obj.f(): |
paul@269 | 20 | obj = obj2 |
paul@269 | 21 | obj.g() |
paul@269 | 22 | return 2 |
paul@269 | 23 | |
paul@269 | 24 | def test_either(obj, obj2): |
paul@269 | 25 | if obj: |
paul@269 | 26 | obj = obj2 |
paul@269 | 27 | obj.g() |
paul@269 | 28 | return obj.f() |
paul@269 | 29 | |
paul@269 | 30 | def test_neither2(obj, obj2): |
paul@269 | 31 | if obj: |
paul@269 | 32 | obj.g() |
paul@269 | 33 | else: |
paul@269 | 34 | obj.f() |
paul@269 | 35 | return 4 |
paul@269 | 36 | |
paul@269 | 37 | c = C() |
paul@269 | 38 | d = D() |
paul@269 | 39 | result1_3 = test_one(d) |
paul@269 | 40 | result1_2 = test_neither(c, d) |
paul@269 | 41 | result2_2 = test_either(c, d) |
paul@269 | 42 | result1_4 = test_neither2(c, d) |
paul@269 | 43 | |
paul@269 | 44 | # vim: tabstop=4 expandtab shiftwidth=4 |