Skip to content

Add test cases for Fibonacci calculation#6

Open
jasonwang82 wants to merge 2 commits intomasterfrom
add-test-cases
Open

Add test cases for Fibonacci calculation#6
jasonwang82 wants to merge 2 commits intomasterfrom
add-test-cases

Conversation

@jasonwang82
Copy link
Owner

@jasonwang82 jasonwang82 commented Jan 3, 2025

User description

Add new test cases to FibonacciRestServiceApplicationTests.java to cover additional scenarios and edge cases for the Fibonacci calculation.

  • Add test case to verify Fibonacci calculation for input 0
  • Add test case to verify Fibonacci calculation for input 1
  • Add test case to verify Fibonacci calculation for input 2
  • Add test case to verify Fibonacci calculation for input 10
  • Add test case to verify Fibonacci calculation for input 20

For more details, open the Copilot Workspace session.


PR Type

Tests


Description

  • Added new test cases for Fibonacci calculation.

  • Covered edge cases for inputs 0, 1, and 2.

  • Included tests for larger inputs like 10 and 20.

  • Ensured proper response validation for each test case.


Changes walkthrough 📝

Relevant files
Tests
FibonacciRestServiceApplicationTests.java
Added test cases for various Fibonacci inputs                       

src/test/java/com/emc/test/FibonacciRestServiceApplicationTests.java

  • Added test case for Fibonacci calculation with input 0.
  • Added test case for Fibonacci calculation with input 1.
  • Added test case for Fibonacci calculation with input 2.
  • Added test case for Fibonacci calculation with input 10.
  • Added test case for Fibonacci calculation with input 20.
  • +34/-0   

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Add new test cases to `FibonacciRestServiceApplicationTests.java` to cover additional scenarios and edge cases for the Fibonacci calculation.
    
    * Add test case to verify Fibonacci calculation for input 0
    * Add test case to verify Fibonacci calculation for input 1
    * Add test case to verify Fibonacci calculation for input 2
    * Add test case to verify Fibonacci calculation for input 10
    * Add test case to verify Fibonacci calculation for input 20
    
    ---
    
    For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/jasonwang82/FibonacciRestful?shareId=XXXX-XXXX-XXXX-XXXX).
    @bolt-new-by-stackblitz
    Copy link

    Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

    @ant-codespaces
    Copy link

    ant-codespaces bot commented Jan 3, 2025

    Run and Debug this pull request in Codespaces

    @qodo-code-review
    Copy link

    Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Test Validation

    The test cases validate the exact byte array output including trailing spaces. Consider using string comparison or trimming the output for more robust tests.

    			.andExpect(content().bytes("0 ".getBytes()));
    }
    
    @Test
    public void verifyFibonacciForInput1() throws Exception {
    	restFibonacciMvc.perform(get("/v1/rest/fibonacci/1"))
    			.andExpect(status().isOk())
    			.andExpect(content().bytes("0 1 ".getBytes()));
    }
    
    @Test
    public void verifyFibonacciForInput2() throws Exception {
    	restFibonacciMvc.perform(get("/v1/rest/fibonacci/2"))
    			.andExpect(status().isOk())
    			.andExpect(content().bytes("0 1 1 ".getBytes()));
    }
    
    @Test
    public void verifyFibonacciForInput10() throws Exception {
    	restFibonacciMvc.perform(get("/v1/rest/fibonacci/10"))
    			.andExpect(status().isOk())
    			.andExpect(content().bytes("0 1 1 2 3 5 8 13 21 34 ".getBytes()));
    }
    
    @Test
    public void verifyFibonacciForInput20() throws Exception {
    	restFibonacciMvc.perform(get("/v1/rest/fibonacci/20"))
    			.andExpect(status().isOk())
    			.andExpect(content().bytes("0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 ".getBytes()));
    Missing Tests

    No test cases for negative numbers or large inputs that could cause integer overflow. Consider adding boundary test cases.

    @Test
    public void verifyFibonacciForInput0() throws Exception {
    	restFibonacciMvc.perform(get("/v1/rest/fibonacci/0"))
    			.andExpect(status().isOk())
    			.andExpect(content().bytes("0 ".getBytes()));
    }
    
    @Test
    public void verifyFibonacciForInput1() throws Exception {
    	restFibonacciMvc.perform(get("/v1/rest/fibonacci/1"))
    			.andExpect(status().isOk())
    			.andExpect(content().bytes("0 1 ".getBytes()));
    }
    
    @Test
    public void verifyFibonacciForInput2() throws Exception {
    	restFibonacciMvc.perform(get("/v1/rest/fibonacci/2"))
    			.andExpect(status().isOk())
    			.andExpect(content().bytes("0 1 1 ".getBytes()));
    }
    
    @Test
    public void verifyFibonacciForInput10() throws Exception {
    	restFibonacciMvc.perform(get("/v1/rest/fibonacci/10"))
    			.andExpect(status().isOk())
    			.andExpect(content().bytes("0 1 1 2 3 5 8 13 21 34 ".getBytes()));
    }
    
    @Test
    public void verifyFibonacciForInput20() throws Exception {
    	restFibonacciMvc.perform(get("/v1/rest/fibonacci/20"))
    			.andExpect(status().isOk())
    			.andExpect(content().bytes("0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 ".getBytes()));
    }

    @qodo-code-review
    Copy link

    qodo-code-review bot commented Jan 3, 2025

    Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add test coverage for large input values to prevent integer overflow issues

    Add test case for large input values to verify handling of potential integer
    overflow scenarios

    src/test/java/com/emc/test/FibonacciRestServiceApplicationTests.java [81-86]

    +@Test
    +public void verifyFibonacciForLargeInput() throws Exception {
    +    restFibonacciMvc.perform(get("/v1/rest/fibonacci/47"))
    +            .andExpect(status().is4xxClientError())
    +            .andExpect(content().bytes("Number too large - may cause integer overflow".getBytes()));
    +}
    +
     @Test
     public void verifyFibonacciForInput20() throws Exception {
         restFibonacciMvc.perform(get("/v1/rest/fibonacci/20"))
                 .andExpect(status().isOk())
                 .andExpect(content().bytes("0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 ".getBytes()));
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    Why: Testing for integer overflow conditions is critical for preventing runtime errors and ensuring system stability. The suggestion addresses a potential security vulnerability that could crash the service.

    9
    General
    ✅ Add test coverage for negative input values to ensure proper error handling

    Add test case for negative input values to verify proper error handling and response

    src/test/java/com/emc/test/FibonacciRestServiceApplicationTests.java [53-58]

    +@Test 
    +public void verifyFibonacciForNegativeInput() throws Exception {
    +    restFibonacciMvc.perform(get("/v1/rest/fibonacci/-1"))
    +            .andExpect(status().is4xxClientError())
    +            .andExpect(content().bytes("Invalid number - negative values not allowed".getBytes()));
    +}
    +
     @Test
     public void verifyFibonacciForInput0() throws Exception {
         restFibonacciMvc.perform(get("/v1/rest/fibonacci/0"))
                 .andExpect(status().isOk())
                 .andExpect(content().bytes("0 ".getBytes()));
     }

    [Suggestion has been applied]

    Suggestion importance[1-10]: 8

    Why: Adding test coverage for negative inputs is important for robust error handling and API validation. The suggestion complements existing invalid input test (for "a") and would help ensure comprehensive input validation.

    8

    … and update README.md
    
    * **src/test/java/com/emc/test/FibonacciRestServiceApplicationTests.java**
      - Add test case for input 0
      - Add test case for input 1
      - Add test case for input 2
      - Add test case for input 10
      - Add test case for input 20
      - Add comments to explain the purpose of each test case
    
    * **README.md**
      - Add information about the new test cases
      - Add section explaining how to run the tests
      - Add section explaining the purpose of the test cases
    Comment on lines 57 to 58
    .andExpect(content().bytes("Invalid number - a".getBytes()));
    }

    Choose a reason for hiding this comment

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

    Suggestion: Add test coverage for negative input values to ensure proper error handling [General, importance: 8]

    Suggested change
    .andExpect(content().bytes("Invalid number - a".getBytes()));
    }
    @Test
    public void verifyFibonacciForNegativeInput() throws Exception {
    restFibonacciMvc.perform(get("/v1/rest/fibonacci/-1"))
    .andExpect(status().is4xxClientError())
    .andExpect(content().bytes("Invalid number - negative values not allowed".getBytes()));
    }
    @Test
    public void verifyFibonacciForInput0() throws Exception {
    restFibonacciMvc.perform(get("/v1/rest/fibonacci/0"))
    .andExpect(status().isOk())
    .andExpect(content().bytes("0 ".getBytes()));
    }

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    1 participant