Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
ed480487
Commit
ed480487
authored
Mar 23, 2021
by
daniel.bub
Browse files
[REFAC
#83
] add unit test for stringToDouble() & stringToInt()
parent
ea2b3830
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
0 deletions
+65
-0
src/modules/filterProtonData/test/WCsvConverter_test.h
src/modules/filterProtonData/test/WCsvConverter_test.h
+65
-0
No files found.
src/modules/filterProtonData/test/WCsvConverter_test.h
View file @
ed480487
...
...
@@ -25,6 +25,8 @@
#ifndef WCSVCONVERTER_TEST_H
#define WCSVCONVERTER_TEST_H
#include <map>
#include <utility>
#include <vector>
#include <string>
#include <cxxtest/TestSuite.h>
...
...
@@ -111,6 +113,69 @@ public:
TS_ASSERT_IS_NAN
(
tmpCsvReader
.
getClusterSize
(
-
0.0001
f
)
);
TS_ASSERT_IS_NAN
(
tmpCsvReader
.
getClusterSize
(
-
1.0
f
)
);
}
/**
* Tests the method stringToDouble()
*/
void
testStringToDouble
()
{
std
::
map
<
std
::
string
,
double
>
testDoubleMap
;
testDoubleMap
.
insert
(
std
::
pair
<
std
::
string
,
double
>
(
"1000.1"
,
1000.1
f
)
);
testDoubleMap
.
insert
(
std
::
pair
<
std
::
string
,
double
>
(
"1."
,
1.0
f
)
);
testDoubleMap
.
insert
(
std
::
pair
<
std
::
string
,
double
>
(
".1"
,
0.1
f
)
);
testDoubleMap
.
insert
(
std
::
pair
<
std
::
string
,
double
>
(
"2.1"
,
2.1
f
)
);
testDoubleMap
.
insert
(
std
::
pair
<
std
::
string
,
double
>
(
"+1"
,
1.0
f
)
);
testDoubleMap
.
insert
(
std
::
pair
<
std
::
string
,
double
>
(
"-1"
,
-
1.0
f
)
);
testDoubleMap
.
insert
(
std
::
pair
<
std
::
string
,
double
>
(
"+.1"
,
0.1
f
)
);
testDoubleMap
.
insert
(
std
::
pair
<
std
::
string
,
double
>
(
"-.1"
,
-
0.1
f
)
);
testDoubleMap
.
insert
(
std
::
pair
<
std
::
string
,
double
>
(
"+1e-1"
,
0.1
f
)
);
testDoubleMap
.
insert
(
std
::
pair
<
std
::
string
,
double
>
(
"0.001e-6"
,
0.000000001
f
)
);
testDoubleMap
.
insert
(
std
::
pair
<
std
::
string
,
double
>
(
"0.111111111111111"
,
0.111111111111111
f
)
);
WCsvConverter
tmpCsvReader
(
m_protonData
,
m_propertyStatus
,
m_colorBar
);
for
(
std
::
pair
<
std
::
string
,
double
>
stringDoublePair
:
testDoubleMap
)
{
TS_ASSERT_EQUALS
(
tmpCsvReader
.
stringToDouble
(
stringDoublePair
.
first
),
stringDoublePair
.
second
);
}
TS_ASSERT_THROWS
(
tmpCsvReader
.
stringToDouble
(
"1.g"
),
WException
&
e
);
TS_ASSERT_THROWS
(
tmpCsvReader
.
stringToDouble
(
""
),
WException
&
e
);
TS_ASSERT_THROWS
(
tmpCsvReader
.
stringToDouble
(
"Test"
),
WException
&
e
);
TS_ASSERT_THROWS
(
tmpCsvReader
.
stringToDouble
(
"1.1.2"
),
WException
&
e
);
}
/**
* Tests the method stringToInt()
*/
void
testStringToInt
()
{
std
::
map
<
std
::
string
,
int
>
testIntMap
;
testIntMap
.
insert
(
std
::
pair
<
std
::
string
,
int
>
(
"1"
,
1
)
);
testIntMap
.
insert
(
std
::
pair
<
std
::
string
,
int
>
(
"0"
,
0
)
);
testIntMap
.
insert
(
std
::
pair
<
std
::
string
,
int
>
(
"10"
,
10
)
);
testIntMap
.
insert
(
std
::
pair
<
std
::
string
,
int
>
(
"+1"
,
1
)
);
testIntMap
.
insert
(
std
::
pair
<
std
::
string
,
int
>
(
"-1"
,
-
1
)
);
testIntMap
.
insert
(
std
::
pair
<
std
::
string
,
int
>
(
"1e-1"
,
0
)
);
testIntMap
.
insert
(
std
::
pair
<
std
::
string
,
int
>
(
"1e1"
,
10
)
);
testIntMap
.
insert
(
std
::
pair
<
std
::
string
,
int
>
(
"+1e-1"
,
0
)
);
testIntMap
.
insert
(
std
::
pair
<
std
::
string
,
int
>
(
"0.001e-6"
,
0
)
);
testIntMap
.
insert
(
std
::
pair
<
std
::
string
,
int
>
(
"0.111111111111111"
,
0
)
);
WCsvConverter
tmpCsvReader
(
m_protonData
,
m_propertyStatus
,
m_colorBar
);
for
(
std
::
pair
<
std
::
string
,
int
>
stringIntPair
:
testIntMap
)
{
TS_ASSERT_EQUALS
(
tmpCsvReader
.
stringToInt
(
stringIntPair
.
first
),
stringIntPair
.
second
);
}
TS_ASSERT_THROWS
(
tmpCsvReader
.
stringToInt
(
"1.g"
),
WException
&
e
);
TS_ASSERT_THROWS
(
tmpCsvReader
.
stringToInt
(
""
),
WException
&
e
);
TS_ASSERT_THROWS
(
tmpCsvReader
.
stringToInt
(
"Test"
),
WException
&
e
);
TS_ASSERT_THROWS
(
tmpCsvReader
.
stringToInt
(
"1.1.2"
),
WException
&
e
);
}
};
#endif // WCSVCONVERTER_TEST_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment