Page MenuHomec4science

test_data_reader.hpp
No OneTemporary

File Metadata

Created
Wed, Nov 6, 16:19

test_data_reader.hpp

/*-------------------------------------------------------
- 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