Skip to content

Commit

Permalink
ENH: Increase coverage for miscellaneous classes
Browse files Browse the repository at this point in the history
Increase coverage for miscellaneous classes:
- Exercise the basic object methods using the
  `ITK_EXERCISE_BASIC_OBJECT_METHODS` macro.
- Test the Set/Get methods using the `ITK_TEST_SET_GET_VALUE` macro.
- Test the boolean ivars using the `ITK_TEST_SET_GET_BOOLEAN` macro, and
  rely on it to set the boolean ivar values.
- Make the calls to the Get methods be quantitative where they were just
  being called without being compared to the expected value.
- Test exceptions using the `ITK_TRY_EXPECT_EXCEPTION` macro.
- Convert existing hard-coded parameters to test input parameters and
  add parameters to the tests where appropriate so that different
  valued-tests can be added.
- Remove explicit calls to the `Print` method and rely on the basic
  method exercising macro call.
- Remove explicit calls to the `GetNameOfClass` and rely on the basic
  method exercising macro call.
  • Loading branch information
jhlegarreta authored and dzenanz committed Dec 30, 2021
1 parent cd8a17c commit 748ddf7
Show file tree
Hide file tree
Showing 93 changed files with 1,058 additions and 340 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ itkVectorImageToImageAdaptorTest(int, char *[])

// run the adaptor
auto vectorImageToImageAdaptor = VectorImageToImageAdaptorType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(vectorImageToImageAdaptor, VectorImageToImageAdaptor, ImageAdaptor);


vectorImageToImageAdaptor->SetExtractComponentIndex(componentToExtract);

vectorImageToImageAdaptor->SetImage(vectorImage);
Expand Down
2 changes: 1 addition & 1 deletion Modules/Core/Mesh/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ itk_add_test(NAME itkRegularSphereMeshSourceTest
itk_add_test(NAME itkRegularSphereMeshSourceTest2
COMMAND ITKMeshTestDriver itkRegularSphereMeshSourceTest2)
itk_add_test(NAME itkSimplexMeshAdaptTopologyFilterTest
COMMAND ITKMeshTestDriver itkSimplexMeshAdaptTopologyFilterTest)
COMMAND ITKMeshTestDriver itkSimplexMeshAdaptTopologyFilterTest 0.5 0)
itk_add_test(NAME itkSimplexMeshToTriangleMeshFilterTest
COMMAND ITKMeshTestDriver itkSimplexMeshToTriangleMeshFilterTest)
itk_add_test(NAME itkSimplexMeshVolumeCalculatorTest
Expand Down
16 changes: 16 additions & 0 deletions Modules/Core/Mesh/test/itkExtractMeshConnectedRegionsTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "itkConnectedRegionsMeshFilter.h"
#include "itkSphereMeshSource.h"
#include "itkTestingMacros.h"

#include <iostream>

Expand Down Expand Up @@ -47,6 +48,9 @@ itkExtractMeshConnectedRegionsTest(int, char *[])
PointType p = pInit;
auto connect = ConnectFilterType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(connect, ConnectedRegionsMeshFilter, MeshToMeshFilter);


connect->SetInput(inMesh);
connect->SetClosestPoint(p);
connect->AddSeed(0);
Expand All @@ -58,21 +62,33 @@ itkExtractMeshConnectedRegionsTest(int, char *[])

// Test with each of the extraction modes
connect->SetExtractionModeToAllRegions();
auto extractionMode = 4;
ITK_TEST_SET_GET_VALUE(extractionMode, connect->GetExtractionMode());
connect->Update();

extractionMode = 1;
connect->SetExtractionModeToCellSeededRegions();
ITK_TEST_SET_GET_VALUE(extractionMode, connect->GetExtractionMode());
connect->Update();

extractionMode = 5;
connect->SetExtractionModeToClosestPointRegion();
ITK_TEST_SET_GET_VALUE(extractionMode, connect->GetExtractionMode());
connect->Update();

extractionMode = 3;
connect->SetExtractionModeToLargestRegion();
ITK_TEST_SET_GET_VALUE(extractionMode, connect->GetExtractionMode());
connect->Update();

extractionMode = 0;
connect->SetExtractionModeToPointSeededRegions();
ITK_TEST_SET_GET_VALUE(extractionMode, connect->GetExtractionMode());
connect->Update();

extractionMode = 2;
connect->SetExtractionModeToSpecifiedRegions();
ITK_TEST_SET_GET_VALUE(extractionMode, connect->GetExtractionMode());
connect->Update();

// Create a Sphere for running the filter on real input data.
Expand Down
8 changes: 7 additions & 1 deletion Modules/Core/Mesh/test/itkInteriorExteriorMeshFilterTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "itkInteriorExteriorMeshFilter.h"
#include "itkMesh.h"
#include "itkSphereSpatialFunction.h"
#include "itkTestingMacros.h"

int
itkInteriorExteriorMeshFilterTest(int, char *[])
Expand Down Expand Up @@ -81,6 +82,9 @@ itkInteriorExteriorMeshFilterTest(int, char *[])
// Create a Filter
auto filter = FilterType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, InteriorExteriorMeshFilter, MeshToMeshFilter);


