[test] Add projection tests for hpx::ranges::{unique_copy, partition_copy, remove_copy, remove_copy_if}#7259
Open
aneek22112007-tech wants to merge 2 commits intoTheHPXProject:masterfrom
Conversation
Collaborator
|
Can one of the admins verify this patch? |
Add dedicated projection-aware tests to the range-based container
algorithm test suite for four copy-classification algorithms:
unique_copy, partition_copy, remove_copy, and remove_copy_if.
All four algorithms accept an optional Proj parameter in their CPO
layer (container_algorithms/unique.hpp, container_algorithms/
remove_copy.hpp), but their existing range test files exercised only
the default hpx::identity projection path, leaving the user-supplied
projection code path completely untested.
Changes:
- unique_copy_range.cpp: add test_unique_copy_projection() that
projects user_defined_type::val and verifies consecutive-equal
elements are correctly deduplicated across seq, par, par_unseq,
seq(task), and par(task) policies. Results are cross-checked
against std::unique_copy with an equivalent lambda predicate.
- partition_copy_range.cpp: add test_partition_copy_projection()
that projects user_defined_type::val to int and applies a plain
integer threshold predicate (distinct from the name-aware
operator< used by existing tests), verifying both true and false
output partitions against std::partition_copy across all policies.
- remove_copy_range.cpp: introduce a projected_element{key, tag}
helper struct and add test_remove_copy_projection() that removes
by projected key equality using a deterministic input (keys 0-4
cycling). Results are verified against a hand-built expected
vector across all policies including async task variants.
- remove_copy_if_range.cpp: same projected_element helper and
test_remove_copy_if_projection() that removes elements with odd
projected keys via a unary predicate, verified across all six
policy variants.
These additions close a silent testing gap: any future refactor that
accidentally breaks projection threading in the internal copy/
remove_copy dispatch would now be caught by CI.
8323713 to
01df0e5
Compare
Up to standards ✅🟢 Issues
|
Contributor
|
@aneek22112007-tech some of the newly added tests fail to compile, could you please have a look? Also, inspect complains abut non-ASCII characters in the tests: |
- Replace UTF-8 em-dash (U+2014) with ASCII hyphen in comments across partition_copy_range.cpp, remove_copy_if_range.cpp, remove_copy_range.cpp and unique_copy_range.cpp (flagged by maintainer CI checks) - Fix hpx::ranges::remove_copy_if CPO: change the predicate invocability constraint from is_invocable_v<Pred, value_type> to is_indirect_callable_v<..., projected<Proj, I>> so that predicates operating on the projected type (not the raw element type) are correctly accepted. This is consistent with how partition_copy, unique_copy and other range algorithms express the same constraint.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
test_unique_copy_projection()tounique_copy_range.cpp— exercises theProjparameter of
hpx::ranges::unique_copyacrossseq,par,par_unseq,seq(task),and
par(task)policies usinguser_defined_type::valas the projected key,cross-checked against
std::unique_copytest_partition_copy_projection()topartition_copy_range.cpp— exercises theProjparameter ofhpx::ranges::partition_copywith a simple integer thresholdpredicate applied to the projected
valfield, verified againststd::partition_copyacross all policies
projected_element{key, tag}helper struct andtest_remove_copy_projection()/test_remove_copy_if_projection()toremove_copy_range.cppandremove_copy_if_range.cpp— exercises theProjparameter ofhpx::ranges::remove_copyandhpx::ranges::remove_copy_ifacross all executionpolicies including async task variants
Any background context you want to provide?
All four algorithms (
unique_copy,partition_copy,remove_copy,remove_copy_if)accept an optional
Projparameter in their CPO layer(
container_algorithms/unique.hpp,container_algorithms/remove_copy.hpp) and correctlythread it to the internal dispatch. However, their existing range test files exercised
only the default
hpx::identityprojection, leaving the user-supplied projectioncode path completely untested — a silent gap that would allow future refactors breaking
projection support to pass CI undetected.
This brings these algorithms in line with the projection testing standard already
established for
is_partitioned(is_partitioned_projection_range.cpp),is_sorted,and
minmax_element.No production code was changed. All additions are pure test code following existing
patterns (
HPX_TEST,test::equal).clang-format --dry-run --Werrorpasses withzero violations.
Checklist
Not all points below apply to all pull requests.
that random numbers generated are valid inputs for the tests.