#include "gromacs/selection/nbsearch.h"
-#include <gtest/gtest.h>
-
#include <cmath>
#include <algorithm>
#include <numeric>
#include <vector>
+#include <gtest/gtest.h>
+
#include "gromacs/math/vec.h"
#include "gromacs/pbcutil/pbc.h"
#include "gromacs/random/random.h"
#include "gromacs/topology/block.h"
#include "gromacs/utility/smalloc.h"
+#include "gromacs/utility/stringutil.h"
#include "testutils/testasserts.h"
struct TestPosition
{
- TestPosition() : refMinDist(0.0), refNearestPoint(-1)
- {
- clear_rvec(x);
- }
explicit TestPosition(const rvec x)
: refMinDist(0.0), refNearestPoint(-1)
{
}
}
+//! Helper function for formatting test failure messages.
+std::string formatVector(const rvec x)
+{
+ return gmx::formatString("[%.3f, %.3f, %.3f]", x[XX], x[YY], x[ZZ]);
+}
+
/*! \brief
* Helper function to check that all expected pairs were found.
*/
-static void checkAllPairsFound(const RefPairList &refPairs)
+void checkAllPairsFound(const RefPairList &refPairs, const rvec refPos[],
+ int testPosIndex, const rvec testPos)
{
// This could be elegantly expressed with Google Mock matchers, but that
// has a significant effect on the runtime of the tests...
+ int count = 0;
+ RefPairList::const_iterator first;
for (RefPairList::const_iterator i = refPairs.begin(); i != refPairs.end(); ++i)
{
if (!i->bFound)
{
- ADD_FAILURE()
- << "Some pairs within the cutoff were not found.";
- break;
+ ++count;
+ first = i;
}
}
+ if (count > 0)
+ {
+ ADD_FAILURE()
+ << "Some pairs (" << count << "/" << refPairs.size() << ") "
+ << "within the cutoff were not found. First pair:\n"
+ << " Ref: " << first->refIndex << " at "
+ << formatVector(refPos[first->refIndex]) << "\n"
+ << "Test: " << testPosIndex << " at " << formatVector(testPos) << "\n"
+ << "Dist: " << first->distance;
+ }
}
void NeighborhoodSearchTest::testPairSearch(
{
if (prevTestPos != -1)
{
- checkAllPairsFound(refPairs);
+ checkAllPairsFound(refPairs, data.refPos_, prevTestPos,
+ data.testPositions_[prevTestPos].x);
}
const int testIndex = pair.testIndex();
if (remainingTestPositions.count(testIndex) == 0)
<< "Distance computed by the neighborhood search does not match.";
}
}
- checkAllPairsFound(refPairs);
+ checkAllPairsFound(refPairs, data.refPos_, prevTestPos,
+ data.testPositions_[prevTestPos].x);
for (std::set<int>::const_iterator i = remainingTestPositions.begin();
i != remainingTestPositions.end(); ++i)
{