-
Notifications
You must be signed in to change notification settings - Fork 0
Fix comparer and add its unit tests #2
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
Conversation
WalkthroughThe pull request introduces JUnit 5 dependencies in the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Comparer
Client->>Comparer: compare(a, b)
alt Either a or b is null
Comparer-->>Client: Throw NullPointerException
else Valid inputs provided
Comparer->>Comparer: Validate types and values
alt Numeric Comparison
Comparer-->>Client: Return 1 if a > b, 0 if a == b, -1 if a < b
else Lexicographical Comparison
Comparer-->>Client: Return string-based comparison or throw IllegalArgumentException on mismatch
end
end
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 0
🧹 Nitpick comments (2)
src/test/java/org/alda/common/ComparerTest.java (2)
18-24: Remove debug print statementThere's a debug print statement in the numeric comparison test that should be removed.
- System.out.println(Comparer.compare(100, 100));
46-57: Null value tests should verify exception messagesWhile the null value tests correctly verify that NullPointerExceptions are thrown, they don't validate the exception messages. Consider adding message validation similar to the invalid type tests.
Exception exception1 = assertThrows(NullPointerException.class, () -> Comparer.compare(null, "banana") ); + assertEquals("Both arguments must be either Strings or Numbers.", exception1.getMessage()); Exception exception2 = assertThrows(NullPointerException.class, () -> Comparer.compare(42, null) ); + assertEquals("Both arguments must be either Strings or Numbers.", exception2.getMessage()); Exception exception3 = assertThrows(NullPointerException.class, () -> Comparer.compare(null, null) ); + assertEquals("Both arguments must be either Strings or Numbers.", exception3.getMessage());
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
pom.xml(1 hunks)src/main/java/org/alda/common/Comparer.java(1 hunks)src/test/java/org/alda/common/ComparerTest.java(1 hunks)
🔇 Additional comments (6)
pom.xml (1)
17-30: Dependencies added for JUnit 5 testingThe addition of JUnit 5 dependencies is appropriate for enabling unit testing in the project. Both the API and the engine are included with the correct test scope.
src/main/java/org/alda/common/Comparer.java (2)
53-53: Logic change from>=to>modifies equality handlingThe comparison logic has been changed from
>=to>. This change affects how equality is determined in numeric comparisons. The logic flow still works correctly as equality is handled in the finalreturn 0statement, but it's important to note this behavioral change.
60-63: Added null check improves error handlingThe addition of null checks before the IllegalArgumentException is a good improvement. It provides a more specific exception when null values are encountered and makes the error handling more explicit.
src/test/java/org/alda/common/ComparerTest.java (3)
11-16: Well-structured string comparison testsThe string comparison tests are well-structured and cover the three important cases: less than, greater than, and equality comparisons. This provides good test coverage for the lexicographical comparison functionality.
26-31: Good test coverage for mixed number typesThe mixed number type tests appropriately verify that the Comparer can handle different numeric types correctly, testing both integer-to-float and float-to-integer comparison scenarios.
33-44: Invalid type tests verify exception behaviorThese tests verify that the proper exception is thrown with the correct message when attempting to compare incompatible types. Both String-to-Number and Number-to-String cases are covered.
Summary by CodeRabbit
Bug Fixes
Tests