Page MenuHomec4science

test.hh
No OneTemporary

File Metadata

Created
Fri, May 3, 04:39
/**
*
* @author Lucas Frérot <lucas.frerot@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2017 EPFL (Ecole Polytechnique Fédérale de
* Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
* Solides)
*
* Tamaas is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Tamaas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Tamaas. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "tamaas.hh"
#include <thrust/complex.h>
#include <utility>
#include <algorithm>
#include <fftw3.h>
#include <numeric>
#include <array>
#include "gtest/gtest.h"
template<typename T, typename U>
bool compare(T&& a, U&& b) {
return std::mismatch(std::begin(a),
std::end(a),
std::begin(b))
== std::make_pair(std::end(a),
std::end(b));
}
template <typename T, typename U, typename Pred>
bool compare(T&& a, U&& b, Pred&& pred) {
return std::mismatch(std::begin(a),
std::end(a),
std::begin(b), pred)
== std::make_pair(std::end(a),
std::end(b));
}
struct AreFloatEqual {
template <typename T, typename U>
inline bool operator()(T&& x, U&& y) {
//T y = reinterpret_cast<T>(z);
tamaas::Real tolerance = 1e-12;
tamaas::Real abs_max = std::max(std::abs(x), std::abs(y));
abs_max = std::max(abs_max, tamaas::Real(1.));
return std::abs(x - y) <= (tolerance * abs_max);
}
};
struct AreComplexEqual {
inline bool operator()(const tamaas::Complex & x, const fftw_complex & y) {
auto equal = AreFloatEqual();
return equal(x.real(), y[0]) && equal(x.imag(), y[1]);
}
};

Event Timeline