Added some more missing test cases for promotable

This commit is contained in:
Johan B.W. de Vries 2025-05-25 14:21:25 +02:00
parent b670bb02ad
commit 2c2a96c8a7

View File

@ -1,3 +1,5 @@
import math
import pytest import pytest
from phasm.type3.entry import Type3Exception from phasm.type3.entry import Type3Exception
@ -23,18 +25,20 @@ def testEntry(x: Foo) -> Baz:
Suite(code_py).run_code() Suite(code_py).run_code()
@pytest.mark.integration_test @pytest.mark.integration_test
def test_promote_ok(): @pytest.mark.parametrize('in_val, exp_val', [
(10.5, 10.5, ),
(9.999999616903162e+35, 9.999999616903162e+35, ),
])
def test_promote_ok(in_val, exp_val):
code_py = """ code_py = """
CONSTANT: f32 = 10.5
@exported @exported
def testEntry() -> f64: def testEntry(x: f32) -> f64:
return promote(CONSTANT) return promote(x)
""" """
result = Suite(code_py).run_code() result = Suite(code_py).run_code(in_val)
assert 10.5 == result.returned_value assert exp_val == result.returned_value
@pytest.mark.integration_test @pytest.mark.integration_test
def test_demote_not_implemented(): def test_demote_not_implemented():
@ -54,15 +58,18 @@ def testEntry(x: Foo) -> Baz:
Suite(code_py).run_code() Suite(code_py).run_code()
@pytest.mark.integration_test @pytest.mark.integration_test
def test_demote_ok(): @pytest.mark.parametrize('in_val, exp_val', [
(10.5, 10.5, ),
(9.999999616903162e+35, 9.999999616903162e+35, ),
(1e39, math.inf, ),
])
def test_demote_ok(in_val, exp_val):
code_py = """ code_py = """
CONSTANT: f64 = 10.5
@exported @exported
def testEntry() -> f32: def testEntry(x: f64) -> f32:
return demote(CONSTANT) return demote(x)
""" """
result = Suite(code_py).run_code() result = Suite(code_py).run_code(in_val)
assert 10.5 == result.returned_value assert exp_val == result.returned_value