Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/src/main/java/com/coderabbit/app/calculator/Adder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.coderabbit.app.calculator

class Adder {

fun minus(a: Int, b: Int): Int {
return a - b
}
}
Comment on lines +3 to +8

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Critical naming inconsistency: "Adder" class contains subtraction logic.

The class name Adder strongly implies addition functionality, but it contains a minus method that performs subtraction. This is misleading and will confuse other developers.

Consider one of these solutions:

  1. Rename the class to match its functionality:
-class Adder {
+class Subtractor {
  1. Add the subtraction method to the existing Calculator class (recommended based on the existing Calculator class in the codebase):
// In Calculator.kt
fun subtract(a: Int, b: Int): Int {
    return a - b
}

The second approach maintains architectural consistency with the existing Calculator class that already handles add and divide operations.

🤖 Prompt for AI Agents
In app/src/main/java/com/coderabbit/app/calculator/Adder.kt around lines 3 to 8,
the class named Adder contains a subtraction method named minus, which is
misleading. To fix this, either rename the class to reflect subtraction
functionality or, preferably, move the minus method into the existing Calculator
class as a subtract method to maintain consistency with other arithmetic
operations.

13 changes: 13 additions & 0 deletions app/src/test/java/com/coderabbit/app/calculator/AdderTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.coderabbit.app.calculator

import org.junit.Test


class AdderTest {

@Test
fun `test minus function`() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Test naming convention violation.

Based on the repository's testing guidelines, test function names should follow the "given (optional) ... when (required) ... then (required)" convention.

Apply this diff to fix the naming:

-    fun `test minus function`() {
+    fun `when subtracting 3 from 5 then returns 2`() {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fun `test minus function`() {
fun `when subtracting 3 from 5 then returns 2`() {
🤖 Prompt for AI Agents
In app/src/test/java/com/coderabbit/app/calculator/AdderTest.kt at line 9, the
test function name `test minus function` does not follow the required "given ...
when ... then ..." naming convention. Rename the function to clearly describe
the test scenario using this format, ensuring it includes the "when" and "then"
parts to reflect the action and expected outcome.

val adder = Adder()
assert(adder.minus(5, 3) == 2)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use assertEquals for better test reporting.

The assert() function provides minimal feedback on failure. Using assertEquals offers clearer error messages and better test reporting.

Apply this diff to improve the assertion:

+import org.junit.Assert.assertEquals
+
-        assert(adder.minus(5, 3) == 2)
+        assertEquals(2, adder.minus(5, 3))
🤖 Prompt for AI Agents
In app/src/test/java/com/coderabbit/app/calculator/AdderTest.kt at line 11,
replace the use of the generic assert() function with assertEquals(expected,
actual) to improve test failure reporting. Change the assertion to
assertEquals(2, adder.minus(5, 3)) so that test failures provide clearer and
more informative messages.

}
}