Skip to content

Commit 62c2d22

Browse files
committed
test: view::size() more tests
1 parent f8cb050 commit 62c2d22

File tree

1 file changed

+19
-3
lines changed
  • libcxx/test/std/ranges/range.adaptors/range.cartesian.product.view

1 file changed

+19
-3
lines changed

libcxx/test/std/ranges/range.adaptors/range.cartesian.product.view/size.pass.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
// std::ranges::cartesian_product_view::size
1212

13+
#include <array>
1314
#include <cassert>
14-
#include <ranges>
1515
#include <initializer_list>
16+
#include <ranges>
1617

1718
constexpr bool test() {
18-
{ // testing: constexpr auto size() const
19-
// example taken from: https://en.cppreference.com/w/cpp/ranges/cartesian_product_view/size
19+
{ // example taken from: https://en.cppreference.com/w/cpp/ranges/cartesian_product_view/size
2020
constexpr static auto w = {1};
2121
constexpr static auto x = {2, 3};
2222
constexpr static auto y = {4, 5, 6};
@@ -33,6 +33,22 @@ constexpr bool test() {
3333
assert(v.size() == w.size() * x.size() * y.size() * z.size());
3434
}
3535

36+
{ // empty range
37+
std::ranges::empty_view<int> e;
38+
auto v = std::ranges::cartesian_product_view(e);
39+
assert(v.size() == 0);
40+
}
41+
42+
{ // 1..3 range(s)
43+
constexpr size_t N0 = 3, N1 = 7, N2 = 42;
44+
std::array<int, N0> a0;
45+
std::array<int, N1> a1;
46+
std::array<int, N2> a2;
47+
assert(std::ranges::cartesian_product_view(a0).size() == N0);
48+
assert(std::ranges::cartesian_product_view(a0, a1).size() == N0 * N1);
49+
assert(std::ranges::cartesian_product_view(a0, a1, a2).size() == N0 * N1 * N2);
50+
}
51+
3652
return true;
3753
}
3854

0 commit comments

Comments
 (0)