combining Value-Parameterized test and Type-Parametered

4,270 views
Skip to first unread message

dh

unread,
Jun 16, 2010, 1:48:42 PM6/16/10
to Google C++ Testing Framework
I have several classes which implement a common interface using
inheritance, with some of class functionality being specified as
template parameters (e.g., float vs double).

So for example, suppose you have two types of
EquationSolvers<RealType>, where each is parameterized by either
double or float, and implements a particular technique for solving an
equation.

I want to test each of these templated classes using a wide range of
input values.

Ideally, I would like to create a test fixture which is parameterized
by the particular implementation class, and which I can run using a
set of instantiated values.

How could I using gtest to implement this? It doesn't seem that
TEST_P and TYPED_TEST can be combined. Is there a proposed approach?

Zhanyong Wan (λx.x x)

unread,
Jun 16, 2010, 2:01:12 PM6/16/10
to dh, Google C++ Testing Framework

You are correct that the two cannot be combined. We *could* devise a
way to combine them, but given C++'s limitations, the result syntax
will probably be too awkward to be worth it. Not to mention how much
complexity this adds to gtest.

I'd suggest that you use the plain old for-loop for your values.

--
Zhanyong

Vlad Losev

unread,
Jun 24, 2010, 7:18:09 PM6/24/10
to Zhanyong Wan (λx.x x), Google C++ Testing Framework


2010/6/16 Zhanyong Wan (λx.x x) <w...@google.com>
You can also combine values and types in a type container:

template <typename T, int N>
class ValueTypeContainer {
 public:
  typedef T Type;
  static const int kValue = N;
};
template <typename T, int N>
const int ValueTypeContainer<T, N>::kValue;

and use ValueTypeContainer<T, N> to assemble your type lists for typed tests. If your value parameter type is not an integral type, you can use ValueTypeContainer<T, some_value>::kValue as an index into an array of real values.

--
Zhanyong

- Vlad

Sam Jaques

unread,
Jan 13, 2017, 10:22:40 AM1/13/17
to Google C++ Testing Framework, w...@google.com
Hello Vlad,

Do you have to specify every type/value combination? Specifying the range of values tested for all types is mostly wanted.
Can you explain more how on how to use it?

Thanks
Sam
Reply all
Reply to author
Forward
0 new messages