Skip to content

Commit

Permalink
test: Add more tests for binary_op
Browse files Browse the repository at this point in the history
  • Loading branch information
xmnlab committed Oct 25, 2023
1 parent 65cb4d9 commit fa255fd
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions tests/test_operators.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
"""Module for testing operators."""
import pytest

from astx.datatypes import Int32Literal
from astx.operators import BinaryOp, UnaryOp

lit_1 = Int32Literal(1)
lit_2 = Int32Literal(2)
lit_3 = Int32Literal(3)


def test_binary_op() -> None:
@pytest.mark.parametrize(
"explicit,implicit",
[
(BinaryOp(op_code="+", lhs=lit_1, rhs=lit_2), lit_1 + lit_2),
(
BinaryOp(
op_code="+",
lhs=lit_1,
rhs=BinaryOp(op_code="+", lhs=lit_2, rhs=lit_3),
),
lit_1 + (lit_2 + lit_3),
),
(
BinaryOp(
op_code="+",
lhs=BinaryOp(op_code="+", lhs=lit_1, rhs=lit_2),
rhs=lit_3,
),
lit_1 + lit_2 + lit_3,
),
],
)
def test_binary_op(explicit: BinaryOp, implicit: BinaryOp) -> None:
"""Test binary operator."""
lit_a = Int32Literal(1)
lit_b = Int32Literal(2)
BinaryOp(op_code="+", lhs=lit_a, rhs=lit_b)
assert implicit.get_struct() == explicit.get_struct()


def test_unary_op() -> None:
Expand Down

0 comments on commit fa255fd

Please sign in to comment.