Skip to content

Fixes #7350: Binary Search Reliability Improvement#7351

Open
surajdm123 wants to merge 1 commit intoTheAlgorithms:masterfrom
surajdm123:7350-binary-search-reliability-improvement
Open

Fixes #7350: Binary Search Reliability Improvement#7351
surajdm123 wants to merge 1 commit intoTheAlgorithms:masterfrom
surajdm123:7350-binary-search-reliability-improvement

Conversation

@surajdm123
Copy link
Copy Markdown

@surajdm123 surajdm123 commented Mar 29, 2026

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new algorithms include a corresponding test class that validates their functionality.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

Summary

Fixes #7350 by adding missing test cases to improve the reliability of the Binary Search Algorithm.

Changes

  • Added test for null array input to ensure method safely returns -1.
  • Added test for duplicate elements to validate correct behavior when multiple matches exist.
  • Added test for arrays with all identical elements.
  • Added test for negative numbers to verify correct comparison handling.
  • Added tests for keys outside array bounds:
  • Key smaller than the smallest element
  • Key larger than the largest element
  • Added test for generic type support using String arrays.
  • Added test for unsorted array input to ensure method does not crash (behavior undefined but handled safely).

Test Plan

Screenshot 2026-03-29 at 1 25 55 AM

Fixes #7350

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.48%. Comparing base (227355e) to head (ae637be).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7351      +/-   ##
============================================
+ Coverage     79.47%   79.48%   +0.01%     
- Complexity     7090     7093       +3     
============================================
  Files           791      791              
  Lines         23202    23202              
  Branches       4565     4565              
============================================
+ Hits          18439    18443       +4     
  Misses         4024     4024              
+ Partials        739      735       -4     

☔ 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.

Add test cases for edge conditions in BinarySearch

2 participants