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

test: fix tests for new spctra file version

parent 30866524
No related branches found
No related tags found
No related merge requests found
...@@ -162,7 +162,9 @@ size_t deepestBraket(const std::string& str, std::string bracketChars, size_t* l ...@@ -162,7 +162,9 @@ size_t deepestBraket(const std::string& str, std::string bracketChars, size_t* l
void stripQuotes(std::string& in) void stripQuotes(std::string& in)
{ {
in.erase(std::remove_if(in.begin(), in.end()+1, [](unsigned char ch){return ch == '"' || ch == '\'';})); in.erase(std::remove_if(in.begin(), in.end(), [](unsigned char ch){return ch == '"' || ch == '\'';}), in.end());
if(in[in.size()-1] == '"' || in[in.size()-1] == '\'')
in.pop_back();
} }
size_t eisRemoveUnneededBrackets(std::string& in, long int bracketStart) size_t eisRemoveUnneededBrackets(std::string& in, long int bracketStart)
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include "strops.h" #include "strops.h"
#include "translators.h" #include "translators.h"
const char testEisSpectraFile[] = const char testEisSpectraFile10[] =
"EISF, 1.0.0\n" "EISF, 1.0.0\n"
"\"r-cr-cr\", 0\n" "\"r-cr-cr\", 0\n"
"labels\n" "labels\n"
...@@ -45,51 +45,24 @@ const char testEisSpectraFile[] = ...@@ -45,51 +45,24 @@ const char testEisSpectraFile[] =
"1.930698e+00, 0.000000e+00, 0.000000e+00\n" "1.930698e+00, 0.000000e+00, 0.000000e+00\n"
"2.682696e+00, 0.000000e+00, 0.000000e+00\n" "2.682696e+00, 0.000000e+00, 0.000000e+00\n"
"3.727594e+00, 0.000000e+00, 0.000000e+00\n" "3.727594e+00, 0.000000e+00, 0.000000e+00\n"
"5.179475e+00, 0.000000e+00, 0.000000e+00\n" "5.179475e+00, 0.000000e+00, 0.000000e+00\n";
"7.196858e+00, 0.000000e+00, 0.000000e+00\n"
"1.000000e+01, 0.000000e+00, 0.000000e+00\n" const char testEisSpectraFile11[] =
"1.389496e+01, 0.000000e+00, 0.000000e+00\n" "EISF, 1.1.0\n"
"1.930698e+01, 0.000000e+00, 0.000000e+00\n" "\"Unkown\"\n"
"2.682696e+01, 0.000000e+00, 0.000000e+00\n" "File origin\n"
"3.727594e+01, 0.000000e+00, 0.000000e+00\n" "CoinCellHell mesurement file\n"
"5.179476e+01, 0.000000e+00, 0.000000e+00\n" "labelsNames\n"
"7.196858e+01, 0.000000e+00, 0.000000e+00\n" "\"step\", \"substep\", \"cellid\", \"temparature\", \"ocv\", \"charge_cycles\", \"thermal_cycles\", \"last_avg_cap\", \"last_avg_step\", \"last_cap\", \"last_cap_step\", \"soc\"\n"
"1.000000e+02, 0.000000e+00, 0.000000e+00\n" "labels\n"
"1.389496e+02, 0.000000e+00, 0.000000e+00\n" "2, 4, 0, 36.1, 3.55081, 1, 8, 0.0448139, 11, 0.0428723, 120, -1\n"
"1.930698e+02, 0.000000e+00, 0.000000e+00\n" "omega, real, im\n"
"2.682696e+02, 0.000000e+00, 0.000000e+00\n" "6.293263e-01, 1.214581e+00, -1.917704e-01\n"
"3.727596e+02, 0.000000e+00, 0.000000e+00\n" "8.324402e-01, 1.193806e+00, -1.599901e-01\n"
"5.179476e+02, 0.000000e+00, 0.000000e+00\n" "1.106767e+00, 1.178542e+00, -1.361918e-01\n"
"7.196858e+02, 0.000000e+00, 0.000000e+00\n" "1.465296e+00, 1.166301e+00, -1.212671e-01\n"
"1.000001e+03, 0.000000e+00, 0.000000e+00\n" "1.947914e+00, 1.156239e+00, -1.091308e-01\n"
"1.389496e+03, 0.000000e+00, 0.000000e+00\n" "2.563042e+00, 1.147515e+00, -1.042249e-01\n";
"1.930698e+03, 0.000000e+00, 0.000000e+00\n"
"2.682698e+03, 0.000000e+00, 0.000000e+00\n"
"3.727595e+03, 0.000000e+00, 0.000000e+00\n"
"5.179476e+03, 0.000000e+00, 0.000000e+00\n"
"7.196858e+03, 0.000000e+00, 0.000000e+00\n"
"1.000000e+04, 0.000000e+00, 0.000000e+00\n"
"1.389497e+04, 0.000000e+00, 0.000000e+00\n"
"1.930699e+04, 0.000000e+00, 0.000000e+00\n"
"2.682697e+04, 0.000000e+00, 0.000000e+00\n"
"3.727595e+04, 0.000000e+00, 0.000000e+00\n"
"5.179476e+04, 0.000000e+00, 0.000000e+00\n"
"7.196858e+04, 0.000000e+00, 0.000000e+00\n"
"1.000000e+05, 0.000000e+00, 0.000000e+00\n"
"1.389497e+05, 0.000000e+00, 0.000000e+00\n"
"1.930699e+05, 0.000000e+00, 0.000000e+00\n"
"2.682698e+05, 0.000000e+00, 0.000000e+00\n"
"3.727596e+05, 0.000000e+00, 0.000000e+00\n"
"5.179476e+05, 0.000000e+00, 0.000000e+00\n"
"7.196858e+05, 0.000000e+00, 0.000000e+00\n"
"1.000001e+06, 0.000000e+00, 0.000000e+00\n"
"1.389497e+06, 1.991211e+00, 0.000000e+00\n"
"1.930699e+06, 5.604766e+00, 0.000000e+00\n"
"2.682698e+06, 6.533646e+00, 0.000000e+00\n"
"3.727596e+06, 4.632523e+00, 0.000000e+00\n"
"5.179476e+06, 5.889149e-01, 0.000000e+00\n"
"7.196866e+06, 0.000000e+00, 0.000000e+00\n"
"1.000001e+07, 0.000000e+00, 0.000000e+00\n";
void printDataVect(const std::vector<eis::DataPoint> in) void printDataVect(const std::vector<eis::DataPoint> in)
{ {
...@@ -390,12 +363,9 @@ static bool nyquistJump() ...@@ -390,12 +363,9 @@ static bool nyquistJump()
static bool testEisNyquistDistance() static bool testEisNyquistDistance()
{ {
const std::filesystem::path filePath("./relaxis_rp-rp_0.csv"); const std::filesystem::path filePath("./relaxis_rp-rp_0.csv");
eis::EisSpectra spectra(filePath); try
if(spectra.data.empty())
{ {
eis::Log(eis::Log::INFO)<<__func__<<" Unable to load "<<filePath<<" skiping test"; eis::EisSpectra spectra(filePath);
return true;
}
std::vector<fvalue> omega(spectra.data.size()); std::vector<fvalue> omega(spectra.data.size());
for(size_t i = 0; i < spectra.data.size(); ++i) for(size_t i = 0; i < spectra.data.size(); ++i)
...@@ -420,16 +390,19 @@ static bool testEisNyquistDistance() ...@@ -420,16 +390,19 @@ static bool testEisNyquistDistance()
return true; return true;
} }
} }
catch(const eis::file_error& err)
{
eis::Log(eis::Log::INFO)<<__func__<<" Unable to load "<<filePath<<": "<<err.what()<<" skiping test";
return true;
}
}
static bool testLoadDeduplication() static bool testLoadDeduplication()
{ {
const std::filesystem::path filePath("./relaxis_rp-rp_0.csv"); const std::filesystem::path filePath("./relaxis_rp-rp_0.csv");
eis::EisSpectra spectra(filePath); try
if(spectra.data.empty())
{ {
eis::Log(eis::Log::INFO)<<__func__<<" Unable to load "<<filePath<<" skiping test"; eis::EisSpectra spectra(filePath);
return true;
}
if(eis::fvalueEq(spectra.data[spectra.data.size()-1].omega, spectra.data[spectra.data.size()-2].omega+2)) if(eis::fvalueEq(spectra.data[spectra.data.size()-1].omega, spectra.data[spectra.data.size()-2].omega+2))
{ {
...@@ -438,6 +411,12 @@ static bool testLoadDeduplication() ...@@ -438,6 +411,12 @@ static bool testLoadDeduplication()
} }
return true; return true;
} }
catch(const eis::file_error& err)
{
eis::Log(eis::Log::INFO)<<__func__<<" Unable to load "<<filePath<<": "<<err.what()<<" skiping test";
return true;
}
}
static bool testTranslators() static bool testTranslators()
{ {
...@@ -478,13 +457,10 @@ static bool testMadapParams() ...@@ -478,13 +457,10 @@ static bool testMadapParams()
} }
} }
static bool testLoader() static bool testLoader(const char* file, const size_t expectedLength, const size_t expectedLabels, const std::string expectedModel, bool same = false)
{ {
const size_t expectedLength = 50; std::stringstream ss(file);
const size_t expectedLabels = 5; eis::Log(eis::Log::INFO)<<__func__<<" STRLEN "<<strlen(file);
const std::string expectedModel("r-cr-cr");
std::stringstream ss(testEisSpectraFile);
eis::Log(eis::Log::INFO)<<__func__<<" STRLEN "<<strlen(testEisSpectraFile);
eis::EisSpectra spectra = eis::EisSpectra::loadFromStream(ss); eis::EisSpectra spectra = eis::EisSpectra::loadFromStream(ss);
if(spectra.data.size() != expectedLength) if(spectra.data.size() != expectedLength)
{ {
...@@ -501,13 +477,13 @@ static bool testLoader() ...@@ -501,13 +477,13 @@ static bool testLoader()
if(spectra.model != expectedModel) if(spectra.model != expectedModel)
{ {
eis::Log(eis::Log::ERROR)<<__func__<<" Spectra has model \""<<spectra.model<<"\" expected \""<<expectedModel<<'\"'; eis::Log(eis::Log::ERROR)<<__func__<<" Spectra has model \""<<spectra.model<<"\" expected \""<<expectedModel<<'\"';
//return false; return false;
} }
std::stringstream saveStream; std::stringstream saveStream;
spectra.saveToStream(saveStream); spectra.saveToStream(saveStream);
if(saveStream.str() != ss.str()) if(same && saveStream.str() != ss.str())
{ {
eis::Log(eis::Log::WARN)<<__func__<<" Saveing and loading dont have the same result. Saved:"; eis::Log(eis::Log::WARN)<<__func__<<" Saveing and loading dont have the same result. Saved:";
eis::Log(eis::Log::WARN)<<saveStream.str(); eis::Log(eis::Log::WARN)<<saveStream.str();
...@@ -557,8 +533,11 @@ int main(int argc, char** argv) ...@@ -557,8 +533,11 @@ int main(int argc, char** argv)
if(!testMadapParams()) if(!testMadapParams())
return 12; return 12;
if(!testLoader()) if(!testLoader(testEisSpectraFile10, 6, 5, "r-cr-cr"))
return 13; return 13;
if(!testLoader(testEisSpectraFile11, 6, 12, "Unkown", true))
return 14;
return 0; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment