Google test compare vector C ++

0

I am putting together a project and trying to use google test to compare the result of some functions. The problem is that my functions return double vectors and I can only compare double or integer in google test.

I try to make one:

EXPECT_EQ(resposta, FUNC_lib::litopar(ZZIN,AMASS,MULTPL,frac,dens,checawv));

In which response is a double vector and FUNC_lib returns a double vector as well. However it automatically generates the following error:

a nonstatic member reference must be relative to a specific object.
    
asked by anonymous 24.01.2018 / 15:36

1 answer

2

As far as I know, GoogleTest does not have a single function / macro to compare vectors. But in the their documentation you have an example of how to do this:

ASSERT_EQ(x.size(), y.size()) << "Vectors x and y are of unequal length";

for (int i = 0; i < x.size(); ++i) {
   EXPECT_EQ(x[i], y[i]) << "Vectors x and y differ at index " << i;
}

I think you have to do something like this.

PS: As in your case you are comparing real numbers (floating point), it is better to use one of the EXPECT_DOUBLE_EQ or EXPECT_NEAR macros, documented here . For example, the code might look like this

ASSERT_EQ(x.size(), y.size()) << "Vectors x and y are of unequal length";

for (int i = 0; i < x.size(); ++i) {
   EXPECT_DOUBLE_EQ(x[i], y[i]) << "Vectors x and y differ at index " << i;
   // ou então o seguinte (para usar uma tolerância de comparação de 1e-4):
   // EXPECT_NEAR(x[i], y[i], 1.e-4) << "Vectors x and y differ at index " << i;
}
    
24.01.2018 / 16:16