I have a question with BOOST_CHECK_EQUAL_COLLECTIONS. It is straightforward to compare the calculated array with the expected one if the data type of the array happens to be int or char. However, when the data type is float or double, using BOOST_CHECK_EQUAL_COLLECTIONS becomes very tricky. For example,
std::vector<float> dis_array;
Distance<float,float>(pt_array,base_point,dis_array);
std::vector<float> dis_ground_truth;
dis_ground_truth.push_back(3.6055f);
dis_ground_truth.push_back(1);
dis_ground_truth.push_back(9.2194f);
BOOST_CHECK_EQUAL_COLLECTIONS(dis_ground_truth.begin(), dis_ground_truth.end(),
dis_array.begin(),dis_array.end());
However, when running BOOST unit test framework, the following error message appear:
{ dis_array.begin(), dis_array.end() } failed.
Mismatch in a position 0: 3.6055 != 3.60555
Mismatch in a position 2: 9.2194 != 9.21954
The problem comes from comparing two variables of double type, and it is very hard to give one variable the exact expected value if its type is double. For the now being, the only solution I can think of is to compare the difference of the two arrays, and if the norm of the difference is below than a small threshold, then it will pass the unit test. Any other ideas? Thanks!