Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6656641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:40:06+00:00 2026-05-26T01:40:06+00:00

I have two implementations of an algorithm working on arrays and returning a single

  • 0

I have two implementations of an algorithm working on arrays and returning a single value, a slow and naive but correct method A and an optimized method B that may be buggy at corners of the input parameter space. Method B has branches depending on the size of the input array and I’d like to test B against A for different input array sizes. Both methods are templated to work with different types.

I’m just starting to use googletest for the first time, but I don’t really see a clear way of how to do this with a fixture (the following is simplified, there is more to set up to get the tests going and I’d also like to run other tests on 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 the fixture definition would be to define the types

typedef ::testing::Types<char, int, unsigned int> MyTypes;
TYPED_TEST_CASE(BTest, MyTypes);

but this shows the limitation, that only a single template parameter is allowed for classes derived from ::testing::Test. Am I reading this right? How would one go about this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:40:07+00:00Added an answer on May 26, 2026 at 1:40 am

    You can always pack multiple parameter types into a tuple. To pack integer values, you can use type-value converters like this:

    template <size_t N> class TypeValue {
     public:
      static const size_t value = N;
    };
    template <size_t N> const size_t TypeValue<N>::value;
    
    #include <tuple>  /// Or <tr1/tuple>
    using testing::Test;
    using testing::Types;
    using std::tuple;  // Or std::tr1::tuple
    using std::element;
    
    template<typename T>  // tuple<type to test on, test array size>
    class BTest : public Test {
     public:
      typedef element<0, T>::type ElementType;
      static const size_t kElementCount = element<1, T>::type::value;
      ElementType* data; // test data
    
     public:
      BTest() {
        // allocate data, populate data with random elements
      }
      ~BTest();
      ElementType run_method_a_on_data(); // reference: method A implementation
    };
    template <typename T> const size_t BTest<T>::kElementCount;
    
    ....
    
    typedef Types<tuple<char, TypeValue<10> >, tuple<int, TypeValue<199> > MyTypes;
    TYPED_TEST_CASE(BTest, MyTypes);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two implementations of a method, one for value types and another for
have two algorithm implementations: average(List) -> sum(List) / len(List). sum([]) -> 0; sum([Head |
I have two arrays of animals (for example). $array = array( array( 'id' =>
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
Sorry I dont know the correct terminology to use but I have a 3x3
I have been working on SSE optimization for a video processing algorithm recently. I
I have two interfaces which are generic, IComparable<T> , with method public boolean gt(T
Given I have two File objects I can think of the following implementation: public
I'm trying a multithreaded Core Data implementation on iPhone SDK 3.1.3. I have two
I have been studying unicode and its Python implementation now for two days, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.