Java icon indicating copy to clipboard operation
Java copied to clipboard

Implement LengthOfLastWord algorithm and add JUnit tests

Open gopaljilab opened this issue 4 months ago • 2 comments

Summary

This pull request introduces the LengthOfLastWord algorithm under the strings package. It also includes comprehensive JUnit test coverage to ensure correctness and reliability.

Details

  • LengthOfLastWord.java Implements a method to compute the length of the last word in a given string. The algorithm efficiently traverses the string from the end to handle trailing spaces.

  • LengthOfLastWordTest.java Adds JUnit tests covering various scenarios, including:

    • Strings with trailing spaces
    • Single-word inputs
    • Multiple-word inputs
    • Empty string edge case

Checklist

  • [x] Code follows the repository’s naming and structural conventions
  • [x] Includes Javadoc-style documentation
  • [x] Added unit tests for all relevant cases
  • [x] Verified all tests pass locally using ./gradlew test

Example

Input: "Hello World" Output: 5

gopaljilab avatar Nov 08 '25 05:11 gopaljilab

👋 Hello, this is my first open-source contribution! I’ve implemented the LengthOfLastWord algorithm under the strings package and added JUnit tests for validation. Please review and let me know if any improvements are needed. Thank you for maintaining this amazing repository! 🙏

gopaljilab avatar Nov 08 '25 05:11 gopaljilab

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 78.88%. Comparing base (a8bc9cc) to head (e6df7dd).

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #7057   +/-   ##
=========================================
  Coverage     78.87%   78.88%           
- Complexity     6828     6834    +6     
=========================================
  Files           766      767    +1     
  Lines         22607    22616    +9     
  Branches       4444     4446    +2     
=========================================
+ Hits          17831    17840    +9     
  Misses         4064     4064           
  Partials        712      712           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov-commenter avatar Nov 08 '25 05:11 codecov-commenter