[Echempp-devel] Experiment/Data/test Makefile.am, 1.5, 1.6 dataTest.cpp, 1.8, 1.9
Status: Beta
Brought to you by:
berndspeiser
|
From: beeblbrox <bee...@us...> - 2007-12-19 13:26:13
|
Update of /cvsroot/echempp/Experiment/Data/test In directory sc8-pr-cvs17.sourceforge.net:/tmp/cvs-serv31758/Experiment/Data/test Modified Files: Makefile.am dataTest.cpp Log Message: Update for Data test functions. Index: dataTest.cpp =================================================================== RCS file: /cvsroot/echempp/Experiment/Data/test/dataTest.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** dataTest.cpp 17 Feb 2007 18:03:16 -0000 1.8 --- dataTest.cpp 19 Dec 2007 13:26:08 -0000 1.9 *************** *** 1,211 **** ! /*! \file dataTest.cpp ! \brief a test file for Data classes ! ! dataTest.cpp is part of Data in Experiment ! */ ! ! /* Copyright (C) 2005 - 2006, Bernd Speiser */ ! /* This file is part of EChem++. ! ! EChem++ is free software; you can redistribute it and/or ! modify it under the terms of the GNU General Public License ! as published by the Free Software Foundation; either version 2 ! of the License, or (at your option) any later version. ! ! EChem++ is distributed in the hope that it will be useful, ! but WITHOUT ANY WARRANTY; without even the implied warranty of ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License ! along with this program; if not, write to the Free Software ! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA ! 02111-1307, USA. ! */ ! ! //#include "Data/data.hpp" ! //#include "Data/electrochemicalData.hpp" ! //#include "xmlReader.h" ! //#include <iostream> ! //using namespace BSUtilities; ! //using namespace data; ! int main(int argc, const char* argv[]) { ! // std::string filename; ! // ! // if (argc > 1) ! // { ! // if (!strcmp (argv[1], "--version")) ! // { ! // std::cout << "Data Test program, " ! // << DataStorage::version () << std::endl; ! // exit (0); ! // } ! // ! // else if (!strcmp (argv[1], "-f")) ! // filename = argv[2]; ! // ! // else ! // { ! // std::cout << " usage: DataTest [--version|-f filename] " ! // << std::endl << " --version: print the Data " ! // "version number" ! // << std::endl << " -f: data file name" ! // << std::endl; ! // exit (1); ! // } ! // } ! // ! // std::cout << "Data Test program" << std::endl; ! // ! // std::cout << "=========================================" << std::endl; ! // ! // std::cout << " testing use of an object of type RealCVData" ! // << std::endl; ! // std::cout << " - declare an object of type RealCVData" ! // << std::endl; ! // data::CV::Real cv; ! // std::cout << " - set title and date stamp" << std::endl; ! // cv.setTitle ("cv test data set"); ! // cv.setTimeStamp ("creation time: xxx"); ! // const int number_of_points = 5; ! // std::cout << " - add " << number_of_points << " data points" ! // << std::endl; ! // quantity::Time t_start (0.); ! // quantity::Time delta_t (0.01); ! // quantity::ElectricPotential E_start (0.); ! // quantity::ElectricPotential delta_E (0.02); ! // quantity::ElectricCurrent I_start (0.); ! // quantity::ElectricCurrent delta_I (-0.001); ! // ! // data::CV::Real::MeasurementDataPoint p; ! // ! // for (int i = 0; i < number_of_points; i++) ! // { ! // Loki::Field<0>(p) = t_start + i * delta_t; ! // Loki::Field<1>(p) = E_start + i * delta_E; ! // Loki::Field<2>(p) = I_start + i * delta_I; ! // ! // cv.push_back (p); ! // } ! // ! // std::cout << " - data table contains " << cv.size () ! // << " data points" << std::endl; ! // std::cout << " testing data write routines" << std::endl; ! // std::cout << " - generate a DataPoint" << std::endl; ! // data::CV::Real::MeasurementDataPoint cvPoint ! // = data::CV::Real::measurementDataPoint ! // (quantity::Time (1.), quantity::ElectricPotential (0.5), ! // quantity::ElectricCurrent (-.7)); ! // ! // std::cout << " - save it" << std::endl; ! // cv.push_back (cvPoint); ! // std::cout << " - data table contains " << cv.size () ! // << " data points" << std::endl; ! // ! // std::cout << " testing save function for real CV data" << std::endl; ! // std::string save_CVdata_filename = "save_CVdata.xml"; ! // xmlw::save (save_CVdata_filename, cv); ! // std::cout << std::endl; ! // std::cout << " testing load function for real CV data" << std::endl; ! // data::CV::Real cv_loaded; ! // try { ! // BSUtilities::xmlr::xmlLoad (save_CVdata_filename, cv_loaded); ! // std::cout << " file `" << save_CVdata_filename ! // << "' succesfully loaded" << std::endl; ! // } ! // catch (DataError error) ! // {std::cout << error.message () << std::endl;} ! // catch (BSUtilities::xmlr::XmlReadError readerror) ! // {std::cout << readerror.message () << std::endl;} ! // ! // const unsigned int index = 2; ! // std::cout << " testing data access routines" << std::endl; ! // std::cout << " - retrieve a data value" << std::endl; ! // std::cout << " response measurement value at index " << index ! // << ":" << cv.getResponseValue (index) << std::endl; ! // ! // std::cout << " - retrieve data values of last data point" ! // << std::endl; ! // unsigned int cvSize = cv.size (); ! // ! // std::cout << " time value: " ! // << cv.getIndependentValue (cvSize - 1) ! // << std::endl ! // << " potential value: " << cv.getDependentValue (cvSize - 1) ! // << std::endl ! // << " current value: " << cv.getResponseValue (cvSize - 1) ! // << std::endl; ! // ! // std::cout << " testing use of an object of type SimulatedCVData" ! // << std::endl; ! // std::cout << " - declare an object of type SimulatedCVData" ! // << std::endl; ! // data::CV::Simulated simCv; ! // std::cout << " - set title and date stamp" << std::endl; ! // simCv.setTitle ("cv test data set"); ! // simCv.setTimeStamp ("creation time: xxx"); ! ! // BAS100data data(filename); ! // ! // ! //// declare CVExcitationFunction object ! //// CVExcitationFunction CV; ! // ! //// // length of each segment ! //// Time tmax(4.0,quantity::time::Second ()); ! // ! //// // start and switching potentials ! //// ElectricPotential Estart(0.0,electricPotential::Volt ()); ! //// ElectricPotential Eend(2.0,electricPotential::Volt ()); ! // ! //// // define 5 segments ! //// LinearEtSegment Seg11 (Estart,Eend,tmax); ! //// LinearEtSegment Seg12 (Eend,Estart,tmax); ! // ! //// // add 5 segments of 4 s to CV ! // ! //// CV.add(Seg11); ! //// CV.add(Seg12); ! // ! //// DiffusionCoefficient Dref( 5.0e-10, diffusionCoefficient::SquareMetrePerSecond() ); ! //// Concentration cRef( 5.0e-5, concentration::MolePerLitre() ); ! //// Length Lref( 1.0, length::CentiMetre() ); ! //// Area area( 0.002, area::SquareMetre() ); ! // ! //// std::vector<double> times; ! //// std::vector<double> currents; ! // ! //// double t = 0.0; ! //// for(;t<=1.0;t+=0.1) ! //// { ! //// times.push_back(t); ! //// currents.push_back( std::pow(t,0.5) ); ! //// } ! // ! //// SimulatedPCdata data( currents, times, 0, Lref, Dref, cRef, area, CV ); ! // ! //// std::vector<double> potentials; ! //// data.getPotentialValues(potentials,"mV"); ! //// data.getTimeValues(times,"s"); ! //// data.getCurrentValues(currents,"uA"); ! // ! //// uint_t i = 0; ! //// for(;i<potentials.size();++i) ! //// { ! //// std::cout << "time: " << times[i] << ! //// ", potentials: " << potentials[i] << ! //// ", currents: " << currents[i] << std::endl; ! //// } ! // std::cout << "=========================================" << std::endl; ! // std::cout << "end of test program for Data classes" << std::endl; ! // exit (0); } --- 1,73 ---- ! #include <iostream> ! #include <fstream> ! // Boost includes ! #include <boost/test/unit_test.hpp> ! using namespace boost::unit_test; ! #include <boost/archive/tmpdir.hpp> ! #include <boost/archive/text_oarchive.hpp> ! #include <boost/archive/text_iarchive.hpp> ! #include <boost/archive/xml_iarchive.hpp> ! #include <boost/archive/xml_oarchive.hpp> ! // Local includes ! #include "../Data.hpp" ! typedef DataPoint<double, double, double> DP; ! typedef MeasurementData<double, double, double> MD; ! // Note: Compile and link with: ! // g++ -o SerializationTest SerializationTest.cpp -lboost_unit_test_framework ! // Test creation of data points ! void test_data_point() { ! DP dp1(0.3, 0.1, 0.4); ! DP dp2(0.1, 0.0, 0.1); ! } + // Create some measurement data + MD create_measurement_data() + { + DP dp1(0.3, 0.1, 0.4); + DP dp2(0.1, 0.0, 0.1); + DP dp3(0.3, 0.2, 0.1); + MD m; + m.add(dp1); + m.add(dp2); + m.add(dp3); + return m; + } ! // Test creation of measurement data ! void test_measurement_data() ! { ! MD m = create_measurement_data(); ! BOOST_CHECK( m.size() == 3 ); ! } ! // Test serialization of measurement data ! void test_serialization() ! { ! std::string dirname = "/tmp/"; ! std::string filename = dirname + "md.xml"; ! const MD m1 = create_measurement_data(); ! MD m2; ! std::ofstream ofs_xml(filename.c_str()); ! boost::archive::xml_oarchive oa_xml(ofs_xml); ! oa_xml << BOOST_SERIALIZATION_NVP(m1); ! ofs_xml.close(); ! std::ifstream ifs_xml(filename.c_str()); ! boost::archive::xml_iarchive ia_xml(ifs_xml); ! ia_xml >> BOOST_SERIALIZATION_NVP(m2); ! ifs_xml.close(); ! // BOOST_CHECK( m1 == m2 ); ! } + test_suite* + init_unit_test_suite( int argc, char * argv[] ) { + test_suite* test= BOOST_TEST_SUITE( "Data unit test" ); + test->add(BOOST_TEST_CASE( &test_data_point ) ); + test->add(BOOST_TEST_CASE( &test_measurement_data ) ); + test->add( BOOST_TEST_CASE( &test_serialization ) ); + return test; } Index: Makefile.am =================================================================== RCS file: /cvsroot/echempp/Experiment/Data/test/Makefile.am,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makefile.am 8 Apr 2006 11:59:49 -0000 1.5 --- Makefile.am 19 Dec 2007 13:26:08 -0000 1.6 *************** *** 1,3 **** ! check_PROGRAMS = dataTest dataTest_SOURCES = dataTest.cpp --- 1,8 ---- ! check_PROGRAMS = dataTest DataTest ! ! DataTest_SOURCES = DataTest.cpp ! ! DataTest_LDADD = -lboost_serialization \ ! -lboost_unit_test_framework dataTest_SOURCES = dataTest.cpp *************** *** 18,19 **** --- 23,26 ---- dataTest_CXXFLAGS = -Wall -Werror -pedantic-errors -DTIXML_USE_STL=YES + DataTest_CXXFLAGS = -Wall -Werror -pedantic-errors + |