Add mathematic edge case tests
This commit is contained in:
parent
bce3ed7ba1
commit
312f7949bd
@ -13,4 +13,4 @@ TYPE_MAP = {
|
||||
**{x: float for x in ALL_FLOAT_TYPES},
|
||||
}
|
||||
|
||||
COMPLETE_PRIMITIVE_TYPES = COMPLETE_INT_TYPES + COMPLETE_FLOAT_TYPES
|
||||
COMPLETE_NUMERIC_TYPES = COMPLETE_INT_TYPES + COMPLETE_FLOAT_TYPES
|
||||
|
||||
@ -3,7 +3,7 @@ import pytest
|
||||
from phasm.exceptions import TypingError
|
||||
|
||||
from ..helpers import Suite
|
||||
from ..constants import ALL_INT_TYPES, ALL_FLOAT_TYPES, COMPLETE_INT_TYPES, TYPE_MAP
|
||||
from ..constants import ALL_INT_TYPES, ALL_FLOAT_TYPES, COMPLETE_INT_TYPES, COMPLETE_NUMERIC_TYPES, TYPE_MAP
|
||||
|
||||
@pytest.mark.integration_test
|
||||
@pytest.mark.parametrize('type_', ALL_INT_TYPES)
|
||||
@ -225,6 +225,20 @@ def testEntry() -> {type_}:
|
||||
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
|
||||
@ -255,6 +269,18 @@ def testEntry() -> {type_}:
|
||||
assert 1.25 == result.returned_value
|
||||
assert TYPE_MAP[type_] == type(result.returned_value)
|
||||
|
||||
@pytest.mark.integration_test
|
||||
@pytest.mark.parametrize('type_', COMPLETE_NUMERIC_TYPES)
|
||||
def test_division_zero_let_it_crash(type_):
|
||||
code_py = f"""
|
||||
@exported
|
||||
def testEntry() -> {type_}:
|
||||
return 10 / 0
|
||||
"""
|
||||
|
||||
with pytest.raises(Exception):
|
||||
Suite(code_py).run_code()
|
||||
|
||||
@pytest.mark.integration_test
|
||||
@pytest.mark.parametrize('type_', ['f32', 'f64'])
|
||||
def test_builtins_sqrt(type_):
|
||||
|
||||
@ -3,7 +3,7 @@ import pytest
|
||||
from phasm.exceptions import StaticError, TypingError
|
||||
|
||||
from ..constants import (
|
||||
ALL_FLOAT_TYPES, ALL_INT_TYPES, COMPLETE_INT_TYPES, COMPLETE_PRIMITIVE_TYPES, TYPE_MAP
|
||||
ALL_FLOAT_TYPES, ALL_INT_TYPES, COMPLETE_INT_TYPES, COMPLETE_NUMERIC_TYPES, TYPE_MAP
|
||||
)
|
||||
from ..helpers import Suite
|
||||
|
||||
@ -25,7 +25,7 @@ def testEntry() -> {type_}:
|
||||
|
||||
@pytest.mark.integration_test
|
||||
@pytest.mark.skip('To decide: What to do on out of index?')
|
||||
@pytest.mark.parametrize('type_', COMPLETE_PRIMITIVE_TYPES)
|
||||
@pytest.mark.parametrize('type_', COMPLETE_NUMERIC_TYPES)
|
||||
def test_static_array_indexed(type_):
|
||||
code_py = f"""
|
||||
CONSTANT: {type_}[3] = (24, 57, 80, )
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
|
||||
from ..constants import COMPLETE_PRIMITIVE_TYPES, TYPE_MAP
|
||||
from ..constants import COMPLETE_NUMERIC_TYPES, TYPE_MAP
|
||||
from ..helpers import Suite
|
||||
|
||||
@pytest.mark.integration_test
|
||||
@ -39,7 +39,7 @@ def helper(vector: (u8, u8, u32, u32, u64, u64, )) -> u32:
|
||||
assert 3333 == result.returned_value
|
||||
|
||||
@pytest.mark.integration_test
|
||||
@pytest.mark.parametrize('type_', COMPLETE_PRIMITIVE_TYPES)
|
||||
@pytest.mark.parametrize('type_', COMPLETE_NUMERIC_TYPES)
|
||||
def test_tuple_simple_constructor(type_):
|
||||
code_py = f"""
|
||||
@exported
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user