Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90985681
test_data_reader.hpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Nov 6, 16:19
Size
2 KB
Mime Type
text/x-c++
Expires
Fri, Nov 8, 16:19 (2 d)
Engine
blob
Format
Raw Data
Handle
22173220
Attached To
rSPECMICP SpecMiCP / ReactMiCP
test_data_reader.hpp
View Options
/*-------------------------------------------------------
- Module : chemy
- File : check_data_reader.h
- Author : Fabien Georget
Copyright (c) 2013, Fabien Georget, Princeton University
This is a test file for databasereader.
---------------------------------------------------------*/
#include <cxxtest/TestSuite.h>
#include "database/reader.hpp"
class
TestSuite_DatabaseReader
:
public
CxxTest
::
TestSuite
{
public
:
void
test_reader
()
{
specmicp
::
database
::
DataReader
reader
(
"data/specmicp_database.js"
);
reader
.
parse
();
specmicp
::
database
::
DataReader
reader2
(
"does_not_exist"
);
TS_ASSERT_THROWS
(
reader2
.
parse
(),
std
::
invalid_argument
);
}
void
test_parse_equation
()
{
std
::
map
<
std
::
string
,
float
>
compo
;
std
::
string
eq
=
"A, 2 B, -C, -3D, SDF, - 3 de, - X"
;
specmicp
::
database
::
parse_equation
(
eq
,
compo
);
TS_ASSERT_EQUALS
(
compo
[
"A"
],
1
);
TS_ASSERT_EQUALS
(
compo
[
"B"
],
2
);
TS_ASSERT_EQUALS
(
compo
[
"C"
],
-
1
);
TS_ASSERT_EQUALS
(
compo
[
"D"
],
-
3
);
TS_ASSERT_EQUALS
(
compo
[
"SDF"
],
1
);
TS_ASSERT_EQUALS
(
compo
[
"de"
],
-
3
);
TS_ASSERT_EQUALS
(
compo
[
"X"
],
-
1
);
}
void
test_parse_charge
()
{
TS_ASSERT_EQUALS
(
specmicp
::
database
::
charge_from_label
(
"neutral"
),
0
);
TS_ASSERT_EQUALS
(
specmicp
::
database
::
charge_from_label
(
"neutral[]"
),
0
);
TS_ASSERT_EQUALS
(
specmicp
::
database
::
charge_from_label
(
"charge[+]"
),
1
);
TS_ASSERT_EQUALS
(
specmicp
::
database
::
charge_from_label
(
"charge[-]"
),
-
1
);
TS_ASSERT_EQUALS
(
specmicp
::
database
::
charge_from_label
(
"charge[2]"
),
2
);
TS_ASSERT_EQUALS
(
specmicp
::
database
::
charge_from_label
(
"charge[2-]"
),
-
2
);
TS_ASSERT_EQUALS
(
specmicp
::
database
::
charge_from_label
(
"charge[2+]"
),
+
2
);
TS_ASSERT_EQUALS
(
specmicp
::
database
::
charge_from_label
(
"charge[-3]"
),
-
3
);
TS_ASSERT_EQUALS
(
specmicp
::
database
::
charge_from_label
(
"charge[+1]"
),
+
1
);
TS_ASSERT_THROWS
(
specmicp
::
database
::
charge_from_label
(
"charge[+3"
),
specmicp
::
database
::
db_invalid_syntax
);
TS_ASSERT_THROWS
(
specmicp
::
database
::
charge_from_label
(
"charge[ddd]"
),
specmicp
::
database
::
db_invalid_syntax
);
}
void
test_parse
()
{
specmicp
::
database
::
DataReader
reader
(
"data/specmicp_database.js"
);
reader
.
parse
();
std
::
shared_ptr
<
specmicp
::
database
::
DataContainer
>
thedata
=
reader
.
get_database
();
TS_ASSERT_EQUALS
(
thedata
->
nb_component
,
8
);
}
};
Event Timeline
Log In to Comment