Page MenuHomec4science

test_data_reader.hpp
No OneTemporary

File Metadata

Created
Sun, May 26, 05:44

test_data_reader.hpp

/*-------------------------------------------------------
- Module : chemy
- File : check_data_reader.h
- Author : Fabien Georget
Copyright (c) 2014, Fabien Georget <fabieng@princeton.edu>, Princeton University
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Princeton University nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This is a test file for databasereader.
---------------------------------------------------------*/
#include <cxxtest/TestSuite.h>
#include "database/reader.hpp"
#define DATABASE_PATH "../data/specmicp_database.js"
class TestSuite_DatabaseReader : public CxxTest::TestSuite
{
public:
void test_reader()
{
specmicp::database::DataReader reader(DATABASE_PATH);
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, specmicp::scalar_t> 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(DATABASE_PATH);
reader.parse();
std::shared_ptr<specmicp::database::DataContainer> thedata = reader.get_database();
TS_ASSERT_EQUALS(thedata->nb_component, 8);
}
};

Event Timeline