Skip to content

Commit

Permalink
[oneDPL][ranges][zip_view][test] LLVM test general.pass and ctor.view…
Browse files Browse the repository at this point in the history
…s tests adaptation for oneDPL
  • Loading branch information
MikeDvorskiy committed Feb 10, 2025
1 parent 5ddc899 commit dc9814c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 32 deletions.
33 changes: 12 additions & 21 deletions test/parallel_api/ranges/range.zip/ctor.views.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@
#include "types.h"

#include <oneapi/dpl/ranges>
namespace std
{
namespace ranges
{
using oneapi::dpl::ranges::zip_view;
}

}
namespace dpl_ranges = oneapi::dpl::ranges;

template <class T>
void conversion_test(T);
Expand All @@ -32,12 +26,12 @@ template <class T, class... Args>
concept implicitly_constructible_from = requires(Args&&... args) { conversion_test<T>({std::move(args)...}); };

// test constructor is explicit
static_assert(std::constructible_from<std::ranges::zip_view<SimpleCommon>, SimpleCommon>);
static_assert(!implicitly_constructible_from<std::ranges::zip_view<SimpleCommon>, SimpleCommon>);
static_assert(std::constructible_from<dpl_ranges::zip_view<SimpleCommon>, SimpleCommon>);
static_assert(!implicitly_constructible_from<dpl_ranges::zip_view<SimpleCommon>, SimpleCommon>);

static_assert(std::constructible_from<std::ranges::zip_view<SimpleCommon, SimpleCommon>, SimpleCommon, SimpleCommon>);
static_assert(std::constructible_from<dpl_ranges::zip_view<SimpleCommon, SimpleCommon>, SimpleCommon, SimpleCommon>);
static_assert(
!implicitly_constructible_from<std::ranges::zip_view<SimpleCommon, SimpleCommon>, SimpleCommon, SimpleCommon>);
!implicitly_constructible_from<dpl_ranges::zip_view<SimpleCommon, SimpleCommon>, SimpleCommon, SimpleCommon>);

struct MoveAwareView : std::ranges::view_base {
int moves = 0;
Expand All @@ -54,20 +48,20 @@ struct MoveAwareView : std::ranges::view_base {

template <class View1, class View2>
constexpr void constructorTest(auto&& buffer1, auto&& buffer2) {
std::ranges::zip_view v{View1{buffer1}, View2{buffer2}};
dpl_ranges::zip_view v{View1{buffer1}, View2{buffer2}};
auto [i, j] = *v.begin();
assert(i == buffer1[0]);
assert(j == buffer2[0]);
};

constexpr bool test() {
int test() {

int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};
int buffer2[4] = {9, 8, 7, 6};

{
// constructor from views
std::ranges::zip_view v(SizedRandomAccessView{buffer}, std::views::iota(0), std::ranges::single_view(2.));
dpl_ranges::zip_view v(SizedRandomAccessView{buffer}, std::views::iota(0), std::ranges::single_view(2.));
auto [i, j, k] = *v.begin();
assert(i == 1);
assert(j == 0);
Expand All @@ -77,7 +71,7 @@ constexpr bool test() {
{
// arguments are moved once
MoveAwareView mv;
std::ranges::zip_view v{std::move(mv), MoveAwareView{}};
dpl_ranges::zip_view v{std::move(mv), MoveAwareView{}};
auto [numMoves1, numMoves2] = *v.begin();
assert(numMoves1 == 2); // one move from the local variable to parameter, one move from parameter to member
assert(numMoves2 == 1);
Expand All @@ -98,12 +92,9 @@ constexpr bool test() {
constructorTest<ContiguousCommonView, ContiguousCommonView>(buffer, buffer2);
}

return true;
return 0;
}

int main(int, char**) {
test();
static_assert(test());

return 0;
int main() {
return test();
}
14 changes: 3 additions & 11 deletions test/parallel_api/ranges/range.zip/general.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,12 @@
#include "types.h"

#include <oneapi/dpl/ranges>
namespace std
{
namespace ranges
{
using oneapi::dpl::ranges::zip_view;
}

}

namespace _std = oneapi::dpl::ranges;
namespace dpl_ranges = oneapi::dpl::ranges;

int main(int, char**) {
{
std::ranges::zip_view v{
dpl_ranges::zip_view v{
std::array{1, 2},
std::vector{4, 5, 6},
std::array{7},
Expand All @@ -48,7 +40,7 @@ int main(int, char**) {
using namespace std::string_literals;
std::vector v{1, 2, 3, 4};
std::array a{"abc"s, "def"s, "gh"s};
auto view = _std::views::zip(v, a);
auto view = dpl_ranges::views::zip(v, a);
auto it = view.begin();
assert(&(std::get<0>(*it)) == &(v[0]));
assert(&(std::get<1>(*it)) == &(a[0]));
Expand Down

0 comments on commit dc9814c

Please sign in to comment.