Skip to content

[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
aneek22112007-tech:test/ranges-copy-algorithm-projections
Open

[test] Add projection tests for hpx::ranges::{unique_copy, partition_copy, remove_copy, remove_copy_if}#7259
aneek22112007-tech wants to merge 2 commits intoTheHPXProject:masterfrom
aneek22112007-tech:test/ranges-copy-algorithm-projections

Conversation

@aneek22112007-tech
Copy link
Copy Markdown
Contributor

Proposed Changes

  • Add test_unique_copy_projection() to unique_copy_range.cpp — exercises the Proj
    parameter of hpx::ranges::unique_copy across seq, par, par_unseq, seq(task),
    and par(task) policies using user_defined_type::val as the projected key,
    cross-checked against std::unique_copy
  • Add test_partition_copy_projection() to partition_copy_range.cpp — exercises the
    Proj parameter of hpx::ranges::partition_copy with a simple integer threshold
    predicate applied to the projected val field, verified against std::partition_copy
    across all policies
  • Add projected_element{key, tag} helper struct and test_remove_copy_projection() /
    test_remove_copy_if_projection() to remove_copy_range.cpp and
    remove_copy_if_range.cpp — exercises the Proj parameter of
    hpx::ranges::remove_copy and hpx::ranges::remove_copy_if across all execution
    policies 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 Proj parameter in their CPO layer
(container_algorithms/unique.hpp, container_algorithms/remove_copy.hpp) and correctly
thread it to the internal dispatch. However, their existing range test files exercised
only the default hpx::identity projection, leaving the user-supplied projection
code 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 --Werror passes with
zero violations.

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
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.
@aneek22112007-tech aneek22112007-tech force-pushed the test/ranges-copy-algorithm-projections branch from 8323713 to 01df0e5 Compare May 8, 2026 22:16
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 8, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@hkaiser
Copy link
Copy Markdown
Contributor

hkaiser commented May 9, 2026

@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:

/libs/core/algorithms/tests/unit/container_algorithms/partition_copy_range.cpp:
    Non-ASCII: line 303
/libs/core/algorithms/tests/unit/container_algorithms/remove_copy_if_range.cpp:
    Non-ASCII: line 291
/libs/core/algorithms/tests/unit/container_algorithms/remove_copy_range.cpp:
    Non-ASCII: line 272
/libs/core/algorithms/tests/unit/container_algorithms/unique_copy_range.cpp:
    Non-ASCII: line 277

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