Commit 9bf5313a authored by Michaël Roynard's avatar Michaël Roynard
Browse files

Finish concept checking

parent a4603199
Pipeline #12726 passed with stages
in 15 minutes and 6 seconds
......@@ -221,3 +221,5 @@ TEST(Core, Transform_Supports_PointerToMemberFunction)
// FIXME: ASSERT_IMAGES_EQ(ref, c);
}
// TODO: add transform2 unit tests
......@@ -152,6 +152,16 @@ TEST(Range, transform2_on_containers)
std::vector<int> v2 = {3, 4};
auto rng = mln::ranges::view::transform(v, v2, [](int x, int y) { return x + y; });
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(mln::concepts::stl::ForwardRange<decltype(v)>);
static_assert(mln::concepts::stl::ForwardRange<decltype(v2)>);
static_assert(mln::concepts::stl::ForwardRange<decltype(rng)>);
#else
static_assert(::ranges::ForwardRange<decltype(v)>());
static_assert(::ranges::ForwardRange<decltype(v2)>());
static_assert(::ranges::ForwardRange<decltype(rng)>());
#endif // PYLENE_CONCEPT_TS_ENABLED
ASSERT_EQ(std::vector({5, 7}), ::ranges::to_vector(rng));
}
......@@ -160,9 +170,21 @@ TEST(Range, transform2_2d_readonly)
{
mln::ranges::multi_indices<2> ind({3, 4});
std::size_t n = 0;
auto g = [](auto a, auto b) { return number_from_vec_t(a) + number_from_vec_t(b); };
for (auto v : mln::ranges::view::transform(ind, ind, g))
std::size_t n = 0;
auto g = [](auto a, auto b) { return number_from_vec_t(a) + number_from_vec_t(b); };
auto rng = mln::ranges::view::transform(ind, ind, g);
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(mln::concepts::SegmentedRange<decltype(ind)>);
static_assert(mln::concepts::ReversibleRange<decltype(ind)>);
static_assert(mln::concepts::SegmentedRange<decltype(rng)>);
static_assert(mln::concepts::ReversibleRange<decltype(rng)>);
#else
static_assert(::ranges::ForwardRange<decltype(ind)>());
static_assert(::ranges::ForwardRange<decltype(rng)>());
#endif // PYLENE_CONCEPT_TS_ENABLED
for (auto v : rng)
n += v;
ASSERT_EQ(2 * 1812, n);
......@@ -176,6 +198,17 @@ TEST(Range, transform2_2d_readonly_rowwise)
std::size_t n = 0;
auto g = [](auto a, auto b) { return number_from_vec_t(a) + number_from_vec_t(b); };
auto rng = mln::ranges::view::transform(ind, ind, g);
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(mln::concepts::SegmentedRange<decltype(ind)>);
static_assert(mln::concepts::ReversibleRange<decltype(ind)>);
static_assert(mln::concepts::SegmentedRange<decltype(rng)>);
static_assert(mln::concepts::ReversibleRange<decltype(rng)>);
#else
static_assert(::ranges::ForwardRange<decltype(ind)>());
static_assert(::ranges::ForwardRange<decltype(rng)>());
#endif // PYLENE_CONCEPT_TS_ENABLED
for (auto row : rng.rows())
for (auto v : row)
n += v;
......@@ -192,10 +225,28 @@ TEST(Range, transform2_2d_write)
mln::ranges::multi_span<std::pair<int, int>, 2> sp2(buffer2.data(), {3, 4}, {4, 1});
auto firsts_of_pairs = [](std::pair<int, int>& a, std::pair<int, int>& b) { return std::tie(a.first, b.first); };
auto rng = mln::ranges::view::transform(sp1, sp2, firsts_of_pairs);
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(mln::concepts::stl::ForwardRange<decltype(buffer1)>);
static_assert(mln::concepts::stl::ForwardRange<decltype(buffer2)>);
static_assert(mln::concepts::SegmentedRange<decltype(sp1)>);
static_assert(mln::concepts::ReversibleRange<decltype(sp1)>);
static_assert(mln::concepts::SegmentedRange<decltype(sp2)>);
static_assert(mln::concepts::ReversibleRange<decltype(sp2)>);
static_assert(mln::concepts::SegmentedRange<decltype(rng)>);
static_assert(mln::concepts::ReversibleRange<decltype(rng)>);
#else
static_assert(::ranges::ForwardRange<decltype(buffer1)>());
static_assert(::ranges::ForwardRange<decltype(buffer2)>());
static_assert(::ranges::ForwardRange<decltype(sp1)>());
static_assert(::ranges::ForwardRange<decltype(sp2)>());
static_assert(::ranges::ForwardRange<decltype(rng)>());
#endif // PYLENE_CONCEPT_TS_ENABLED
{
std::size_t i = 0;
for (auto&& v : mln::ranges::view::transform(sp1, sp2, firsts_of_pairs))
for (auto&& v : rng)
{
std::get<0>(v) = i++;
std::get<1>(v) = i++;
......@@ -220,10 +271,27 @@ TEST(Range, transform2_2d_write_row_wise)
mln::ranges::multi_span<std::pair<int, int>, 2> sp2(buffer2.data(), {3, 4}, {4, 1});
auto firsts_of_pairs = [](std::pair<int, int>& a, std::pair<int, int>& b) { return std::tie(a.first, b.first); };
auto rng = mln::ranges::view::transform(sp1, sp2, firsts_of_pairs);
#ifdef PYLENE_CONCEPT_TS_ENABLED
static_assert(mln::concepts::stl::ForwardRange<decltype(buffer1)>);
static_assert(mln::concepts::stl::ForwardRange<decltype(buffer2)>);
static_assert(mln::concepts::SegmentedRange<decltype(sp1)>);
static_assert(mln::concepts::ReversibleRange<decltype(sp1)>);
static_assert(mln::concepts::SegmentedRange<decltype(sp2)>);
static_assert(mln::concepts::ReversibleRange<decltype(sp2)>);
static_assert(mln::concepts::SegmentedRange<decltype(rng)>);
static_assert(mln::concepts::ReversibleRange<decltype(rng)>);
#else
static_assert(::ranges::ForwardRange<decltype(buffer1)>());
static_assert(::ranges::ForwardRange<decltype(buffer2)>());
static_assert(::ranges::ForwardRange<decltype(sp1)>());
static_assert(::ranges::ForwardRange<decltype(sp2)>());
static_assert(::ranges::ForwardRange<decltype(rng)>());
#endif // PYLENE_CONCEPT_TS_ENABLED
{
std::size_t i = 0;
auto rng = mln::ranges::view::transform(sp1, sp2, firsts_of_pairs);
std::size_t i = 0;
for (auto row : rng.rows())
for (auto&& v : row)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment