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

Tests using c++ templates #48

Open
MarcelInTO opened this issue Mar 10, 2021 · 1 comment
Open

Tests using c++ templates #48

MarcelInTO opened this issue Mar 10, 2021 · 1 comment

Comments

@MarcelInTO
Copy link
Contributor

MarcelInTO commented Mar 10, 2021

It would be useful to be able to define a test that uses C++ templates to test template functions. For example, if I have a function like this:

template <typename T>
inline bool isSubnormal(const T & v)
{
    return std::isfinite(v) && !std::isnormal(v) && v != T(0.0);
}

Currently, my tests look like this:

CESTER_TEST(isSubnormalFloatWithSubnormalInput, inst,
    float p1 = std::numeric_limits<float>::min() / float(2.0);
    cester_assert_true(isSubnormal(p1));
)
CESTER_TEST(isSubnormalDoubleWithSubnormalInput, inst,
    double p1 = std::numeric_limits<double>::min() / double(2.0);
    cester_assert_true(isSubnormal(p1));
)

It would be great to do something like:

CESTER_TEMPLATE_TEST(isSubnormalWithSubnormalInput, inst, T, (float, double, long double),
    T p1 = std::numeric_limits<T>::min() / T(2.0);
    cester_assert_true(isSubnormal(p1));
)

Basically - add parameters specifying the template variable and the list of types to instantiate.

It would have to generate names for each of the tests that include an indication what T was for that test.

I have not really thought through the ideal syntax, because if you have more than one template variable, my suggested syntax is not very practical, but you get the idea.....

@Thecarisma
Copy link
Member

Thecarisma commented Mar 10, 2021 via email

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