Skip to content

Commit

Permalink
ENH: Add ValueInitializedIsZeroFilled tests for derived FixedArray types
Browse files Browse the repository at this point in the history
Tested that a "value-initialized" object of one of the `FixedArray` derived
types, `CovariantVector` `DiffusionTensor3D`, `RGBAPixel`, `RGBPixel`,
`SymmetricSecondRankTensor`, `Point`, or `Vector` is zero-filled.
  • Loading branch information
N-Dekker committed Feb 11, 2024
1 parent 8440914 commit aa38dce
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Modules/Core/Common/test/CMakeLists.txt
Expand Up @@ -1719,7 +1719,9 @@ set(ITKCommonGTests
itkConnectedImageNeighborhoodShapeGTest.cxx
itkConstantBoundaryImageNeighborhoodPixelAccessPolicyGTest.cxx
itkCopyGTest.cxx
itkCovariantVectorGTest.cxx
itkDerefGTest.cxx
itkDiffusionTensor3DGTest.cxx
itkExceptionObjectGTest.cxx
itkFixedArrayGTest.cxx
itkImageNeighborhoodOffsetsGTest.cxx
Expand All @@ -1741,9 +1743,12 @@ set(ITKCommonGTests
itkOffsetGTest.cxx
itkOptimizerParametersGTest.cxx
itkPointGTest.cxx
itkRGBAPixelGTest.cxx
itkRGBPixelGTest.cxx
itkShapedImageNeighborhoodRangeGTest.cxx
itkSizeGTest.cxx
itkSmartPointerGTest.cxx
itkSymmetricSecondRankTensorGTest.cxx
itkVectorContainerGTest.cxx
itkVectorGTest.cxx
itkWeakPointerGTest.cxx
Expand Down
37 changes: 37 additions & 0 deletions Modules/Core/Common/test/itkCovariantVectorGTest.cxx
@@ -0,0 +1,37 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/

// First include the header file to be tested:
#include "itkCovariantVector.h"
#include <gtest/gtest.h>


// Tests that a CovariantVector that is "value-initialized" (by empty braces, `{}`) is zero-filled.
TEST(CovariantVector, ValueInitializedIsZeroFilled)
{
const auto expectZeroFilled = [](const auto & fixedArray) {
for (const auto element : fixedArray)
{
EXPECT_EQ(element, 0);
}
};

expectZeroFilled(itk::CovariantVector<int>{});
expectZeroFilled(itk::CovariantVector<float, 2>{});
expectZeroFilled(itk::CovariantVector<double, 4>{});
}
37 changes: 37 additions & 0 deletions Modules/Core/Common/test/itkDiffusionTensor3DGTest.cxx
@@ -0,0 +1,37 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/

// First include the header file to be tested:
#include "itkDiffusionTensor3D.h"
#include <gtest/gtest.h>


// Tests that a DiffusionTensor3D that is "value-initialized" (by empty braces, `{}`) is zero-filled.
TEST(DiffusionTensor3D, ValueInitializedIsZeroFilled)
{
const auto expectZeroFilled = [](const auto & fixedArray) {
for (const auto element : fixedArray)
{
EXPECT_EQ(element, 0);
}
};

expectZeroFilled(itk::DiffusionTensor3D<int>{});
expectZeroFilled(itk::DiffusionTensor3D<float>{});
expectZeroFilled(itk::DiffusionTensor3D<double>{});
}
16 changes: 16 additions & 0 deletions Modules/Core/Common/test/itkPointGTest.cxx
Expand Up @@ -48,6 +48,22 @@ Expect_Point_can_be_constructed_by_std_array()
} // namespace


// Tests that a Point that is "value-initialized" (by empty braces, `{}`) is zero-filled.
TEST(Point, ValueInitializedIsZeroFilled)
{
const auto expectZeroFilled = [](const auto & fixedArray) {
for (const auto element : fixedArray)
{
EXPECT_EQ(element, 0);
}
};

expectZeroFilled(itk::Point<int>{});
expectZeroFilled(itk::Point<float, 2>{});
expectZeroFilled(itk::Point<double, 4>{});
}


// Tests that a Point can be constructed by specifying
// its coordinates by an std::array<ValueType, VDimension>.
TEST(Point, CanBeConstructedByStdArray)
Expand Down
37 changes: 37 additions & 0 deletions Modules/Core/Common/test/itkRGBAPixelGTest.cxx
@@ -0,0 +1,37 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/

// First include the header file to be tested:
#include "itkRGBAPixel.h"
#include <gtest/gtest.h>


// Tests that a RGBAPixel that is "value-initialized" (by empty braces, `{}`) is zero-filled.
TEST(RGBAPixel, ValueInitializedIsZeroFilled)
{
const auto expectZeroFilled = [](const auto & fixedArray) {
for (const auto element : fixedArray)
{
EXPECT_EQ(element, 0);
}
};

expectZeroFilled(itk::RGBAPixel<>{});
expectZeroFilled(itk::RGBAPixel<std::uint8_t>{});
expectZeroFilled(itk::RGBAPixel<float>{});
}
37 changes: 37 additions & 0 deletions Modules/Core/Common/test/itkRGBPixelGTest.cxx
@@ -0,0 +1,37 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/

// First include the header file to be tested:
#include "itkRGBPixel.h"
#include <gtest/gtest.h>


// Tests that a RGBPixel that is "value-initialized" (by empty braces, `{}`) is zero-filled.
TEST(RGBPixel, ValueInitializedIsZeroFilled)
{
const auto expectZeroFilled = [](const auto & fixedArray) {
for (const auto element : fixedArray)
{
EXPECT_EQ(element, 0);
}
};

expectZeroFilled(itk::RGBPixel<>{});
expectZeroFilled(itk::RGBPixel<std::uint8_t>{});
expectZeroFilled(itk::RGBPixel<float>{});
}
37 changes: 37 additions & 0 deletions Modules/Core/Common/test/itkSymmetricSecondRankTensorGTest.cxx
@@ -0,0 +1,37 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/

// First include the header file to be tested:
#include "itkSymmetricSecondRankTensor.h"
#include <gtest/gtest.h>


// Tests that a SymmetricSecondRankTensor that is "value-initialized" (by empty braces, `{}`) is zero-filled.
TEST(SymmetricSecondRankTensor, ValueInitializedIsZeroFilled)
{
const auto expectZeroFilled = [](const auto & fixedArray) {
for (const auto element : fixedArray)
{
EXPECT_EQ(element, 0);
}
};

expectZeroFilled(itk::SymmetricSecondRankTensor<int>{});
expectZeroFilled(itk::SymmetricSecondRankTensor<float, 2>{});
expectZeroFilled(itk::SymmetricSecondRankTensor<double, 4>{});
}
16 changes: 16 additions & 0 deletions Modules/Core/Common/test/itkVectorGTest.cxx
Expand Up @@ -48,6 +48,22 @@ Expect_itk_Vector_can_be_constructed_by_std_array()
} // namespace


// Tests that an itk::Vector that is "value-initialized" (by empty braces, `{}`) is zero-filled.
TEST(Vector, ValueInitializedIsZeroFilled)
{
const auto expectZeroFilled = [](const auto & fixedArray) {
for (const auto element : fixedArray)
{
EXPECT_EQ(element, 0);
}
};

expectZeroFilled(itk::Vector<int>{});
expectZeroFilled(itk::Vector<float, 2>{});
expectZeroFilled(itk::Vector<double, 4>{});
}


// Tests that an itk::Vector can be constructed by specifying
// its coordinates by an std::array<ValueType, VDimension>.
TEST(Vector, CanBeConstructedByStdArray)
Expand Down

0 comments on commit aa38dce

Please sign in to comment.