Skip to content
Snippets Groups Projects
Commit 1f031eec authored by Carl Philipp Klemm's avatar Carl Philipp Klemm
Browse files

improve fvalueEq

add test case for deduplication
parent c933b28f
No related branches found
No related tags found
No related merge requests found
#include "basicmath.h" #include "basicmath.h"
#include <algorithm> #include <algorithm>
#include <random> #include <random>
#include <limits>
#include "eistype.h" #include "eistype.h"
...@@ -213,15 +214,15 @@ void eis::removeDuplicates(std::vector<eis::DataPoint>& data) ...@@ -213,15 +214,15 @@ void eis::removeDuplicates(std::vector<eis::DataPoint>& data)
std::sort(data.begin(), data.end()); std::sort(data.begin(), data.end());
std::vector<eis::DataPoint>::iterator it = data.begin(); std::vector<eis::DataPoint>::iterator it = data.begin();
while((it = std::adjacent_find(data.begin(), data.end())) != data.end()) while((it = std::adjacent_find(data.begin(), data.end(),
[](const eis::DataPoint& a, const eis::DataPoint& b){return fvalueEq(a.omega, b.omega);})) != data.end())
{ {
std::cout<<"erase\n";
data.erase(it); data.erase(it);
} }
} }
bool eis::fvalueEq(fvalue a, fvalue b, fvalue epsilon) bool eis::fvalueEq(fvalue a, fvalue b, unsigned int ulp)
{ {
fvalue epsilon = std::numeric_limits<fvalue>::epsilon()*std::fabs(a+b)*ulp;
return a - epsilon < b && a + epsilon > b; return a - epsilon < b && a + epsilon > b;
} }
...@@ -18,6 +18,6 @@ namespace eis ...@@ -18,6 +18,6 @@ namespace eis
fvalue maximumNyquistJump(const std::vector<eis::DataPoint>& data); fvalue maximumNyquistJump(const std::vector<eis::DataPoint>& data);
void noise(std::vector<eis::DataPoint>& data, double amplitude, bool relative); void noise(std::vector<eis::DataPoint>& data, double amplitude, bool relative);
void removeDuplicates(std::vector<eis::DataPoint>& data); void removeDuplicates(std::vector<eis::DataPoint>& data);
bool fvalueEq(fvalue a, fvalue b, fvalue epsilon = 0.001); bool fvalueEq(fvalue a, fvalue b, unsigned int ulp = 4);
} }
...@@ -334,6 +334,24 @@ static bool testEisNyquistDistance() ...@@ -334,6 +334,24 @@ static bool testEisNyquistDistance()
} }
} }
static bool testLoadDeduplication()
{
const std::filesystem::path filePath("./relaxis_rp-rp_0.csv");
eis::EisSpectra spectra(filePath);
if(spectra.data.empty())
{
eis::Log(eis::Log::INFO)<<__func__<<" Unable to load "<<filePath<<" skiping test";
return true;
}
if(eis::fvalueEq(spectra.data[spectra.data.size()-1].omega, spectra.data[spectra.data.size()-2].omega+2))
{
eis::Log(eis::Log::ERROR)<<__func__<<" deduplication failed";
return false;
}
return true;
}
static bool testTranslators() static bool testTranslators()
{ {
const std::string boukamp("R(RP)"); const std::string boukamp("R(RP)");
...@@ -383,6 +401,9 @@ int main(int argc, char** argv) ...@@ -383,6 +401,9 @@ int main(int argc, char** argv)
if(!modelConsistancy()) if(!modelConsistancy())
return 2; return 2;
if(!testLoadDeduplication())
return 3;
if(!runRescale()) if(!runRescale())
return 3; return 3;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment