Skip to content

Commit

Permalink
Merge pull request #24 from tserg/tests/floordiv
Browse files Browse the repository at this point in the history
add more tests for floordiv
  • Loading branch information
charles-cooper authored Feb 20, 2024
2 parents f8cc8c3 + e65f8a8 commit 75a55b2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def test_binop_nested_intermediate_overflow():
code = """
@external
def foo():
a: uint256 = 2**255 * 2 / 10
a: uint256 = 2**255 * 2 // 10
"""
with pytest.raises(OverflowException):
compile_code(code)
4 changes: 2 additions & 2 deletions tests/functional/syntax/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def foo() -> int128[2]:
def foo() -> decimal:
x: int128 = as_wei_value(5, "finney")
y: int128 = block.timestamp + 50
return x / y
return x // y
""",
(
"""
Expand Down Expand Up @@ -106,7 +106,7 @@ def add_record():
def foo() -> uint256:
x: uint256 = as_wei_value(5, "finney")
y: uint256 = block.timestamp + 50 - block.timestamp
return x / y
return x // y
""",
"""
@external
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/syntax/test_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def test1():
@external
@view
def test():
for i: uint256 in range(CONST / 4):
for i: uint256 in range(CONST // 4):
pass
""",
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/syntax/test_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__():
@external
def foo() -> int128:
return self.x / self.y / self.z
return self.x // self.y // self.z
""",
# expansion of public user-defined struct
"""
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/ast/nodes/test_fold_binop_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@example(left=1, right=-1)
@example(left=-1, right=1)
@example(left=-1, right=-1)
@pytest.mark.parametrize("op", "+-*/%")
@pytest.mark.parametrize("op", ["+", "-", "*", "//", "%"])
def test_binop_int128(get_contract, tx_failed, op, left, right):
source = f"""
@external
Expand Down Expand Up @@ -45,7 +45,7 @@ def foo(a: int128, b: int128) -> int128:
@pytest.mark.fuzzing
@settings(max_examples=50)
@given(left=st_uint64, right=st_uint64)
@pytest.mark.parametrize("op", "+-*/%")
@pytest.mark.parametrize("op", ["+", "-", "*", "//", "%"])
def test_binop_uint256(get_contract, tx_failed, op, left, right):
source = f"""
@external
Expand Down Expand Up @@ -94,7 +94,7 @@ def foo(a: uint256, b: uint256) -> uint256:
@settings(max_examples=50)
@given(
values=st.lists(st.integers(min_value=-256, max_value=256), min_size=2, max_size=10),
ops=st.lists(st.sampled_from("+-*/%"), min_size=11, max_size=11),
ops=st.lists(st.sampled_from(["+", "-", "*", "//", "%"]), min_size=11, max_size=11),
)
def test_binop_nested(get_contract, tx_failed, values, ops):
variables = "abcdefghij"
Expand Down
12 changes: 10 additions & 2 deletions tests/unit/semantics/analysis/test_potential_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,17 @@ def test_attribute_not_member_type(build_node, namespace):
get_possible_types_from_node(node)


@pytest.mark.parametrize("op", ["+", "-", "*", "//", "%"])
@pytest.mark.parametrize("left,right", INTEGER_LITERALS)
def test_binop_ints(build_node, namespace, op, left, right):
node = build_node(f"{left}{op}{right}")
with namespace.enter_scope():
get_possible_types_from_node(node)


@pytest.mark.parametrize("op", "+-*/%")
@pytest.mark.parametrize("left,right", INTEGER_LITERALS + DECIMAL_LITERALS)
def test_binop(build_node, namespace, op, left, right):
@pytest.mark.parametrize("left,right", DECIMAL_LITERALS)
def test_binop_decimal(build_node, namespace, op, left, right):
node = build_node(f"{left}{op}{right}")
with namespace.enter_scope():
get_possible_types_from_node(node)
Expand Down

0 comments on commit 75a55b2

Please sign in to comment.