test: Cover float comparison ops and WhileStmt float condition#239
test: Cover float comparison ops and WhileStmt float condition#239Jaskirat-s7 wants to merge 2 commits intoarxlang:mainfrom
Conversation
e85c85f to
65e4ce7
Compare
tests/test_binary_op.py
Outdated
| @pytest.mark.parametrize( | ||
| "a_val, b_val, op, expected", | ||
| [ | ||
| (2.0, 3.0, "<=", "le_true"), |
There was a problem hiding this comment.
le is short for "less than or equal" (<=). le_true is printed when the condition holds (2.0 <= 3.0), and le_false
when it doesn't (3.0 <= 2.0). I am happy to rename to something clearer like "yes" / "no" or "lte_pass" / "lte_fail" if preferred.
|
|
||
|
|
||
| @pytest.mark.parametrize("builder_class", [LLVMLiteIR]) | ||
| def test_while_float_condition( |
There was a problem hiding this comment.
we can parametrize it with the basic while functionality, right?
There was a problem hiding this comment.
I have added Float32 and Float64 to test_while_expr. One issue came up during implementation was that the original increment used UnaryOp("++"), which generates an integer add instruction in LLVM IR. When floats were added, this produced add double which is invalid — floats need fadd.
It was fixed by replacing the increment with VariableAssignment + BinaryOp("+"), which correctly dispatches to fadd for floats and add for integers. All 6 types now pass (Int8/Int16/Int32/Int64/Float32/Float64).
tests/test_binary_op.py
Outdated
| module = builder.module() | ||
|
|
||
| cond = astx.BinaryOp( | ||
| op_code=">=", |
There was a problem hiding this comment.
i don't understand why are we hardcoding operator, op should be accepted as parameter
There was a problem hiding this comment.
I have merged all 4 functions (test_binary_op_float_le, test_binary_op_float_ge, test_binary_op_float_eq, test_binary_op_float_ne) into a single test_binary_op_float_comparison that accepts op_code as a parameter. The parametrize list now covers all 4 float comparison operators (<=, >=, ==, !=) with both true and false branches , 8 cases total, all are passing.
tests/test_binary_op.py
Outdated
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "a_val, b_val, expected", |
There was a problem hiding this comment.
@pytest.mark.parametrize(
"a_val, b_val, op, true_label, false_label",
[
(2.0, 3.0, "<=", "le_true", "le_false"),
(3.0, 2.0, ">=", "ge_true", "ge_false"),
(2.0, 2.0, "==", "eq_true", "eq_false"),
(1.0, 2.0, "!=", "ne_true", "ne_false"),
],
)
There was a problem hiding this comment.
i have updated to use your suggested structure exactly. 4 rows with a_val, b_val, op, true_label, false_label as separate parameters. true_label is used in the then block and asserted as output, false_label in the else
block. All 4 cases pass.
fe37ecd to
18f6ff6
Compare
|
@yuvimittal ,I have addressed all 4 review comments in the latest push: 1."what is le here?" — le/ ge/eq/ne are standard abbreviations for "less than or equal", "greater than or equal", etc. I have kept the labels as-is since they're consistent with operator naming conventions. |
18f6ff6 to
8c9278a
Compare
|
@Jaskirat-s7 could you rebase your branch on top of the upstream main please? I tried it here but it has some rebase conflicts to handle |
8c9278a to
6361bca
Compare
…in (rebased from PR arxlang#239) - Replace LLVMLiteIR with Builder as LLVMBuilder (new public API after arxlang#272) - Replace 'from irx.system import PrintExpr' with 'from irx.astx import PrintExpr' - Extend test_while_expr parametrize to cover Float32 and Float64 - Change UnaryOp('++') update to VariableAssignment+BinaryOp('+') for float compat - Add test_while_float_condition: Float32 condition covers fcmp_ordered path - Add test_binary_op_float_comparison: parametrized <=, >=, ==, != with Float32
6361bca to
16675d5
Compare
|
@xmnlab ,i have rebased onto main after #272 landed. The old branch had a chain of fixup commits that conflicted with main's already-updated test files, so I ported the meaningful end-state onto a fresh branch instead. Changes to align with #272: LLVMLiteIR → Builder as LLVMBuilder (new public API) |
PR Title
test(#38): cover float comparison operators and WhileStmt float condition
PR Description
What this PR does
This PR adds 8 new tests across 2 test files that cover previously untested float-type code paths in LLVMLiteIRVisitor. No production code was changed — only test files.
Newly covered compiler paths
Float32 <=fcmp_ordered <=emitted correctlyFloat32 >=fcmp_ordered >=emitted correctlyFloat32 ==fcmp_ordered ==emitted correctlyFloat32 !=fcmp_ordered !=emitted correctlyWhileStmt + Float32i1correctlyAll 5 of these code paths previously had 0% coverage.
Why the overall percentage looks unchanged
The 86% figure is a rounded integer over 1,793 tracked lines. Each additional covered line moves the raw percentage by ~0.056%. Covering 5 new lines moves it from
85.96%→86.24%— both display as86%. The raw missed line count dropped from 211 → 208 in llvmliteir.py.To be transparent: a visible percentage jump to 87% requires covering ~18 lines in one PR. These tests cover 5 lines but specifically target previously untested float comparison semantics.
Why these tests matter (not just coverage)
The original issue (#38) was partly about tests that only verified the compiler didn't crash, not that it produced correct output. Every test in this PR:
2.0 <= 3.0 → "le_true"AND3.0 <= 2.0 → "le_false")For example, test_binary_op_float_le proves that
2.0 <= 3.0produces"le_true"at runtime — not just that it compiles without crashing.Test count
Files changed