Skip to content

add tests - #7

Merged
NamigGadir merged 1 commit into
mainfrom
tech/test-naming-checks_handled
Jul 29, 2025
Merged

add tests#7
NamigGadir merged 1 commit into
mainfrom
tech/test-naming-checks_handled

Conversation

@NamigGadir

@NamigGadir NamigGadir commented Jul 28, 2025

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Tests
    • Added a new unit test to verify that dividing 14 by 0 correctly throws an error.

@coderabbitai

coderabbitai Bot commented Jul 28, 2025

Copy link
Copy Markdown

Walkthrough

A new unit test method was added to the CalculatorTest class to verify that dividing 14 by 0 in the Calculator class throws an ArithmeticException. This test follows the pattern of existing tests that check division by zero for other values.

Changes

Cohort / File(s) Change Summary
CalculatorTest Division by Zero Test Addition
app/src/test/java/com/coderabbit/app/calculator/CalculatorTest.kt
Added a unit test method to assert that dividing 14 by 0 throws an ArithmeticException.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

  • add tests #6: Adds a similar unit test for division by zero with a different dividend (13), targeting the same class and method.
  • calculator tests #4: Introduces the divide method and its basic test, which this PR extends by adding more division-by-zero cases.
  • Tech/add new tests zeor #5: Adds further division-by-zero tests to CalculatorTest, closely related in purpose and implementation.

Poem

In the warren where numbers hop and play,
A new test checks if errors come our way.
Fourteen divided by zero, the code must shout—
"ArithmeticException!"—no doubt.
With every test, our math grows bright,
Hopping forward, code just right!
🐇➗0

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch tech/test-naming-checks_handled

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e932306 and c2bbd6d.

📒 Files selected for processing (1)
  • app/src/test/java/com/coderabbit/app/calculator/CalculatorTest.kt (1 hunks)

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

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.

@NamigGadir
NamigGadir merged commit 6ea8c9a into main Jul 29, 2025
2 checks passed
This was referenced Jul 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant