Skip to content

Conversation

@divyanshsaxena002
Copy link

Description

This PR refactors the KMP and RabinKarp algorithms to improve their design, reusability, and testability.

Changes

  • Refactoring:
    • Removed main methods and console System.out.println statements.
    • Updated methods to programmatically return a List<Integer> of match indices instead of printing them.
    • Removed dependency on java.util.Scanner in RabinKarp.
  • Bug Fixes:
    • Fixed an integer overflow issue in RabinKarp by implementing modular exponentiation for hash calculation.
    • Fixed a StringIndexOutOfBoundsException when the pattern length exceeds the text length.
    • Implemented safer rolling hash updates to handle negative modulo cases correctly.
  • Testing:
    • Added comprehensive JUnit tests (KMPTest.java and RabinKarpTest.java).
    • Added explicit tests for edge cases: null inputs, empty strings, and hash collisions.
    • Ensured high code coverage to meet build requirements.

Checklists

  • Test passed locally
  • Code formatted correctly

@codecov-commenter
Copy link

codecov-commenter commented Jan 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.37%. Comparing base (11eec78) to head (01f597a).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7250      +/-   ##
============================================
+ Coverage     79.10%   79.37%   +0.26%     
- Complexity     6983     7014      +31     
============================================
  Files           784      784              
  Lines         22971    22970       -1     
  Branches       4515     4519       +4     
============================================
+ Hits          18171    18232      +61     
+ Misses         4077     4017      -60     
+ Partials        723      721       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

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.

2 participants