AutoPas  3.0.0
Loading...
Searching...
No Matches
ParticleMatcher.h
Go to the documentation of this file.
1
7#pragma once
8
9#include <gmock/gmock.h>
10#include <gtest/gtest.h>
11
13#include "autopas/utils/Math.h"
14
26bool equalParticles(const auto &lhs, const auto &rhs) {
27 return lhs.getR() == rhs.getR() && lhs.getV() == rhs.getV() && lhs.getF() == rhs.getF() && lhs.getID() == rhs.getID();
28}
29
31
40MATCHER(ParticleEq, "Comparing if two particles are strictly equal to each other") {
41 const auto &lhs = std::get<0>(arg);
42 const auto &rhs = std::get<1>(arg);
43
44 return lhs.getR() == rhs.getR() && lhs.getV() == rhs.getV() && lhs.getF() == rhs.getF() && lhs.getID() == rhs.getID();
45}
47
61bool almostEqualParticles(const auto &lhs, const auto &rhs,
62 double epsilon = autopas::utils::Math::EPSILON_RELATIVE_EQUALITY) {
63 return autopas::utils::ArrayMath::isNearRel(lhs.getR(), rhs.getR(), epsilon) &&
64 autopas::utils::ArrayMath::isNearRel(lhs.getV(), rhs.getV(), epsilon) &&
65 autopas::utils::ArrayMath::isNearRel(lhs.getF(), rhs.getF(), epsilon) && lhs.getTypeId() == rhs.getTypeId();
66}
67
69
80MATCHER_P(ParticleAlmostEq, epsilon,
81 "Comparing if two particles are almost equal to each other given a relative epsilon") {
82 const auto &lhs = std::get<0>(arg);
83 const auto &rhs = std::get<1>(arg);
84 return almostEqualParticles(lhs, rhs, epsilon);
85}
87
100bool almostEqualParticlesUlps(const auto &lhs, const auto &rhs,
101 unsigned int ulpDistance = autopas::utils::Math::MAX_ULP_DISTANCE) {
102 return autopas::utils::ArrayMath::isInUlp(lhs.getR(), rhs.getR(), ulpDistance) &&
103 autopas::utils::ArrayMath::isInUlp(lhs.getV(), rhs.getV(), ulpDistance) &&
104 autopas::utils::ArrayMath::isInUlp(lhs.getF(), rhs.getF(), ulpDistance) && lhs.getTypeId() == rhs.getTypeId();
105}
106
108
119MATCHER_P(ParticleUlpsEq, ulpDistance,
120 "Comparing if two particles are almost equal to each other given an ULP distance") {
121 const auto &lhs = std::get<0>(arg);
122 const auto &rhs = std::get<1>(arg);
123 return almostEqualParticlesUlps(lhs, rhs, ulpDistance);
124}
125
bool almostEqualParticles(const auto &lhs, const auto &rhs, double epsilon=autopas::utils::Math::EPSILON_RELATIVE_EQUALITY)
Check if two particle-like objects are almost equal using relative comparisons.
Definition: ParticleMatcher.h:61
bool equalParticles(const auto &lhs, const auto &rhs)
Check if two particle-like objects are strictly equal.
Definition: ParticleMatcher.h:26
bool almostEqualParticlesUlps(const auto &lhs, const auto &rhs, unsigned int ulpDistance=autopas::utils::Math::MAX_ULP_DISTANCE)
Check if two particle-like objects are almost equal using an ULP distance.
Definition: ParticleMatcher.h:100
bool isInUlp(Container lhs, Container rhs, unsigned int ulpDistance=Math::MAX_ULP_DISTANCE)
Function for comparing closeness of two floating point numbers using ULP (Units in the Last Place) me...
Definition: ArrayMath.h:372
bool isNearRel(Container lhs, Container rhs, double maxRelativeDifference=Math::EPSILON_RELATIVE_EQUALITY)
Returns true if arrays are elementwise relatively near each other.
Definition: ArrayMath.h:387