]> Git trees. - libqmvoc.git/commitdiff
* Reorganize the tests a little
authorCarsten Niehaus <cniehaus@gmx.de>
Tue, 29 May 2007 07:35:43 +0000 (07:35 +0000)
committerCarsten Niehaus <cniehaus@gmx.de>
Tue, 29 May 2007 07:35:43 +0000 (07:35 +0000)
* Reactivate the isotopestuff. Need to check for mem-leaks. But the
* parser works again

svn path=/trunk/KDE/kdeedu/libkdeedu/; revision=669387

libscience/isotope.cpp
libscience/isotopeparser.cpp
libscience/tests/CMakeLists.txt
libscience/tests/isotopereadingtest.cpp [new file with mode: 0644]

index 9a8140d1916b90f331b80cbb786e9dd67593203b..3e6c4fdb7cf840b62ecb662869ca10a27e0c1f22 100644 (file)
@@ -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 )
index 38bf616490c674a00d077fd5414020c64c334c21..0c5e35cf0727ae1145e7c3d5c6673740470b74a1 100644 (file)
@@ -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;
index b4de2bb7599a18fe33dcf97e5a819c71c424a937..ac832266cd77c76adf429813065dc7192f29e909 100644 (file)
@@ -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 (file)
index 0000000..24f8034
--- /dev/null
@@ -0,0 +1,59 @@
+/***************************************************************************
+ *   Copyright (C) 2005, 2006 by Carsten Niehaus <cniehaus@kde.org>        *
+ *                                                                         *
+ *   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 <kdebug.h>
+#include <iostream>
+
+int main(int argc, char *argv[])
+{
+    if (argc < 2 || argc > 2) {
+        std::cout << "Usage: isotopes <XML_FILE>\n";
+        return 1;
+    }
+
+    IsotopeParser * parser = new IsotopeParser();
+    QFile xmlFile(argv[1]);
+
+    QXmlInputSource source(&xmlFile);
+    QXmlSimpleReader reader;
+
+    reader.setContentHandler(parser);
+    reader.parse(source);
+
+    QList<Isotope*> 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;
+}