// Create the Spatial Function
auto spatialFunction = SpatialFunctionType::New();

Expand All @@ -94,9 +98,11 @@ itkInteriorExteriorMeshFilterTest(int, char *[])
spatialFunction->SetCenter(center);
spatialFunction->SetRadius(radius);

filter->SetSpatialFunction(spatialFunction);
ITK_TEST_SET_GET_VALUE(spatialFunction, filter->GetSpatialFunction());

// Connect the inputs
filter->SetInput(inputMesh);
filter->SetSpatialFunction(spatialFunction);

// Execute the filter
filter->Update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ InternalTest(int argc, char * argv[])
return EXIT_FAILURE;
}

ITK_EXERCISE_BASIC_OBJECT_METHODS(parametricFilter, ParametricSpaceToImageSpaceMeshFilter, MeshToMeshFilter);


// Set the input mesh for the parametric filter
parametricFilter->SetInput(mesh);

Expand Down
22 changes: 20 additions & 2 deletions Modules/Core/Mesh/test/itkSimplexMeshAdaptTopologyFilterTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@
#include "itkTriangleMeshToSimplexMeshFilter.h"
#include "itkSimplexMeshAdaptTopologyFilter.h"
#include "itkDefaultDynamicMeshTraits.h"
#include "itkTestingMacros.h"

