class MultiDimArrayTest : public ::testing::Test
{
- public:
- MultiDimArrayTest()
- {
- std::fill(begin(staticArray_), end(staticArray_), testNumber_ - 1);
- std::fill(begin(dynamicArray_), end(dynamicArray_), testNumber_ - 1);
- }
- protected:
-
- using static_container_type = std::array<float, 3*3>;
- using static_extents_type = extents<3, 3>;
- using static_array_type = MultiDimArray<static_container_type, static_extents_type>;
-
- using dynamic_container_type = std::vector<float>;
- using dynamic_extents_type = extents<dynamic_extent, dynamic_extent>;
- using dynamic_array_type = MultiDimArray<dynamic_container_type, dynamic_extents_type>;
-
- static_array_type staticArray_;
- dynamic_array_type dynamicArray_ {2, 2};
-
- float testNumber_ = 42;
+public:
+ MultiDimArrayTest()
+ {
+ std::fill(begin(staticArray_), end(staticArray_), testNumber_ - 1);
+ std::fill(begin(dynamicArray_), end(dynamicArray_), testNumber_ - 1);
+ }
+
+protected:
+ using static_container_type = std::array<float, 3 * 3>;
+ using static_extents_type = extents<3, 3>;
+ using static_array_type = MultiDimArray<static_container_type, static_extents_type>;
+
+ using dynamic_container_type = std::vector<float>;
+ using dynamic_extents_type = extents<dynamic_extent, dynamic_extent>;
+ using dynamic_array_type = MultiDimArray<dynamic_container_type, dynamic_extents_type>;
+
+ static_array_type staticArray_;
+ dynamic_array_type dynamicArray_{ 2, 2 };
+
+ float testNumber_ = 42;
};
TEST_F(MultiDimArrayTest, canConstructAndFillStatic)
{
- for (const auto &x : staticArray_)
+ for (const auto& x : staticArray_)
{
EXPECT_EQ(testNumber_ - 1, x);
}
TEST_F(MultiDimArrayTest, canConstructAndFillDynamic)
{
- for (const auto &x : dynamicArray_)
+ for (const auto& x : dynamicArray_)
{
EXPECT_EQ(testNumber_ - 1, x);
}
TEST_F(MultiDimArrayTest, canSetValuesInStatic)
{
staticArray_(1, 1) = testNumber_;
- EXPECT_EQ(testNumber_, staticArray_(1, 1) );
+ EXPECT_EQ(testNumber_, staticArray_(1, 1));
}
TEST_F(MultiDimArrayTest, canSetValuesInDynamic)
TEST_F(MultiDimArrayTest, canMoveConstructStatic)
{
auto other(std::move(staticArray_));
- for (const auto &x : other)
+ for (const auto& x : other)
{
EXPECT_EQ(testNumber_ - 1, x);
}
TEST_F(MultiDimArrayTest, canMoveConstructDynamic)
{
auto other(std::move(dynamicArray_));
- for (const auto &x : other)
+ for (const auto& x : other)
{
EXPECT_EQ(testNumber_ - 1, x);
}
{
static_array_type other;
other = std::move(staticArray_);
- for (const auto &x : other)
+ for (const auto& x : other)
{
EXPECT_EQ(testNumber_ - 1, x);
}
{
dynamic_array_type other;
other = std::move(dynamicArray_);
- for (const auto &x : other)
+ for (const auto& x : other)
{
EXPECT_EQ(testNumber_ - 1, x);
}
{
auto other = staticArray_;
auto twoDArrayIt = begin(staticArray_);
- for (const auto &x : other)
+ for (const auto& x : other)
{
EXPECT_EQ(*twoDArrayIt, x);
++twoDArrayIt;
{
auto other = dynamicArray_;
auto twoDArrayIt = begin(dynamicArray_);
- for (const auto &x : other)
+ for (const auto& x : other)
{
EXPECT_EQ(*twoDArrayIt, x);
++twoDArrayIt;
TEST_F(MultiDimArrayTest, canCopyAssignStatic)
{
static_array_type other;
- other = staticArray_;
- auto twoDArrayIt = begin(staticArray_);
- for (const auto &x : other)
+ other = staticArray_;
+ auto twoDArrayIt = begin(staticArray_);
+ for (const auto& x : other)
{
EXPECT_EQ(*twoDArrayIt, x);
++twoDArrayIt;
TEST_F(MultiDimArrayTest, canCopyAssignDynamic)
{
dynamic_array_type other;
- other = dynamicArray_;
- auto twoDArrayIt = begin(dynamicArray_);
- for (const auto &x : other)
+ other = dynamicArray_;
+ auto twoDArrayIt = begin(dynamicArray_);
+ for (const auto& x : other)
{
EXPECT_EQ(*twoDArrayIt, x);
++twoDArrayIt;
TEST_F(MultiDimArrayTest, staticMultiDimArrayFromArray)
{
- static_array_type arr = {{1, 2, 3, 4, 5, 6, 7, 8, 9}};
+ static_array_type arr = { { 1, 2, 3, 4, 5, 6, 7, 8, 9 } };
EXPECT_EQ(arr(0, 0), 1);
EXPECT_EQ(arr(0, 1), 2);
EXPECT_EQ(arr(0, 2), 3);
TEST_F(MultiDimArrayTest, conversionToView)
{
static_array_type::view_type view = staticArray_.asView();
- view(2, 2) = testNumber_;
+ view(2, 2) = testNumber_;
EXPECT_EQ(testNumber_, view(2, 2));
}
static_array_type::const_view_type view = staticArray_.asConstView();
// the following must not compile:
// view(2, 2) = testNumber_;
- for (const auto &x : view)
+ for (const auto& x : view)
{
EXPECT_EQ(testNumber_ - 1, x);
}
TEST_F(MultiDimArrayTest, viewBegin)
{
static_array_type::view_type view = staticArray_.asView();
- *begin(view) = testNumber_;
+ *begin(view) = testNumber_;
EXPECT_EQ(*begin(view), testNumber_);
}
TEST_F(MultiDimArrayTest, viewEnd)
{
static_array_type::view_type view = staticArray_.asView();
- auto x = end(view);
+ auto x = end(view);
--x;
view(2, 2) = testNumber_;
EXPECT_EQ(*x, testNumber_);
TEST_F(MultiDimArrayTest, constViewConstBegin)
{
staticArray_(0, 0) = testNumber_;
- const auto view = staticArray_.asConstView();
+ const auto view = staticArray_.asConstView();
// must not compile: *begin(view) = testNumber_;
EXPECT_EQ(*begin(view), testNumber_);
}
TEST_F(MultiDimArrayTest, constViewConstEnd)
{
staticArray_(2, 2) = testNumber_;
- const auto view = staticArray_.asConstView();
- auto x = end(view);
+ const auto view = staticArray_.asConstView();
+ auto x = end(view);
--x;
EXPECT_EQ(*x, testNumber_);
}
TEST(MultiDimArrayToMdSpanTest, convertsToMdSpan)
{
- MultiDimArray < std::array<int, 4>, extents < 2, 2>> arr = {{0, 1, 2, 3}};
- basic_mdspan < int, extents < 2, 2>> span(arr);
+ MultiDimArray<std::array<int, 4>, extents<2, 2>> arr = { { 0, 1, 2, 3 } };
+ basic_mdspan<int, extents<2, 2>> span(arr);
// test copy correctness
EXPECT_EQ(span(1, 1), 3);
TEST(MultiDimArrayToMdSpanTest, constArrayToMdSpan)
{
- const MultiDimArray < std::array<int, 4>, extents < 2, 2>> constArr = {{0, 1, 2, 3}};
- basic_mdspan < const int, extents < 2, 2>> span(constArr);
+ const MultiDimArray<std::array<int, 4>, extents<2, 2>> constArr = { { 0, 1, 2, 3 } };
+ basic_mdspan<const int, extents<2, 2>> span(constArr);
EXPECT_EQ(span(0, 1), 1);
}
TEST(MultiDimArrayToMdSpanTest, nonConstArrayToConstMdSpan)
{
- MultiDimArray < std::array<int, 4>, extents < 2, 2>> arr = {{0, 1, 2, 3}};
- basic_mdspan < const int, extents < 2, 2>> span(arr);
+ MultiDimArray<std::array<int, 4>, extents<2, 2>> arr = { { 0, 1, 2, 3 } };
+ basic_mdspan<const int, extents<2, 2>> span(arr);
EXPECT_EQ(span(0, 1), 1);
}
TEST(MultiDimArrayToMdSpanTest, implicitConversionToMdSpan)
{
- auto testFunc = [](basic_mdspan < const int, extents < 2, 2>> a){
- return a(0, 0);
- };
- MultiDimArray < std::array<int, 4>, extents < 2, 2>> arr = {{0, 1, 2, 3}};
+ auto testFunc = [](basic_mdspan<const int, extents<2, 2>> a) { return a(0, 0); };
+ MultiDimArray<std::array<int, 4>, extents<2, 2>> arr = { { 0, 1, 2, 3 } };
EXPECT_EQ(testFunc(arr), 0);
}