Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMP: Add coverage IsCongruentImageGeometry IsSameImageGeometryAs #4592

Conversation

hjmjohnson
Copy link
Member

PR Checklist

  • No API changes were made (or the changes have been approved)
  • No major design changes were made (or the changes have been approved)
  • Added test (or behavior not changed)

@hjmjohnson hjmjohnson added the area:Documentation Issues affecting the Documentation module label Apr 17, 2024
@hjmjohnson hjmjohnson added this to the ITK 5.4.0 milestone Apr 17, 2024
@hjmjohnson hjmjohnson self-assigned this Apr 17, 2024
@github-actions github-actions bot added type:Compiler Compiler support or related warnings type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Core Issues affecting the Core module type:Coverage Code coverage impacts and removed area:Documentation Issues affecting the Documentation module labels Apr 17, 2024
Comment on lines +236 to 247
// Test that a const pointer can be instantiated from a non-const pointer
Image::ConstPointer myconstptr = image;
if (!image->IsCongruentImageGeometry(myconstptr, 0.0, 0.0))
{
std::cerr << "Image compare to self fails IsCongruentImageGeometry" << std::endl;
}
if (!image->IsSameImageGeometryAs(myconstptr, 0.0, 0.0))
{
std::cerr << "Image compare to self fails IsSameImageGeometryAs" << std::endl;
}

return (EXIT_SUCCESS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, your test does not fail when IsCongruentImageGeometry returns false! It reaches return (EXIT_SUCCESS) anyway.

Please 🙏 consider using GoogleTest for tests like this. With GTest, it would just be:

EXPECT_TRUE(image->IsSameImageGeometryAs(myconstptr, 0.0, 0.0));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added these methods for SimpleITK and took full advantage of things for testing:
https://github.com/SimpleITK/SimpleITK/pull/2097/files#diff-b59e3fb36168b499154d941782889660f04ab0c66ed5a31f4a994ca88764b17d

@hjmjohnson I'llI see what I can do in the itkImageGTest.cxx file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ITK_TEST_EXPECT_TRUE can do the job.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhlegarreta I agree, if you want to keep using the old ITK test framework (instead of GoogleTest), you can do something like:

ITK_TEST_EXPECT_TRUE(image->IsSameImageGeometryAs(myconstptr, 0.0, 0.0));

FYI, there's a small difference between ITK_TEST_EXPECT_TRUE and GTest EXPECT_TRUE: ITK_TEST_EXPECT_TRUE will exit the test immediately if it fails, whereas with a GTest EXPECT_TRUE failure, the unit test will not exit immediately. (Even though it will be reported as a test failure, by GTest.)

@hjmjohnson
Copy link
Member Author

Superceeded by @blowekamp #4594

@hjmjohnson hjmjohnson closed this Apr 17, 2024
@hjmjohnson hjmjohnson deleted the add-new-test-coverage branch April 19, 2024 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:Core Issues affecting the Core module type:Compiler Compiler support or related warnings type:Coverage Code coverage impacts type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants