I have two implementations of an algorithm that works on arrays and returns the same value, slow and naive, but the correct method A and optimized method B , which may be wrong in the corners of the space of the input parameters. Method B has branches depending on the size of the input array, and I would like to check B on A for different sizes of input arrays. Both methods are designed to work with different types.
Iβm just starting to use googletest for the first time, but in fact I donβt see a clear way to do this using fasteners (the following is simplified: there is more to configure the tests and I would also like to run other tests according to the data):
template<typename T, unsigned int length> // type to test on, test array size class BTest : public ::testing:Test { public: T* data; // test data public: BTest(); // allocate data, populate data with random elements ~BTest(); T run_method_a_on_data(); // reference: method A implementation }; // ... TYPED_TEST_CASE(...) // set up types, see text below TYPED_TEST(...) { // test that runs method B on data and compares to run_method_a_on_data() }
In the googletest documentation, the step to run the actual tests after determining the device will determine the types
typedef ::testing::Types<char, int, unsigned int> MyTypes; TYPED_TEST_CASE(BTest, MyTypes);
but this shows the limitation that for classes derived from ::testing::Test , only one template parameter is allowed. Am I reading this correctly? How to do it?
source share