-
Notifications
You must be signed in to change notification settings - Fork 33
feat: Add support for >= and <= comparison operators #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Add support for >= and <= comparison operators #72
Conversation
- Added GTE and LTE token types to TokenType enum - Extended Lexer to recognize >= and <= operators - Updated Parser precedence map to include GTE and LTE - Added >= and <= cases to Parser's infix expression handling - Implemented >= and <= evaluation logic in Evaluator - Enables more comprehensive conditional expressions in KidCode
WalkthroughThis PR introduces support for two new relational operators ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
kidcode-core/src/main/java/com/kidcode/core/evaluator/Evaluator.java(1 hunks)kidcode-core/src/main/java/com/kidcode/core/lexer/Lexer.java(1 hunks)kidcode-core/src/main/java/com/kidcode/core/lexer/TokenType.java(1 hunks)kidcode-core/src/main/java/com/kidcode/core/parser/Parser.java(2 hunks)
🔇 Additional comments (4)
kidcode-core/src/main/java/com/kidcode/core/lexer/TokenType.java (1)
18-18: LGTM! Token types added correctly.The new GTE and LTE token types are appropriately grouped with other comparison operators and follow consistent naming conventions.
kidcode-core/src/main/java/com/kidcode/core/lexer/Lexer.java (1)
127-142: LGTM! Lexer tokenization implemented correctly.The two-character operator tokenization for
<=and>=follows the same pattern as the existing==and!=operators, correctly usingpeekChar()for lookahead andreadChar()to consume the second character.kidcode-core/src/main/java/com/kidcode/core/parser/Parser.java (2)
22-23: LGTM! Operator precedence configured correctly.The LTE and GTE operators are correctly assigned the same precedence level as LT and GT, which is the appropriate precedence for comparison operators.
258-258: LGTM! Infix parsing extended correctly.The LTE and GTE operators are correctly included in the infix expression parsing case statement, enabling proper parsing of these new comparison operators.
| case ">=" -> l >= r; | ||
| case "<=" -> l <= r; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
LGTM! Evaluation logic implemented correctly.
The >= and <= operators are correctly implemented for integer comparisons, following the same pattern as the existing > and < operators and returning boolean results as expected.
Please verify that test coverage exists for these new operators. Run the following script to check for existing tests:
🏁 Script executed:
#!/bin/bash
# Description: Search for test files and check if >= and <= operators are tested
# Find test files that test comparison operators
fd -e java -e kt test | xargs rg -l "comparison|operator|evaluator" -i
# Search for tests of comparison operators
rg -n ">=|<=" --type=java --type=kotlin -g "*test*" -g "*Test*" -C 3Length of output: 153
🏁 Script executed:
#!/bin/bash
# Description: Examine test files to identify comparison operator test coverage
# Show the full content of EvaluatorTest.java to see what's tested
echo "=== EvaluatorTest.java content ==="
cat kidcode-core/src/test/java/com/kidcode/core/evaluator/EvaluatorTest.java
# Show the full content of EvaluatorStringOpTest.java for context
echo -e "\n=== EvaluatorStringOpTest.java content ==="
cat kidcode-core/src/test/java/com/kidcode/core/evaluator/EvaluatorStringOpTest.javaLength of output: 3392
🏁 Script executed:
#!/bin/bash
# Description: Comprehensively search for comparison operator tests across entire test directory
# Find ALL test files
echo "=== All test files in evaluator test directory ==="
find kidcode-core/src/test/java -name "*Test*.java" -type f
# Search for any tests that might test comparison operators (>, <, >=, <=, ==, !=)
echo -e "\n=== Searching for comparison operator patterns in all test files ==="
rg -n "testGreater|testLess|testEqual|comparison|operator.*test|test.*operator" --type=java -g "*test*" -i
# Search for InfixExpression with comparison operators in tests
echo -e "\n=== InfixExpression usage in test files ==="
rg -n 'InfixExpression.*[<>=!]' --type=java -g "*test*" -C 2
# Count total test methods in evaluator test files
echo -e "\n=== Evaluator-related test files ==="
find kidcode-core/src/test/java/com/kidcode/core/evaluator -name "*.java" -type f -exec basename {} \;Length of output: 606
Tests required for >= and <= operators.
Verification confirms that no tests exist for the new >= and <= operators (nor for other comparison operators like >, <, ==, !=). Test coverage is critical before these operators can be considered production-ready.
Add test methods to kidcode-core/src/test/java/com/kidcode/core/evaluator/EvaluatorTest.java covering:
-
= with various integer comparisons (true and false cases)
- <= with various integer comparisons (true and false cases)
- Edge cases (equal values, negative numbers)
🤖 Prompt for AI Agents
In kidcode-core/src/main/java/com/kidcode/core/evaluator/Evaluator.java around
lines 205-206, new >= and <= operator handling was added but lacks unit tests;
add tests in
kidcode-core/src/test/java/com/kidcode/core/evaluator/EvaluatorTest.java that
exercise the >= and <= operators with multiple assertions: create separate test
methods forGreaterOrEqual_andLessOrEqual (or similar), include true cases (e.g.,
5 >= 3, 3 >= 3, -1 >= -2; 2 <= 4, 3 <= 3, -3 <= -1) and false cases (e.g., 2 >=
4, -2 >= -1; 5 <= 1, 0 <= -1), and include edge cases with equal values and
negative numbers to ensure behavior is correct; use the same evaluation helper
and assertion style used by existing tests so they run in the test suite.
Summary by CodeRabbit