Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Eisgenerator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Klemm, Carl Philipp
Eisgenerator
Commits
e0f3dbb3
Commit
e0f3dbb3
authored
10 months ago
by
Carl Philipp Klemm
Browse files
Options
Downloads
Patches
Plain Diff
test: fix tests for new spctra file version
parent
30866524
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
strops.cpp
+3
-1
3 additions, 1 deletion
strops.cpp
test.cpp
+66
-87
66 additions, 87 deletions
test.cpp
with
69 additions
and
88 deletions
strops.cpp
+
3
−
1
View file @
e0f3dbb3
...
...
@@ -162,7 +162,9 @@ size_t deepestBraket(const std::string& str, std::string bracketChars, size_t* l
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
)
...
...
This diff is collapsed.
Click to expand it.
test.cpp
+
66
−
87
View file @
e0f3dbb3
...
...
@@ -34,7 +34,7 @@
#include
"strops.h"
#include
"translators.h"
const
char
testEisSpectraFile
[]
=
const
char
testEisSpectraFile
10
[]
=
"EISF, 1.0.0
\n
"
"
\"
r-cr-cr
\"
, 0
\n
"
"labels
\n
"
...
...
@@ -45,51 +45,24 @@ const char testEisSpectraFile[] =
"1.930698e+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
"
"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
"
"1.389496e+01, 0.000000e+00, 0.000000e+00
\n
"
"1.930698e+01, 0.000000e+00, 0.000000e+00
\n
"
"2.682696e+01, 0.000000e+00, 0.000000e+00
\n
"
"3.727594e+01, 0.000000e+00, 0.000000e+00
\n
"
"5.179476e+01, 0.000000e+00, 0.000000e+00
\n
"
"7.196858e+01, 0.000000e+00, 0.000000e+00
\n
"
"1.000000e+02, 0.000000e+00, 0.000000e+00
\n
"
"1.389496e+02, 0.000000e+00, 0.000000e+00
\n
"
"1.930698e+02, 0.000000e+00, 0.000000e+00
\n
"
"2.682696e+02, 0.000000e+00, 0.000000e+00
\n
"
"3.727596e+02, 0.000000e+00, 0.000000e+00
\n
"
"5.179476e+02, 0.000000e+00, 0.000000e+00
\n
"
"7.196858e+02, 0.000000e+00, 0.000000e+00
\n
"
"1.000001e+03, 0.000000e+00, 0.000000e+00
\n
"
"1.389496e+03, 0.000000e+00, 0.000000e+00
\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
"
;
"5.179475e+00, 0.000000e+00, 0.000000e+00
\n
"
;
const
char
testEisSpectraFile11
[]
=
"EISF, 1.1.0
\n
"
"
\"
Unkown
\"\n
"
"File origin
\n
"
"CoinCellHell mesurement file
\n
"
"labelsNames
\n
"
"
\"
step
\"
,
\"
substep
\"
,
\"
cellid
\"
,
\"
temparature
\"
,
\"
ocv
\"
,
\"
charge_cycles
\"
,
\"
thermal_cycles
\"
,
\"
last_avg_cap
\"
,
\"
last_avg_step
\"
,
\"
last_cap
\"
,
\"
last_cap_step
\"
,
\"
soc
\"\n
"
"labels
\n
"
"2, 4, 0, 36.1, 3.55081, 1, 8, 0.0448139, 11, 0.0428723, 120, -1
\n
"
"omega, real, im
\n
"
"6.293263e-01, 1.214581e+00, -1.917704e-01
\n
"
"8.324402e-01, 1.193806e+00, -1.599901e-01
\n
"
"1.106767e+00, 1.178542e+00, -1.361918e-01
\n
"
"1.465296e+00, 1.166301e+00, -1.212671e-01
\n
"
"1.947914e+00, 1.156239e+00, -1.091308e-01
\n
"
"2.563042e+00, 1.147515e+00, -1.042249e-01
\n
"
;
void
printDataVect
(
const
std
::
vector
<
eis
::
DataPoint
>
in
)
{
...
...
@@ -390,33 +363,36 @@ static bool nyquistJump()
static
bool
testEisNyquistDistance
()
{
const
std
::
filesystem
::
path
filePath
(
"./relaxis_rp-rp_0.csv"
);
eis
::
EisSpectra
spectra
(
filePath
);
if
(
spectra
.
data
.
empty
())
try
{
eis
::
Log
(
eis
::
Log
::
INFO
)
<<
__func__
<<
" Unable to load "
<<
filePath
<<
" skiping test"
;
return
true
;
eis
::
EisSpectra
spectra
(
filePath
);
std
::
vector
<
fvalue
>
omega
(
spectra
.
data
.
size
());
for
(
size_t
i
=
0
;
i
<
spectra
.
data
.
size
();
++
i
)
omega
[
i
]
=
spectra
.
data
[
i
].
omega
;
eis
::
Log
(
eis
::
Log
::
INFO
)
<<
__func__
<<
" using model string: "
<<
spectra
.
model
;
eis
::
Model
model
(
spectra
.
model
);
std
::
vector
<
eis
::
DataPoint
>
genData
=
model
.
executeSweep
(
omega
);
fvalue
dist
=
eisNyquistDistance
(
spectra
.
data
,
genData
);
if
(
std
::
isnan
(
dist
))
{
eis
::
Log
(
eis
::
Log
::
ERROR
)
<<
__func__
<<
" spectra.data:"
;
printDataVect
(
spectra
.
data
);
eis
::
Log
(
eis
::
Log
::
ERROR
)
<<
__func__
<<
" genData:"
;
printDataVect
(
genData
);
eis
::
Log
(
eis
::
Log
::
ERROR
)
<<
__func__
<<
" distanece is NAN!"
;
return
false
;
}
else
{
return
true
;
}
}
std
::
vector
<
fvalue
>
omega
(
spectra
.
data
.
size
());
for
(
size_t
i
=
0
;
i
<
spectra
.
data
.
size
();
++
i
)
omega
[
i
]
=
spectra
.
data
[
i
].
omega
;
eis
::
Log
(
eis
::
Log
::
INFO
)
<<
__func__
<<
" using model string: "
<<
spectra
.
model
;
eis
::
Model
model
(
spectra
.
model
);
std
::
vector
<
eis
::
DataPoint
>
genData
=
model
.
executeSweep
(
omega
);
fvalue
dist
=
eisNyquistDistance
(
spectra
.
data
,
genData
);
if
(
std
::
isnan
(
dist
))
{
eis
::
Log
(
eis
::
Log
::
ERROR
)
<<
__func__
<<
" spectra.data:"
;
printDataVect
(
spectra
.
data
);
eis
::
Log
(
eis
::
Log
::
ERROR
)
<<
__func__
<<
" genData:"
;
printDataVect
(
genData
);
eis
::
Log
(
eis
::
Log
::
ERROR
)
<<
__func__
<<
" distanece is NAN!"
;
return
false
;
}
else
catch
(
const
eis
::
file_error
&
err
)
{
eis
::
Log
(
eis
::
Log
::
INFO
)
<<
__func__
<<
" Unable to load "
<<
filePath
<<
": "
<<
err
.
what
()
<<
" skiping test"
;
return
true
;
}
}
...
...
@@ -424,19 +400,22 @@ static bool testEisNyquistDistance()
static
bool
testLoadDeduplication
()
{
const
std
::
filesystem
::
path
filePath
(
"./relaxis_rp-rp_0.csv"
);
eis
::
EisSpectra
spectra
(
filePath
);
if
(
spectra
.
data
.
empty
())
try
{
eis
::
Log
(
eis
::
Log
::
INFO
)
<<
__func__
<<
" Unable to load "
<<
filePath
<<
" skiping test"
;
eis
::
EisSpectra
spectra
(
filePath
);
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
;
}
if
(
eis
::
fvalueEq
(
spectra
.
data
[
spectra
.
data
.
size
()
-
1
].
omega
,
spectra
.
data
[
spectra
.
data
.
size
()
-
2
].
omega
+
2
))
catch
(
const
eis
::
file_error
&
err
)
{
eis
::
Log
(
eis
::
Log
::
ERROR
)
<<
__func__
<<
"
deduplication failed
"
;
return
fals
e
;
eis
::
Log
(
eis
::
Log
::
INFO
)
<<
__func__
<<
"
Unable to load "
<<
filePath
<<
": "
<<
err
.
what
()
<<
" skiping test
"
;
return
tru
e
;
}
return
true
;
}
static
bool
testTranslators
()
...
...
@@ -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
;
const
size_t
expectedLabels
=
5
;
const
std
::
string
expectedModel
(
"r-cr-cr"
);
std
::
stringstream
ss
(
testEisSpectraFile
);
eis
::
Log
(
eis
::
Log
::
INFO
)
<<
__func__
<<
" STRLEN "
<<
strlen
(
testEisSpectraFile
);
std
::
stringstream
ss
(
file
);
eis
::
Log
(
eis
::
Log
::
INFO
)
<<
__func__
<<
" STRLEN "
<<
strlen
(
file
);
eis
::
EisSpectra
spectra
=
eis
::
EisSpectra
::
loadFromStream
(
ss
);
if
(
spectra
.
data
.
size
()
!=
expectedLength
)
{
...
...
@@ -501,13 +477,13 @@ static bool testLoader()
if
(
spectra
.
model
!=
expectedModel
)
{
eis
::
Log
(
eis
::
Log
::
ERROR
)
<<
__func__
<<
" Spectra has model
\"
"
<<
spectra
.
model
<<
"
\"
expected
\"
"
<<
expectedModel
<<
'\"'
;
//
return false;
return
false
;
}
std
::
stringstream
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
)
<<
saveStream
.
str
();
...
...
@@ -557,8 +533,11 @@ int main(int argc, char** argv)
if
(
!
testMadapParams
())
return
12
;
if
(
!
testLoader
())
if
(
!
testLoader
(
testEisSpectraFile10
,
6
,
5
,
"r-cr-cr"
))
return
13
;
if
(
!
testLoader
(
testEisSpectraFile11
,
6
,
12
,
"Unkown"
,
true
))
return
14
;
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment