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
|
/*
* 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/array.hpp>
#include <gridtools/common/array_addons.hpp>
#include <gtest/gtest.h>
using namespace gridtools;
TEST(array, test_copyctr) {
array<uint_t, 4> a{4, 2, 3, 1};
auto mod_a(a);
EXPECT_EQ(mod_a, a);
EXPECT_EQ(mod_a[0], 4);
}
TEST(array, iterate_empty) {
array<uint_t, 0> a;
EXPECT_EQ(a.begin(), a.end());
for (auto &&el : a) {
(void)el;
FAIL();
}
}
namespace constexpr_compare {
constexpr array<uint_t, 3> a{0, 0, 0};
constexpr array<uint_t, 3> b{0, 0, 0};
constexpr array<uint_t, 3> c{0, 0, 1};
static_assert(a == b);
static_assert(a != c);
} // namespace constexpr_compare
TEST(array, iterate) {
const int N = 5;
array<double, N> a{};
EXPECT_EQ(N, std::distance(a.begin(), a.end()));
int count = 0;
for (auto &&el : a) {
(void)el;
count++;
}
EXPECT_EQ(N, count);
}
|