Skip to content

[tests] Add return-iterator compliance and edge-case regression tests for hpx::partial_sort#7196

Merged
hkaiser merged 3 commits intoTheHPXProject:masterfrom
aneek22112007-tech:test/partial-sort-return-iterator-compliance
Apr 18, 2026
Merged

[tests] Add return-iterator compliance and edge-case regression tests for hpx::partial_sort#7196
hkaiser merged 3 commits intoTheHPXProject:masterfrom
aneek22112007-tech:test/partial-sort-return-iterator-compliance

Conversation

@aneek22112007-tech
Copy link
Copy Markdown
Contributor

@aneek22112007-tech aneek22112007-tech commented Apr 17, 2026

Summary

The existing partial_sort.cpp test suite verified only that the sorted prefix contained correct values, but never validated the return value of hpx::partial_sort across any execution policy. According to the C++ standard (and HPX documentation), partial_sort must return an iterator pointing to last -- this was completely untested.

Additionally, the following boundary conditions had zero coverage:

  • Empty range (first == last)
    • middle == first (zero elements to sort)
    • middle == last (degenerates to full sort)
    • Single-element range
    • Already-sorted input
  • Changes## Summary

The existing partial_sort.cpp test suite verified only that the sorted prefix contained correct values, but never validated the return value of hpx::partial_sort across any execution policy. According to the C++ standard (and HPX documentation), partial_sort must return an iterator pointing to last -- this was completely untested.

Additionally, the following boundary conditions had zero coverage:

  • Empty range (first == last)
  • middle == first (zero elements to sort)
  • middle == last (degenerates to full sort)
  • Single-element range
  • Already-sorted input

Changes

  • libs/core/algorithms/tests/unit/algorithms/partial_sort.cpp (test-only change)
    • Added result == B.end() assertions to all three existing test functions: sequential, parallel, and async variants.
    • Added new test_partial_sort_edge_cases() function covering all boundary conditions listed above across all policies (seq, par, par_unseq, and no-policy sequential).

Testing

All new tests validate both return value correctness and content correctness (where applicable). The code is clang-format clean (verified locally with --dry-run --Werror).

Why This Matters

Return-iterator compliance is a correctness guarantee of the C++ standard. Callers chaining operations on the returned iterator rely on it pointing to exactly last. Without this regression test, a future refactor could silently break this contract.-

    • libs/core/algorithms/tests/unit/algorithms/partial_sort.cpp (test-only change)
    • Added result == B.end() assertions to all three existing test functions: sequential, parallel, and async variants.
    • Added new test_partial_sort_edge_cases() function covering all boundary conditions listed above across all policies (seq, par, par_unseq, and no-policy sequential).
  • Testing

  • All new tests validate both return value correctness and content correctness (where applicable). The code is clang-format clean (verified locally with --dry-run --Werror).

  • Why This Matters

  • Return-iterator compliance is a correctness guarantee of the C++ standard. Callers chaining operations on the returned iterator rely on it pointing to exactly last. Without this regression test, a future refactor could silently break this contract.The existing partial_sort.cpp test suite verified only that the sorted prefix contained correct values, but never validated the return value of hpx::partial_sort across any execution policy. According to the C++ standard (and HPX documentation), partial_sort must return an iterator pointing to last

Checklist

Not all points below apply to all pull requests.

  • I have added a new feature and have added tests to go along with it.
  • I have fixed a bug and have added a regression test.
  • I have added a test using random numbers; I have made sure it uses a seed, and that random numbers generated are valid inputs for the tests.

@StellarBot
Copy link
Copy Markdown

Can one of the admins verify this patch?

@aneek22112007-tech aneek22112007-tech changed the title [tests] Add return-iterator compliance and edge-case tests f[tests] Add return-iterator compliance and edge-case tests for hpx::partial_sortor hpx::p… [tests] Add return-iterator compliance and edge-case tests for hpx::partial_sort[tests] Add return-iterator compliance and edge-case tests f[tests] Add return-iterator compliance and edge-case tests for hpx::partial_sortor hpx::p… Apr 17, 2026
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 17, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@aneek22112007-tech aneek22112007-tech changed the title [tests] Add return-iterator compliance and edge-case tests for hpx::partial_sort[tests] Add return-iterator compliance and edge-case tests f[tests] Add return-iterator compliance and edge-case tests for hpx::partial_sortor hpx::p… [tests] Add return-iterator compliance and edge-case tests for hpx::partial_sort Apr 17, 2026
@aneek22112007-tech aneek22112007-tech changed the title [tests] Add return-iterator compliance and edge-case tests for hpx::partial_sort [tests] Add return-iterator compliance and edge-case regression tests for hpx::partial_sort Apr 17, 2026
Copy link
Copy Markdown
Contributor

@hkaiser hkaiser left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@hkaiser hkaiser added this to the 2.0.0 milestone Apr 17, 2026
@hkaiser hkaiser merged commit 2dbdb70 into TheHPXProject:master Apr 18, 2026
65 checks passed
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.

4 participants