Skip to content

Commit

Permalink
ENH: Add GTest FixedArray.ValueInitialized
Browse files Browse the repository at this point in the history
Tests that initialization by `{}` properly initializes a `FixedArray`.
  • Loading branch information
N-Dekker authored and dzenanz committed Jan 23, 2023
1 parent d58bf56 commit 6bb951c
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion Modules/Core/Common/test/itkFixedArrayGTest.cxx
Expand Up @@ -25,7 +25,8 @@
#include <gtest/gtest.h>

#include <array>
#include <numeric> // For iota.
#include <numeric> // For iota.
#include <type_traits> // For remove_reference_t.


namespace
Expand Down Expand Up @@ -324,3 +325,22 @@ TEST(FixedArray, StdMemberFunctionsWork)
d3arr.data()[0] = 10;
EXPECT_EQ(cdata[0], 10);
}


// Tests that each element of a value-initialized FixedArray is itself value-initialized. By definition,
// "value-initialization" is performed when an object is constructed with an empty {} initializer.
TEST(FixedArray, ValueInitialized)
{
const auto expectEachElementValueInitialized = [](const auto & fixedArray) {
for (const auto & element : fixedArray)
{
using ValueType = std::remove_reference_t<decltype(element)>;

EXPECT_EQ(element, ValueType{});
}
};

expectEachElementValueInitialized(itk::FixedArray<int, 3>{});
expectEachElementValueInitialized(itk::FixedArray<float, 3>{});
expectEachElementValueInitialized(itk::FixedArray<void *, 3>{});
}

0 comments on commit 6bb951c

Please sign in to comment.