def test_getAndSetNonPrimitiveProperties(): calc = Calculator() calc.add(3_200_000) calc.neg() calc.curr = Multiply(Number(2), calc.curr) assert calc.value == -6_400_000
def test_maps(): calc2 = Calculator() # Initializer overload (props is optional) calc2.add(10) calc2.add(20) calc2.mul(2) assert len(calc2.operations_map.get("add")) == 2 assert len(calc2.operations_map.get("mul")) == 1 assert calc2.operations_map.get("add")[1].value == 30
def test_unionProperties(): calc3 = Calculator() calc3.union_property = Multiply(Number(9), Number(3)) assert isinstance(calc3.union_property, Multiply) assert calc3.read_union_value() == 9 * 3 calc3.union_property = Power(Number(10), Number(3)) assert isinstance(calc3.union_property, Power) assert calc3.read_union_value() == 10 ** 3
def test_exceptions(): calc3 = Calculator(initial_value=20, maximum_value=30) calc3.add(3) assert calc3.value == 23 with pytest.raises(Exception): calc3.add(10) calc3.max_value = 40 calc3.add(10) assert calc3.value == 33
def test_getAndSetEnumValues(): calc = Calculator() calc.add(9) calc.pow(3) CompositeOperation = composition.CompositeOperation assert calc.string_style == CompositeOperation.CompositionStringStyle.NORMAL calc.string_style = CompositeOperation.CompositionStringStyle.DECORATED assert calc.string_style == CompositeOperation.CompositionStringStyle.DECORATED assert calc.to_string() == "<<[[{{(((1 * (0 + 9)) * (0 + 9)) * (0 + 9))}}]]>>"
def test_callMethods(): calc = Calculator() calc.add(10) assert calc.value == 10 calc.mul(2) assert calc.value == 20 calc.pow(5) assert calc.value == 20 ** 5 calc.neg() assert calc.value == -3_200_000
def test_subclassing(): calc = Calculator() calc.curr = AddTen(33) calc.neg() assert calc.value == -43
def test_undefinedAndNull(): calc = Calculator() assert calc.max_value is None calc.max_value = None
def test_unmarshallIntoAbstractType(): calc = Calculator() calc.add(120) assert calc.curr.value == 120
def test_createObjectAndCtorOverloads(): Calculator() Calculator(maximum_value=10)