<s> from pypy . translator . jvm . test . runtest import JvmTest <EOL> class MyClass : <EOL> INCREMENT = <NUM_LIT:1> <EOL> def __init__ ( self , x , y ) : <EOL> self . x = x <EOL> self . y = y <EOL> def compute ( self ) : <EOL> return self . x + self . y <EOL> def compute_and_multiply ( self , factor ) : <EOL> return self . compute ( ) * factor <EOL> def static_meth ( x , y ) : <EOL> return x * y <EOL> static_meth = staticmethod ( static_meth ) <EOL> def class_attribute ( self ) : <EOL> return self . x + self . INCREMENT <EOL> class MyDerivedClass ( MyClass ) : <EOL> INCREMENT = <NUM_LIT:2> <EOL> def __init__ ( self , x , y ) : <EOL> MyClass . __init__ ( self , x + <NUM_LIT:12> , y + <NUM_LIT> ) <EOL> def compute ( self ) : <EOL> return self . x - self . y <EOL> def call_method ( obj ) : <EOL> return obj . compute ( ) <EOL> def init_and_compute ( cls , x , y ) : <EOL> return cls ( x , y ) . compute ( ) <EOL> def nonnull_helper ( lst ) : <EOL> if lst is None : <EOL> return <NUM_LIT:1> <EOL> else : <EOL> return <NUM_LIT:2> <EOL> class TestOO ( JvmTest ) : <EOL> def test_indirect_call ( self ) : <EOL> def f ( ) : <EOL> return <NUM_LIT:1> <EOL> def g ( ) : <EOL> return <NUM_LIT:2> <EOL> def fn ( flag ) : <EOL> if flag : <EOL> x = f <EOL> else : <EOL> x = g <EOL> return x ( ) <EOL> assert self . interpret ( fn , [ True ] ) == <NUM_LIT:1> <EOL> assert self . interpret ( fn , [ False ] ) == <NUM_LIT:2> <EOL> def test_indirect_call_arguments ( self ) : <EOL> def f ( x ) : <EOL> return x + <NUM_LIT:1> <EOL> def g ( x ) : <EOL> return x + <NUM_LIT:2> <EOL> def fn ( flag , n ) : <EOL> if flag : <EOL> x = f <EOL> else : <EOL> x = g <EOL> return x ( n ) <EOL> assert self . interpret ( fn , [ True , <NUM_LIT> ] ) == <NUM_LIT> <EOL> def test_compute ( self ) : <EOL> def fn ( x , y ) : <EOL> obj = MyClass ( x , y ) <EOL> return obj . compute ( ) <EOL> assert self . interpret ( fn , [ <NUM_LIT> , <NUM_LIT> ] ) == fn ( <NUM_LIT> , <NUM_LIT> ) <EOL> def test_compute_multiply ( self ) : <EOL> def fn ( x , y ) : <EOL> obj = MyClass ( x , y ) <EOL> return obj . compute_and_multiply ( <NUM_LIT:2> ) <EOL> assert self . interpret ( fn , [ <NUM_LIT> , <NUM_LIT> ] ) == fn ( <NUM_LIT> , <NUM_LIT> ) <EOL> def test_inheritance ( self ) : <EOL> def fn ( x , y ) : <EOL> obj = MyDerivedClass ( x , y ) <EOL> return obj . compute_and_multiply ( <NUM_LIT:2> ) <EOL> assert self . interpret ( fn , [ <NUM_LIT> , <NUM_LIT> ] ) == fn ( <NUM_LIT> , <NUM_LIT> ) <EOL> def test_liskov ( self ) : <EOL> def fn ( x , y ) : <EOL> base = MyClass ( x , y ) <EOL> derived = MyDerivedClass ( x , y ) <EOL> return call_method ( base ) + call_method ( derived ) <EOL> assert self . interpret ( fn , [ <NUM_LIT> , <NUM_LIT> ] ) == fn ( <NUM_LIT> , <NUM_LIT> ) <EOL> def test_static_method ( self ) : <EOL> def fn ( x , y ) : <EOL> base = MyClass ( x , y ) <EOL> derived = MyDerivedClass ( x , y ) <EOL> return base . static_meth ( x , y ) + derived . static_meth ( x , y ) + MyClass . static_meth ( x , y ) + MyDerivedClass . static_meth ( x , y ) <EOL> assert self . interpret ( fn , [ <NUM_LIT> , <NUM_LIT> ] ) == fn ( <NUM_LIT> , <NUM_LIT> ) <EOL> def test_class_attribute ( self ) : <EOL> def fn ( x , y ) : <EOL> base = MyClass ( x , y ) <EOL> derived = MyDerivedClass ( x , y ) <EOL> return base . class_attribute ( ) + derived . class_attribute ( ) <EOL> assert self . interpret ( fn , [ <NUM_LIT> , <NUM_LIT> ] ) == fn ( <NUM_LIT> , <NUM_LIT> ) <EOL> def test_runtimenew ( self ) : <EOL> def fn ( x , y ) : <EOL> return init_and_compute ( MyClass , x , y ) + init_and_compute ( MyDerivedClass , x , y ) <EOL> assert self . interpret ( fn , [ <NUM_LIT> , <NUM_LIT> ] ) == fn ( <NUM_LIT> , <NUM_LIT> ) <EOL> def test_nonnull ( self ) : <EOL> def fn ( x , y ) : <EOL> return nonnull_helper ( [ ] ) + nonnull_helper ( None ) <EOL> assert self . interpret ( fn , [ <NUM_LIT> , <NUM_LIT> ] ) == fn ( <NUM_LIT> , <NUM_LIT> ) </s>