int
itkSimplexMeshAdaptTopologyFilterTest(int, char *[])
itkSimplexMeshAdaptTopologyFilterTest(int argc, char * argv[])
{
if (argc != 3)
{
std::cerr << "Missing parameters." << std::endl;
std::cerr << "Usage: " << itkNameOfTestExecutableMacro(argv) << " threshold selectionMethod" << std::endl;
return EXIT_FAILURE;
}

// Declare the type of the input and output mesh
using TriangleMeshTraits = itk::DefaultDynamicMeshTraits<double, 3, 3, double, double>;
Expand Down Expand Up @@ -62,9 +69,20 @@ itkSimplexMeshAdaptTopologyFilterTest(int, char *[])
using FilterType = itk::SimplexMeshAdaptTopologyFilter<SimplexMeshType, SimplexMeshType>;

auto filter = FilterType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(filter, SimplexMeshAdaptTopologyFilter, MeshToMeshFilter);


auto threshold = std::stod(argv[1]);
filter->SetThreshold(threshold);
ITK_TEST_SET_GET_VALUE(threshold, filter->GetThreshold());

auto selectionMethod = std::stoi(argv[2]);
filter->SetSelectionMethod(selectionMethod);
ITK_TEST_SET_GET_VALUE(selectionMethod, filter->GetSelectionMethod());

filter->SetInput(simplexMesh);
filter->Update();
filter->Print(std::cout);

std::cout << "[TEST DONE]" << std::endl;

Expand Down
4 changes: 4 additions & 0 deletions Modules/Core/Mesh/test/itkWarpMeshFilterTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "itkWarpMeshFilter.h"
#include "itkRegularSphereMeshSource.h"
#include "itkImage.h"
#include "itkTestingMacros.h"

int
itkWarpMeshFilterTest(int, char *[])
Expand Down Expand Up @@ -102,6 +103,9 @@ itkWarpMeshFilterTest(int, char *[])

auto warpFilter = WarpFilterType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(warpFilter, WarpMeshFilter, MeshToMeshFilter);


warpFilter->SetInput(sphereMeshSource->GetOutput());

warpFilter->SetDisplacementField(deformationField);
Expand Down
10 changes: 10 additions & 0 deletions Modules/Core/SpatialObjects/test/itkNewMetaObjectTypeTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ itkNewMetaObjectTypeTest(int, char *[])
ITK_EXERCISE_BASIC_OBJECT_METHODS(converter, MetaSceneConverter, Object);


auto binaryPoints = false;
ITK_TEST_SET_GET_BOOLEAN(converter, BinaryPoints, binaryPoints);

unsigned int transformPrecision = 6;
converter->SetTransformPrecision(transformPrecision);
ITK_TEST_SET_GET_VALUE(transformPrecision, converter->GetTransformPrecision());

auto writeImagesInSeparateFile = false;
ITK_TEST_SET_GET_BOOLEAN(converter, WriteImagesInSeparateFile, writeImagesInSeparateFile);

converter->RegisterMetaConverter("Dummy", "DummySpatialObject", dummyConverter);

MetaScene * metaScene = converter->CreateMetaScene(group);
Expand Down
13 changes: 9 additions & 4 deletions Modules/Core/SpatialObjects/test/itkTubeSpatialObjectTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ itkTubeSpatialObjectTest(int, char *[])
ITK_EXERCISE_BASIC_OBJECT_METHODS(tube1, TubeSpatialObject, PointBasedSpatialObject);


auto root = false;
ITK_TEST_SET_GET_BOOLEAN(tube1, Root, root);

tube1->GetProperty().SetName("Tube 1");
tube1->SetId(1);

Expand Down Expand Up @@ -458,18 +461,20 @@ itkTubeSpatialObjectTest(int, char *[])

std::cout << "[PASSED]" << std::endl;

// Testing IsInside() with m_EndType set to rounded end-type;
std::cout << "IsInside() with m_RoundedEnd=True: ";
// Testing IsInside() with different end types
auto endRounded = false;
ITK_TEST_SET_GET_BOOLEAN(tube1, EndRounded, endRounded);

p1.Fill(19.5);
tube1->SetEndRounded(false);

if (tube1->IsInsideInWorldSpace(p1))
{
std::cout << "[FAILED]" << std::endl;
return EXIT_FAILURE;
}

tube1->SetEndRounded(true);
endRounded = true;
ITK_TEST_SET_GET_BOOLEAN(tube1, EndRounded, endRounded);

if (!tube1->IsInsideInWorldSpace(p1))
{
Expand Down
26 changes: 16 additions & 10 deletions Modules/Core/Transform/test/itkBSplineDeformableTransformTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "itkVersorRigid3DTransform.h"

#include "itkTextOutput.h"
#include "itkTestingMacros.h"

/**
* This module test the functionality of the BSplineDeformableTransform class.
Expand Down Expand Up @@ -79,10 +80,23 @@ itkBSplineDeformableTransformTest1()
*/
auto transform = TransformType::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(transform, BSplineDeformableTransform, BSplineBaseTransform);

transform->SetGridSpacing(spacing);
ITK_TEST_SET_GET_VALUE(spacing, transform->GetGridSpacing());

transform->SetGridOrigin(origin);
ITK_TEST_SET_GET_VALUE(origin, transform->GetGridOrigin());

transform->SetGridRegion(region);
transform->Print(std::cout);
ITK_TEST_SET_GET_VALUE(region, transform->GetGridRegion());

using DirectionType = TransformType::DirectionType;
DirectionType direction = transform->GetCoefficientImages()[0]->GetDirection();
transform->SetGridDirection(direction);
ITK_TEST_SET_GET_VALUE(direction, transform->GetGridDirection());

std::cout << transform->GetValidRegion() << std::endl;

/**
* Allocate memory for the parameters
Expand Down Expand Up @@ -138,7 +152,7 @@ itkBSplineDeformableTransformTest1()
// optional: set bulk transform parameters

transform->SetBulkTransform(bulkTransform);
std::cout << "BulkTransform: " << transform->GetBulkTransform() << std::endl;
ITK_TEST_SET_GET_VALUE(bulkTransform, transform->GetBulkTransform());

/**
* Transform some points
Expand Down Expand Up @@ -382,14 +396,6 @@ itkBSplineDeformableTransformTest1()
}
}

/**
* Exercise other methods
*/
std::cout << transform->GetGridRegion() << std::endl;
std::cout << transform->GetGridSpacing() << std::endl;
std::cout << transform->GetGridOrigin() << std::endl;
std::cout << transform->GetValidRegion() << std::endl;

using EvenOrderTransformType = itk::BSplineDeformableTransform<CoordinateRepType, SpaceDimension, 2>;
auto evenOrderTransform = EvenOrderTransformType::New();
if (evenOrderTransform.IsNull())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <iostream>

#include "itkRigid3DPerspectiveTransform.h"

#include "itkTestingMacros.h"

int
itkRigid3DPerspectiveTransformTest(int, char *[])
Expand All @@ -35,6 +35,44 @@ itkRigid3DPerspectiveTransformTest(int, char *[])

bool Ok = true;

// Test exceptions
{
auto transform = TransformType::New();

typename TransformType::InputVectorType vector{ { 1.0, 4.0, 9.0 } };
ITK_TRY_EXPECT_EXCEPTION(transform->TransformVector(vector));

typename TransformType::InputVnlVectorType vnlVector;
vnlVector.fill(1.0);
ITK_TRY_EXPECT_EXCEPTION(transform->TransformVector(vnlVector));

typename TransformType::InputCovariantVectorType covVector;
covVector.Fill(1.0);
ITK_TRY_EXPECT_EXCEPTION(transform->TransformCovariantVector(covVector));

typename TransformType::InputPointType point{ { 1.0, 1.0, 1.0 } };
typename TransformType::JacobianPositionType jacobianPosition;
ITK_TRY_EXPECT_EXCEPTION(transform->ComputeJacobianWithRespectToPosition(point, jacobianPosition));
}

// Exercise basic object methods and test Set/Get macros
{
auto transform = TransformType::New();

EXERCISE_BASIC_OBJECT_METHODS(transform, Rigid3DPerspectiveTransform, Transform);


typename TransformType::OffsetType fixedOffset;
fixedOffset.Fill(0);

transform->SetFixedOffset(fixedOffset);
ITK_TEST_SET_GET_VALUE(fixedOffset, transform->GetFixedOffset());

typename TransformType::InputPointType centerOfRotation;
centerOfRotation.Fill(0);
transform->SetCenterOfRotation(centerOfRotation);
ITK_TEST_SET_GET_VALUE(centerOfRotation, transform->GetCenterOfRotation());
}

/* Create a 3D identity transformation and show its parameters */
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "itkVectorGradientAnisotropicDiffusionImageFilter.h"
#include "itkVectorCurvatureAnisotropicDiffusionImageFilter.h"
#include "itkNullImageToImageFilterDriver.hxx"
#include "itkTestingMacros.h"

inline std::ostream &
operator<<(std::ostream & o, const itk::Vector<float, 3> & v)
Expand All @@ -38,6 +39,11 @@ itkVectorAnisotropicDiffusionImageFilterTest(int itkNotUsed(argc), char * itkNot
// Set up Gradient diffusion filter
itk::VectorGradientAnisotropicDiffusionImageFilter<ImageType, ImageType>::Pointer filter =
itk::VectorGradientAnisotropicDiffusionImageFilter<ImageType, ImageType>::New();

ITK_EXERCISE_BASIC_OBJECT_METHODS(
filter, VectorGradientAnisotropicDiffusionImageFilter, AnisotropicDiffusionImageFilter);


filter->SetNumberOfIterations(1);
filter->SetConductanceParameter(3.0f);
filter->SetTimeStep(0.125f);
Expand Down
Loading

0 comments on commit 748ddf7

Please sign in to comment.