Index: src/unittests/FormulaUnittest.cpp
===================================================================
--- src/unittests/FormulaUnittest.cpp	(revision 1e1dac5d1c26592f4cda16544662cd19744d935c)
+++ src/unittests/FormulaUnittest.cpp	(revision 1e1dac5d1c26592f4cda16544662cd19744d935c)
@@ -0,0 +1,183 @@
+/*
+ * FormulaUnittest.cpp
+ *
+ *  Created on: Jul 21, 2010
+ *      Author: crueger
+ */
+
+#include "FormulaUnittest.hpp"
+
+#include <cppunit/CompilerOutputter.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+
+#include <iostream>
+
+#include "Formula.hpp"
+#include "World.hpp"
+
+#ifdef HAVE_TESTRUNNER
+#include "UnitTestMain.hpp"
+#endif /*HAVE_TESTRUNNER*/
+
+using namespace std;
+
+CPPUNIT_TEST_SUITE_REGISTRATION( FormulaUnittest );
+
+void FormulaUnittest::setUp(){}
+void FormulaUnittest::tearDown(){
+  World::purgeInstance();
+}
+
+void FormulaUnittest::baseTest(){
+  Formula formula;
+  CPPUNIT_ASSERT_EQUAL(formula.getElementCount(),(unsigned int)0);
+  CPPUNIT_ASSERT(formula.begin()==formula.end());
+
+  // test some one letter element names
+  formula += "H";
+  CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)1);
+  CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula.getElementCount(),(unsigned int)1);
+  CPPUNIT_ASSERT(formula.begin()!=formula.end());
+  formula += "H";
+  CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)2);
+  CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula.getElementCount(),(unsigned int)1);
+  CPPUNIT_ASSERT(formula.begin()!=formula.end());
+  formula += "O";
+  CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)2);
+  CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)1);
+  CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula.getElementCount(),(unsigned int)2);
+  CPPUNIT_ASSERT(formula.begin()!=formula.end());
+
+  // test copy constructor
+  Formula formula2=formula;
+  CPPUNIT_ASSERT_EQUAL(formula2["H"],(unsigned int)2);
+  CPPUNIT_ASSERT_EQUAL(formula2["O"],(unsigned int)1);
+  CPPUNIT_ASSERT_EQUAL(formula2["C"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula2.getElementCount(),(unsigned int)2);
+  CPPUNIT_ASSERT(formula2.begin()!=formula2.end());
+
+  // test Assignment operator
+  formula2=Formula();
+  CPPUNIT_ASSERT_EQUAL(formula2["H"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula2["O"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula2["C"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula2.getElementCount(),(unsigned int)0);
+  CPPUNIT_ASSERT(formula2.begin()==formula2.end());
+
+  // test comparison
+  CPPUNIT_ASSERT(formula!=formula2);
+  Formula formula3;
+  formula3 += "H";
+  formula3 += "H";
+  formula3 += "O";
+  CPPUNIT_ASSERT(formula==formula3);
+
+  // removal of elements
+  formula -= "H";
+  CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)1);
+  CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)1);
+  CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula.getElementCount(),(unsigned int)2);
+  CPPUNIT_ASSERT(formula.begin()!=formula.end());
+
+  formula -= "O";
+  CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)1);
+  CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula.getElementCount(),(unsigned int)1);
+  CPPUNIT_ASSERT(formula.begin()!=formula.end());
+
+  formula -= "H";
+  CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
+  CPPUNIT_ASSERT_EQUAL(formula.getElementCount(),(unsigned int)0);
+  CPPUNIT_ASSERT(formula.begin()==formula.end());
+}
+
+void FormulaUnittest::parseTest(){
+  {
+    Formula formula("");
+    CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)0);
+    CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)0);
+    CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
+    CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
+  }
+  {
+    Formula formula("H");
+    CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)1);
+    CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)0);
+    CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
+    CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
+  }
+  {
+    Formula formula("H2");
+    CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)2);
+    CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)0);
+    CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
+    CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
+  }
+  {
+    Formula formula("H2O");
+    CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)2);
+    CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)1);
+    CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
+    CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
+  }
+  {
+    Formula formula("CH3COOH");
+    CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)4);
+    CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)2);
+    CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)2);
+    CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
+  }
+  {
+    Formula formula("CH3COONa");
+    CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)3);
+    CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)2);
+    CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)2);
+    CPPUNIT_ASSERT_EQUAL(formula["Na"],(unsigned int)1);
+    CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
+  }
+  {
+    Formula formula("NaCH3COO");
+    CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)3);
+    CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)2);
+    CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)2);
+    CPPUNIT_ASSERT_EQUAL(formula["Na"],(unsigned int)1);
+    CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
+  }
+  {
+    Formula formula("Na2CO3");
+    CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)0);
+    CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)3);
+    CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)1);
+    CPPUNIT_ASSERT_EQUAL(formula["Na"],(unsigned int)2);
+    CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
+  }
+  {
+    CPPUNIT_ASSERT_THROW(Formula formula("74107"),ParseError);
+    CPPUNIT_ASSERT_THROW(Formula formula("  "),ParseError);
+    CPPUNIT_ASSERT_THROW(Formula formula("nAcL"),ParseError);
+    CPPUNIT_ASSERT_THROW(Formula formula("NAcL"),ParseError);
+    CPPUNIT_ASSERT_THROW(Formula formula("Na Cl"),ParseError);
+    CPPUNIT_ASSERT_THROW(Formula formula("1NaCl"),ParseError);
+    CPPUNIT_ASSERT_THROW(Formula formula("Mag"),ParseError);
+  }
+
+
+}
Index: src/unittests/FormulaUnittest.hpp
===================================================================
--- src/unittests/FormulaUnittest.hpp	(revision 1e1dac5d1c26592f4cda16544662cd19744d935c)
+++ src/unittests/FormulaUnittest.hpp	(revision 1e1dac5d1c26592f4cda16544662cd19744d935c)
@@ -0,0 +1,28 @@
+/*
+ * FormulaUnittest.hpp
+ *
+ *  Created on: Jul 21, 2010
+ *      Author: crueger
+ */
+
+#ifndef FORMULAUNITTEST_HPP_
+#define FORMULAUNITTEST_HPP_
+
+#include <cppunit/extensions/HelperMacros.h>
+
+class FormulaUnittest : public CppUnit::TestFixture
+{
+  CPPUNIT_TEST_SUITE( FormulaUnittest );
+  CPPUNIT_TEST ( baseTest );
+  CPPUNIT_TEST ( parseTest );
+  CPPUNIT_TEST_SUITE_END();
+
+public:
+  void setUp();
+  void tearDown();
+
+  void baseTest();
+  void parseTest();
+};
+
+#endif /* FORMULAUNITTEST_HPP_ */
Index: src/unittests/Makefile.am
===================================================================
--- src/unittests/Makefile.am	(revision be97a841b19bbe05e88f3d3ac69c9cb5cd562f10)
+++ src/unittests/Makefile.am	(revision 1e1dac5d1c26592f4cda16544662cd19744d935c)
@@ -21,4 +21,5 @@
   CacheableTest \
   CountBondsUnitTest \
+  FormulaUnittest \
   GSLMatrixSymmetricUnitTest \
   GSLMatrixUnitTest \
@@ -66,4 +67,5 @@
   CacheableTest.cpp \
   CountBondsUnitTest.cpp \
+  FormulaUnittest.cpp \
   gslmatrixsymmetricunittest.cpp \
   gslmatrixunittest.cpp \
@@ -102,4 +104,5 @@
   CacheableTest.hpp \
   CountBondsUnitTest.hpp \
+  FormulaUnittest.hpp \
   gslmatrixsymmetricunittest.hpp \
   gslmatrixunittest.hpp \
@@ -158,4 +161,7 @@
 CountBondsUnitTest_LDADD = ${ALLLIBS}
 
+FormulaUnittest_SOURCES = UnitTestMain.cpp FormulaUnittest.cpp FormulaUnittest.hpp
+FormulaUnittest_LDADD = ${ALLLIBS}
+
 GSLMatrixSymmetricUnitTest_SOURCES = UnitTestMain.cpp gslmatrixsymmetricunittest.cpp gslmatrixsymmetricunittest.hpp
 GSLMatrixSymmetricUnitTest_LDADD = ${GSLLIBS}
