1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
/*
* GridTools
*
* Copyright (c) 2014-2023, ETH Zurich
* All rights reserved.
*
* Please, refer to the LICENSE file in the root directory.
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <gridtools/common/stride_util.hpp>
#include <type_traits>
#include <gtest/gtest.h>
#include <gridtools/common/hymap.hpp>
#include <gridtools/common/integral_constant.hpp>
#include <gridtools/common/tuple.hpp>
#include <gridtools/common/tuple_util.hpp>
namespace gridtools {
namespace stride_util {
namespace {
using namespace literals;
namespace tu = tuple_util;
TEST(make_strides_from_sizes, smoke) {
auto testee = make_strides_from_sizes(tuple(20, 30, 40));
static_assert(std::is_same_v<decltype(testee), tuple<integral_constant<int, 1>, int, int>>);
EXPECT_EQ(1, tu::get<0>(testee));
EXPECT_EQ(20, tu::get<1>(testee));
EXPECT_EQ(600, tu::get<2>(testee));
}
TEST(make_strides_from_sizes, integral_constants) {
auto testee = make_strides_from_sizes(tuple(20_c, 30_c, 40));
static_assert(std::is_same_v<decltype(testee),
tuple<integral_constant<int, 1>, integral_constant<int, 20>, integral_constant<int, 600>>>);
EXPECT_EQ(1, tu::get<0>(testee));
EXPECT_EQ(20, tu::get<1>(testee));
EXPECT_EQ(600, tu::get<2>(testee));
}
struct a;
struct b;
struct c;
TEST(make_strides_from_sizes, hymap) {
auto testee = make_strides_from_sizes(hymap::keys<a, b, c>::make_values(20, 30, 40));
static_assert(std::is_same_v<decltype(testee),
hymap::keys<a, b, c>::values<integral_constant<int, 1>, int, int>>);
EXPECT_EQ(1, at_key<a>(testee));
EXPECT_EQ(20, at_key<b>(testee));
EXPECT_EQ(600, at_key<c>(testee));
}
TEST(total_size, smoke) {
auto testee = total_size(tuple(20, 30, 40));
EXPECT_EQ(24000, testee);
}
TEST(total_size, integral_constants) {
auto testee = total_size(tuple(20_c, 30_c, 40_c));
static_assert(std::is_same_v<decltype(testee), integral_constant<int, 24000>>);
EXPECT_EQ(24000, testee);
}
} // namespace
} // namespace stride_util
} // namespace gridtools
|