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

converting from boost to catch test framework #2

Closed
conradsnicta opened this issue Oct 5, 2018 · 2 comments
Closed

converting from boost to catch test framework #2

conradsnicta opened this issue Oct 5, 2018 · 2 comments

Comments

@conradsnicta
Copy link
Contributor

The (temporary) tests_catch/ directory contains the converted tests from boost to catch. This is currently a work in progress.

I've converted about a third of the tests and came up with the following conversion rules. I'm not sure whether these are completely correct, so it would be useful to check these.

BOOST_AUTO_TEST_SUITE(blah) -> delete, but "blah" is used as the second argument to all instances of TEST_CASE() within a given file

BOOST_AUTO_TEST_SUITE_END() -> delete

BOOST_AUTO_TEST_CASE(testname) -> TEST_CASE("testname", "[blah]")
following the examples given in the Catch2 tutorial

BOOST_REQUIRE_SMALL(x, 0.015) -> REQUIRE(x == Approx(0.0).margin(0.015))
as per the docs for Catch2 assertion macros; not sure whether this is the best or even the correct approach

BOOST_REQUIRE_CLOSE(x, 1.23, 0.15) -> REQUIRE(result == Approx(1.23).epsilon(0.0015))
Boost uses the "0.15" to express 0.15%. I'm not certain on the Catch2 equivalent expression. I've followed the example in the docs for assertion macros, which uses .epsilon(0.01) to express a 1% difference. The Catch2 docs appear unclear on the exact meaning of .epsilon(val): "epsilon serves to set the coefficient by which a result can differ from Approx's value before it is rejected." Coefficient of what?

BOOST_REQUIRE_EQUAL(i, 123) -> REQUIRE(i == 123)
BOOST_REQUIRE_GT(x, 0.05) -> REQUIRE(x > 0.05)
BOOST_REQUIRE_GE(x, 0.05) -> REQUIRE(x >= 0.05)
BOOST_REQUIRE_LT(x, 0.05) -> REQUIRE(x < 0.05)
BOOST_REQUIRE_LE(x, 0.05) -> REQUIRE(x <= 0.05)

@zoq
Copy link
Member

zoq commented Oct 5, 2018

BOOST_REQUIRE_SMALL(x, 0.015) -> REQUIRE(x == Approx(0.0).margin(0.015))

I guess you could also write REQUIRE(std::abs(x) <= 0.015), but I think it makes sense to check against the plain output (x ).

The rest looks reasonable to me, as I understand the doc REQUIRE(result == Approx(1.23).epsilon(0.0015)) is the equivalent of BOOST_REQUIRE_CLOSE(x, 1.23, 0.15), worked on a couple of examples.

@conradsnicta
Copy link
Contributor Author

The REQUIRE(std::abs(x) <= 0.015) form is certainly more compact. However, std::abs() only works for signed types. Using size_t or arma::uword wouldn't work. From what I have seen in the current tests, not all of the values that are checked are floats. Probably a minor issue, but it would be easier not to worry about these special cases by simply being consistent with the use of the REQUIRE(x == Approx(0.0).margin(0.015)) form.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants