def test_getSetPrimitiveProperties(): number = Number(20) assert number.value == 20 assert number.double_value == 40 assert Negate(Add(Number(20), Number(10))).value == -30 assert Multiply(Add(Number(5), Number(5)), Number(2)).value == 20 assert Power(Number(3), Number(4)).value == 3 ** 4 assert Power(Number(999), Number(1)).value == 999 assert Power(Number(999), Number(0)).value == 1
def test_testInterfaces(): friendly: IFriendly friendlier: IFriendlier random_number_generator: IRandomNumberGenerator friendly_random_generator: IFriendlyRandomGenerator add = Add(Number(10), Number(20)) friendly = add assert friendly.hello() == "Hello, I am a binary operation. What's your name?" multiply = Multiply(Number(10), Number(30)) friendly = multiply friendlier = multiply random_number_generator = multiply assert friendly.hello() == "Hello, I am a binary operation. What's your name?" assert friendlier.goodbye() == "Goodbye from Multiply!" assert random_number_generator.next() == 89 friendly_random_generator = DoubleTrouble() assert friendly_random_generator.hello() == "world" assert friendly_random_generator.next() == 12 poly = Polymorphism() assert ( poly.say_hello(friendly) == "oh, Hello, I am a binary operation. What's your name?" ) assert poly.say_hello(friendly_random_generator) == "oh, world" assert ( poly.say_hello(SubclassNativeFriendlyRandom()) == "oh, SubclassNativeFriendlyRandom" ) assert poly.say_hello(PureNativeFriendlyRandom()) == "oh, I am a native!"