Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ class CalculatorTest {
}
}

@Test
fun `test divide function che divide fourteen`() {
val calculator = Calculator()
assertThrows(ArithmeticException::class.java){
calculator.divide(14,0)
}
}
Comment on lines +50 to +56

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Remove redundant test - division by zero is already well covered.

This test is redundant as it follows the exact same pattern as multiple existing tests (lines 35-40, 43-48, 59-64, 67-72) that already verify division by zero throws an ArithmeticException. Testing the same behavior with different dividend values doesn't add meaningful coverage.

Consider consolidating these redundant tests into a single parameterized test:

-    @Test
-    fun `test divide function che divide fourteen`() {
-        val calculator = Calculator()
-        assertThrows(ArithmeticException::class.java){
-            calculator.divide(14,0)
-        }
-    }

Also, the Calculator class shown in the relevant snippets only contains an add method, but these tests reference a divide method. Please verify that the divide method exists in the Calculator class.


🏁 Script executed:

#!/bin/bash
# Verify that the Calculator class has a divide method
ast-grep --pattern 'class Calculator {
  $$$
  fun divide($_, $_) {
    $$$
  }
  $$$
}'

Length of output: 90


🏁 Script executed:

#!/bin/bash
# Search for any divide method definitions in the codebase
rg -n "fun divide" .

Length of output: 126


Consolidate redundant division-by-zero tests into a single parameterized test

The Calculator.divide(a: Int, b: Int): Int method is already defined (see Calculator.kt:9). The new test at CalculatorTest.kt:50-56 duplicates four existing “divide by zero” tests (lines 35-40, 43-48, 59-64, 67-72) without adding new coverage.

• File needing update:

  • app/src/test/java/com/coderabbit/app/calculator/CalculatorTest.kt (lines 50–56)
    • Action: remove the standalone test and replace all five hard-coded tests with one JUnit 5 parameterized test covering all dividend values.

Suggested diff:

-    @Test
-    fun `test divide function che divide fourteen`() {
-        val calculator = Calculator()
-        assertThrows(ArithmeticException::class.java) {
-            calculator.divide(14, 0)
-        }
-    }

Replace with:

import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.ValueSource
import org.junit.jupiter.api.assertThrows

class CalculatorTest {

    @ParameterizedTest(name = "division of {0} by zero throws ArithmeticException")
    @ValueSource(ints = [4, 13, 10, 17, 14])
    fun `divide by zero throws exception`(dividend: Int) {
        val calculator = Calculator()
        assertThrows<ArithmeticException> {
            calculator.divide(dividend, 0)
        }
    }
}

This consolidates all “divide by zero” scenarios into one clean, maintainable test.

🤖 Prompt for AI Agents
In app/src/test/java/com/coderabbit/app/calculator/CalculatorTest.kt around
lines 50 to 56, the divide-by-zero test duplicates four other similar tests
without adding coverage. Remove this standalone test and consolidate all five
divide-by-zero cases into a single JUnit 5 parameterized test using
@ParameterizedTest and @ValueSource annotations to iterate over the dividend
values. This will create one maintainable test method that asserts
ArithmeticException is thrown for each dividend divided by zero.


@Test
fun `test divide function che divide zero`() {
val calculator = Calculator()
Expand Down