Skip to content

Check duplicate counts in sorting tests - #1080

Open
ashish358 wants to merge 1 commit into
TheAlgorithms:masterfrom
ashish358:fix/sorting-duplicate-counts
Open

ashish358 wants to merge 1 commit into
TheAlgorithms:masterfrom
ashish358:fix/sorting-duplicate-counts

Conversation

@ashish358

Copy link
Copy Markdown

Description

The shared sorting test helper accepts [1, 2, 2] as a rearrangement of [1, 1, 2]. Both slices have the same length and distinct values, even though a sort has lost a 1 and duplicated a 2.

Count occurrences in the first slice and consume a count for each item in the second. The regression test covers incorrect duplicate counts, a valid rearrangement, unequal lengths, and a missing value.

Type of change

  • Bug fix

Testing

The isolated regression test failed with the old helper and passed with the fix on stable Rust. The repository-wide nightly checks are pending.

  • cargo clippy --all -- -D warnings on nightly
  • cargo fmt on nightly
  • cargo test on nightly

Refactor have_same_elements to use HashMap for counting elements instead of HashSet for comparison.
@ashish358
ashish358 requested a review from imp2002 as a code owner December 3, 2026 14:41
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.14%. Comparing base (976f1cd) to head (11eecc4).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1080      +/-   ##
==========================================
- Coverage   96.17%   96.14%   -0.03%     
==========================================
  Files         396      396              
  Lines       30418    30428      +10     
==========================================
+ Hits        29254    29256       +2     
- Misses       1164     1172       +8     

☔ View full report in Codecov by Harness.
📢 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