From: Carsten Niehaus Date: Tue, 29 May 2007 07:35:43 +0000 (+0000) Subject: * Reorganize the tests a little X-Git-Tag: v3.91.0~34 X-Git-Url: https://git.rmz.fi/?a=commitdiff_plain;h=c774b5476555cf0a2dfa0d9e0bee717a65b3d282;p=libqmvoc.git * Reorganize the tests a little * Reactivate the isotopestuff. Need to check for mem-leaks. But the * parser works again svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=669387 --- diff --git a/libscience/isotope.cpp b/libscience/isotope.cpp index 9a8140d..3e6c4fd 100644 --- a/libscience/isotope.cpp +++ b/libscience/isotope.cpp @@ -66,101 +66,90 @@ void Isotope::addData( ChemicalDataObject o ) double Isotope::mass() const { - //return m_mass ? m_mass.value().toDouble() : -1.0; - return -1.0; + return m_mass.value().toDouble(); } QString Isotope::errorMargin() const { - //return m_mass ? m_mass.errorValue().toString() : QString(); - return QString(); + return m_mass.errorValue().toString(); } int Isotope::parentElementNumber() const { -// return m_identifier ? m_identifier.value().toInt() : -1; - return -1; + return m_identifier.value().toInt(); } QString Isotope::spin() const { - //return m_spin ? m_spin.value().toString() : QString(); - return QString(); + return m_spin.value().toString(); } QString Isotope::magmoment() const { - //return m_magmoment ? m_magmoment.value().toString() : QString(); - return QString(); + return m_magmoment.value().toString(); } QString Isotope::abundance() const { - //return m_abundance ? m_abundance.value().toString() : QString(); + return m_abundance.value().toString(); return QString(); } double Isotope::halflife() const { - //return m_halflife ? m_halflife.value().toDouble() : -1.0; - return -1.0; + return m_halflife.value().toDouble(); } double Isotope::ecdecay() const { - //return m_ecdecay ? m_ecdecay.value().toDouble() : -1.0; - return -1.0; + return m_ecdecay.value().toDouble(); } double Isotope::eclikeliness() const { - //return m_eclikeliness ? m_eclikeliness.value().toDouble() : -1.0; - return -1.0; + return m_eclikeliness.value().toDouble(); } double Isotope::betaplusdecay() const { - //return m_betaplusdecay ? m_betaplusdecay.value().toDouble() : -1.0; - return -1.0; + return m_betaplusdecay.value().toDouble(); } + double Isotope::betapluslikeliness() const { - //return m_betapluslikeliness ? m_betapluslikeliness.value().toDouble() : -1.0; - return -1.0; + return m_betapluslikeliness.value().toDouble(); } + double Isotope::betaminusdecay() const { - //return m_betaminusdecay ? m_betaminusdecay.value().toDouble() : -1.0; - return -1.0; + return m_betaminusdecay.value().toDouble(); } + double Isotope::betaminuslikeliness() const { - //return m_betaminuslikeliness ? m_betaminuslikeliness.value().toDouble() : -1.0; - return -1.0; + return m_betaminuslikeliness.value().toDouble(); } + double Isotope::alphadecay() const { - //return m_alphadecay ? m_alphadecay.value().toDouble() : -1.0; - return -1.0; + return m_alphadecay.value().toDouble(); } + double Isotope::alphalikeliness() const { - //return m_alphalikeliness ? m_alphalikeliness.value().toDouble() : -1.0; - return -1.0; + return m_alphalikeliness.value().toDouble(); } + QString Isotope::parentElementSymbol() const { - //return m_parentElementSymbol ? m_parentElementSymbol.value().toString() : QString(); - return QString(); + return m_parentElementSymbol.value().toString(); } void Isotope::setNucleons( int number ) { - Q_UNUSED(number); - //m_numberOfNucleons = number; + m_numberOfNucleons = number; } int Isotope::nucleons() const { - //return m_numberOfNucleons; - return 0; + return m_numberOfNucleons; } Isotope::Nucleons Isotope::nucleonsAfterDecay( Decay kind ) diff --git a/libscience/isotopeparser.cpp b/libscience/isotopeparser.cpp index 38bf616..0c5e35c 100644 --- a/libscience/isotopeparser.cpp +++ b/libscience/isotopeparser.cpp @@ -88,6 +88,7 @@ IsotopeParser::~IsotopeParser() bool IsotopeParser::startElement(const QString&, const QString &localName, const QString&, const QXmlAttributes &attrs) { +//X kDebug() << "IsotopeParser::startElement()" << endl; if (localName == "isotopeList") { d->inElement = true; @@ -98,18 +99,21 @@ bool IsotopeParser::startElement(const QString&, const QString &localName, const if ( attrs.localName( i ) == "id" ) d->currentElementSymbol = attrs.value( i ); - //X kDebug() << "Symbol of the current Element: " << attrs.value( i ) << endl; +//X kDebug() << "Symbol of the current Element: " << attrs.value( i ) << endl; } } else if ( d->inElement && localName == "isotope") { - //X kDebug() << "setting inIsotope true!" << endl; +//X kDebug() << "setting inIsotope true!" << endl; d->currentIsotope = new Isotope(); d->currentIsotope->addData( ChemicalDataObject( QVariant( d->currentElementSymbol ), ChemicalDataObject::symbol ) ); d->inIsotope = true; for (int i = 0; i < attrs.length(); ++i) { if ( attrs.localName( i ) == "number" ) + { d->currentIsotope->setNucleons( attrs.value( i ).toInt() ); +//X kDebug() << attrs.value( i ).toInt() << endl; + } } } else if (d->inIsotope && localName == "scalar") { @@ -168,6 +172,7 @@ bool IsotopeParser::startElement(const QString&, const QString &localName, const bool IsotopeParser::endElement( const QString&, const QString& localName, const QString& ) { +//X kDebug() << "IsotopeParser::endElement()" << endl; if ( localName == "isotope" ) { d->isotopes.append(d->currentIsotope); @@ -177,8 +182,8 @@ bool IsotopeParser::endElement( const QString&, const QString& localName, const } else if ( localName == "isotopeList" ) {//a new list of isotopes start... -//X kDebug() << "setting d->inElement FALSE" << endl; - d->inElement = false; +//X kDebug() << "setting d->inElement FALSE" << endl; + d->inElement = false; } return true; @@ -186,6 +191,7 @@ bool IsotopeParser::endElement( const QString&, const QString& localName, const bool IsotopeParser::characters(const QString &ch) { +//X kDebug() << "IsotopeParser::characters() with ch: " << ch << endl; d->currentDataObject = ChemicalDataObject(); ChemicalDataObject::BlueObelisk type; QVariant value; diff --git a/libscience/tests/CMakeLists.txt b/libscience/tests/CMakeLists.txt index b4de2bb..ac83226 100644 --- a/libscience/tests/CMakeLists.txt +++ b/libscience/tests/CMakeLists.txt @@ -7,11 +7,19 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) ########### next target ############### -set(parsertest_SRCS xmlreadingtest.cpp) +set(elementparsertest_SRCS xmlreadingtest.cpp) -kde4_add_executable(parsertest ${parsertest_SRCS}) +kde4_add_executable(elementparsertest ${elementparsertest_SRCS}) -target_link_libraries(parsertest science) +target_link_libraries(elementparsertest science) + +########### next target ############### + +set(isotopeparsertest_SRCS isotopereadingtest.cpp) + +kde4_add_executable(isotopeparsertest ${isotopeparsertest_SRCS}) + +target_link_libraries(isotopeparsertest science) endif(KDE4_BUILD_TESTS) diff --git a/libscience/tests/isotopereadingtest.cpp b/libscience/tests/isotopereadingtest.cpp new file mode 100644 index 0000000..24f8034 --- /dev/null +++ b/libscience/tests/isotopereadingtest.cpp @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (C) 2005, 2006 by Carsten Niehaus * + * * + * This program 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. * + * * + * This program 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., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "isotopeparser.h" +#include "isotope.h" +#include +#include + +int main(int argc, char *argv[]) +{ + if (argc < 2 || argc > 2) { + std::cout << "Usage: isotopes \n"; + return 1; + } + + IsotopeParser * parser = new IsotopeParser(); + QFile xmlFile(argv[1]); + + QXmlInputSource source(&xmlFile); + QXmlSimpleReader reader; + + reader.setContentHandler(parser); + reader.parse(source); + + QList v = parser->getIsotopes(); + + kDebug() << "Found " << v.count() << " isotopes." << endl;; + + kDebug() << "As a test I am now issuing all isotopes with 50 nuclueons: " << endl; + + foreach( Isotope* i, v ){ + if ( i ) + { + if (i->nucleons() == 50 ) + kDebug() << " Isotope of " << i->parentElementSymbol() << " with a mass of " << i->mass() << endl; + } + } + + delete parser; + qDeleteAll(v); + + return 0; +}