import pytest from phasm.type3.entry import Type3Exception from ..helpers import Suite from ..constants import ALL_INT_TYPES, ALL_FLOAT_TYPES, COMPLETE_INT_TYPES, TYPE_MAP @pytest.mark.integration_test @pytest.mark.parametrize('type_', COMPLETE_INT_TYPES) def test_addition_int(type_): code_py = f""" @exported def testEntry() -> {type_}: return 10 + 3 """ result = Suite(code_py).run_code() assert 13 == result.returned_value assert TYPE_MAP[type_] == type(result.returned_value) @pytest.mark.integration_test @pytest.mark.parametrize('type_', ALL_FLOAT_TYPES) def test_addition_float(type_): code_py = f""" @exported def testEntry() -> {type_}: return 32.0 + 0.125 """ result = Suite(code_py).run_code() assert 32.125 == result.returned_value assert TYPE_MAP[type_] == type(result.returned_value) @pytest.mark.integration_test @pytest.mark.parametrize('type_', COMPLETE_INT_TYPES) def test_subtraction_int(type_): code_py = f""" @exported def testEntry() -> {type_}: return 10 - 3 """ result = Suite(code_py).run_code() assert 7 == result.returned_value assert TYPE_MAP[type_] == type(result.returned_value) @pytest.mark.integration_test @pytest.mark.parametrize('type_', ALL_FLOAT_TYPES) def test_subtraction_float(type_): code_py = f""" @exported def testEntry() -> {type_}: return 100.0 - 67.875 """ result = Suite(code_py).run_code() assert 32.125 == result.returned_value assert TYPE_MAP[type_] == type(result.returned_value) @pytest.mark.integration_test @pytest.mark.skip('TODO: Runtimes return a signed value, which is difficult to test') @pytest.mark.parametrize('type_', ('u32', 'u64')) # FIXME: u8 def test_subtraction_underflow(type_): code_py = f""" @exported def testEntry() -> {type_}: return 10 - 11 """ result = Suite(code_py).run_code() assert 0 < result.returned_value # TODO: Multiplication @pytest.mark.integration_test @pytest.mark.parametrize('type_', COMPLETE_INT_TYPES) def test_call_with_expression_int(type_): code_py = f""" @exported def testEntry() -> {type_}: return helper(10 + 20, 3 + 5) def helper(left: {type_}, right: {type_}) -> {type_}: return left - right """ result = Suite(code_py).run_code() assert 22 == result.returned_value assert TYPE_MAP[type_] == type(result.returned_value) @pytest.mark.integration_test @pytest.mark.parametrize('type_', ALL_FLOAT_TYPES) def test_call_with_expression_float(type_): code_py = f""" @exported def testEntry() -> {type_}: return helper(10.078125 + 90.046875, 63.0 + 5.0) def helper(left: {type_}, right: {type_}) -> {type_}: return left - right """ result = Suite(code_py).run_code() assert 32.125 == result.returned_value assert TYPE_MAP[type_] == type(result.returned_value)