Ignore:
Timestamp:
May 2, 2010, 4:47:18 PM (15 years ago)
Author:
Saskia Metzler <metzler@…>
Children:
0647f4
Parents:
0f7883
Message:

Tremolo format parser

Location:
molecuilder/src/unittests
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/unittests/ParserUnitTest.cpp

    r0f7883 rd3513b  
    1515#include "Parser/TremoloParser.hpp"
    1616#include "World.hpp"
     17#include "atom.hpp"
    1718#include "element.hpp"
    1819#include "periodentafel.hpp"
     20#include "Descriptors/AtomTypeDescriptor.hpp"
    1921
    2022#ifdef HAVE_TESTRUNNER
     
    4143
    4244void ParserUnitTest::tearDown() {
     45  World::purgeInstance();
    4346}
    4447
     
    6366}
    6467
    65 void ParserUnitTest::rewriteTremoloTest() {
     68void ParserUnitTest::readTremoloPreliminaryCommentsTest() {
    6669  cout << "Testing the tremolo parser." << endl;
    6770  TremoloParser* testParser = new TremoloParser();
    68   stringstream input;
     71  stringstream input, output;
     72  string waterTremolo;
    6973
    7074  // Atomdata beginning with "# ATOMDATA"
    71   string waterTremolo = "#\n# ATOMDATA Id name Type x=3\n\n\n";
     75  waterTremolo = "# ATOMDATA\tId\tname\tType\tx=3\n";
    7276  input << waterTremolo;
    7377  testParser->load(&input);
     78  testParser->save(&output);
     79  CPPUNIT_ASSERT(waterTremolo == output.str());
    7480  input.clear();
     81  output.clear();
    7582
    7683  // Atomdata beginning with "#ATOMDATA"
    77   waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 H hydrogen 3.0 4.5 0.1\n\n";
     84  waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
    7885  input << waterTremolo;
    7986  testParser->load(&input);
     87  testParser->save(&output);
     88  CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
    8089  input.clear();
    81 
    82   // One simple data line
    83   waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 H hydrogen 3.0 4.5 0.1\n\n";
    84   input << waterTremolo;
    85   testParser->load(&input);
    86   input.clear();
     90  output.clear();
    8791
    8892  // Invalid key in Atomdata line
     
    9094  input << waterTremolo;
    9195  testParser->load(&input);
     96  //TODO: proove invalidity
    9297  input.clear();
     98}
     99
     100void ParserUnitTest::readTremoloCoordinatesTest() {
     101  TremoloParser* testParser = new TremoloParser();
     102  stringstream input;
     103  string waterTremolo;
     104
     105  // One simple data line
     106  waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
     107  input << waterTremolo;
     108  testParser->load(&input);
     109  CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->x.x[0] == 3.0);
     110  input.clear();
     111}
     112
     113void ParserUnitTest::readTremoloVelocityTest() {
     114  TremoloParser* testParser = new TremoloParser();
     115  stringstream input;
     116  string waterTremolo;
     117
     118  // One simple data line
     119  waterTremolo = "#\n#ATOMDATA Id name Type u=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
     120  input << waterTremolo;
     121  testParser->load(&input);
     122  CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->v.x[0] == 3.0);
     123  input.clear();
     124}
     125
     126void ParserUnitTest::readTremoloNeighborInformationTest() {
     127  TremoloParser* testParser = new TremoloParser();
     128  stringstream input;
     129  string waterTremolo;
     130
     131  // Neighbor data
     132  waterTremolo = "#\n#ATOMDATA Id Type neighbors=2\n1 H 3 0\n2 H 3 0\n3 O 1 2\n";
     133  input << waterTremolo;
     134  testParser->load(&input);
     135
     136  CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
     137  CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
     138      IsBondedTo(World::getInstance().getAtom(AtomByType(1))));
     139  input.clear();
     140}
     141
     142void ParserUnitTest::readAndWriteTremoloImprDataInformationTest() {
     143  TremoloParser* testParser = new TremoloParser();
     144  stringstream input, output;
     145  string waterTremolo;
     146
     147  // Neighbor data
     148  waterTremolo = "#\n#ATOMDATA Id Type imprData\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n";
     149  input << waterTremolo;
     150  testParser->load(&input);
     151  testParser->save(&output);
     152  CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
     153  CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
     154  input.clear();
     155  output.clear();
     156}
     157
     158void ParserUnitTest::readAndWriteTremoloTorsionInformationTest() {
     159  TremoloParser* testParser = new TremoloParser();
     160  stringstream input, output;
     161  string waterTremolo;
     162
     163  // Neighbor data
     164  waterTremolo = "#\n#ATOMDATA Id Type torsion\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n";
     165  input << waterTremolo;
     166  testParser->load(&input);
     167  testParser->save(&output);
     168  CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
     169  CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
     170  input.clear();
     171  output.clear();
     172}
     173
     174void ParserUnitTest::writeTremoloTest() {
     175  TremoloParser* testParser = new TremoloParser();
     176  stringstream output;
     177
     178  // with the maximum number of fields and minimal information, default values are printed
     179  atom* newAtom = World::getInstance().createAtom();
     180  newAtom->type = World::getInstance().getPeriode()->FindElement(1);
     181  testParser->setFieldsForSave("x=3 u=3 F stress Id neighbors=5 imprData GroupMeasureTypeNo Type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion");
     182  testParser->save(&output);
     183  CPPUNIT_ASSERT(output.str() == "# ATOMDATA\tx=3\tu=3\tF\tstress\tId\tneighbors=5\timprData\tGroupMeasureTypeNo\tType\textType\tname\tresName\tchainID\tresSeq\toccupancy\ttempFactor\tsegID\tCharge\tcharge\tGrpTypeNo\ttorsion\n0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t-\t0\tH\t-\t-\t-\t0\t0\t0\t0\t0\t0\t0\t0\t-\t\n");
    93184
    94185  cout << "testing the tremolo parser is done" << endl;
  • molecuilder/src/unittests/ParserUnitTest.hpp

    r0f7883 rd3513b  
    1515  CPPUNIT_TEST_SUITE( ParserUnitTest ) ;
    1616  CPPUNIT_TEST ( rewriteAnXyzTest );
    17   CPPUNIT_TEST ( rewriteTremoloTest );
     17  CPPUNIT_TEST ( readTremoloPreliminaryCommentsTest );
     18  CPPUNIT_TEST ( readTremoloCoordinatesTest );
     19  CPPUNIT_TEST ( readTremoloVelocityTest );
     20  CPPUNIT_TEST ( readTremoloNeighborInformationTest );
     21  CPPUNIT_TEST ( readAndWriteTremoloImprDataInformationTest );
     22  CPPUNIT_TEST ( readAndWriteTremoloTorsionInformationTest );
     23  CPPUNIT_TEST ( writeTremoloTest );
    1824  CPPUNIT_TEST_SUITE_END();
    1925
     
    2329
    2430  void rewriteAnXyzTest();
    25   void rewriteTremoloTest();
     31  void readTremoloPreliminaryCommentsTest();
     32  void readTremoloCoordinatesTest();
     33  void readTremoloVelocityTest();
     34  void readTremoloNeighborInformationTest();
     35  void readAndWriteTremoloImprDataInformationTest();
     36  void readAndWriteTremoloTorsionInformationTest();
     37  void writeTremoloTest();
    2638};
    2739
  • molecuilder/src/unittests/SingletonTest.cpp

    r0f7883 rd3513b  
    5252    count1++;
    5353  }
    54   // explicit copy constructor to catch if thsi is ever called
     54  // explicit copy constructor to catch if this is ever called
    5555  SingletonStub2(const SingletonStub2&){
    5656    CPPUNIT_FAIL    ( "Copy constructor of Singleton called" );
Note: See TracChangeset for help on using the changeset viewer.