| [4fbca9c] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
| [0aa122] | 4 | * Copyright (C)  2010-2012 University of Bonn. All rights reserved. | 
|---|
| [4fbca9c] | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | /* | 
|---|
|  | 9 | * ParserTremoloUnitTest.cpp | 
|---|
|  | 10 | * | 
|---|
|  | 11 | *  Created on: Mar 3, 2010 | 
|---|
|  | 12 | *      Author: metzler | 
|---|
|  | 13 | */ | 
|---|
|  | 14 |  | 
|---|
|  | 15 | // include config.h | 
|---|
|  | 16 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 17 | #include <config.h> | 
|---|
|  | 18 | #endif | 
|---|
|  | 19 |  | 
|---|
|  | 20 | #include "ParserTremoloUnitTest.hpp" | 
|---|
|  | 21 |  | 
|---|
|  | 22 | #include <cppunit/CompilerOutputter.h> | 
|---|
|  | 23 | #include <cppunit/extensions/TestFactoryRegistry.h> | 
|---|
|  | 24 | #include <cppunit/ui/text/TestRunner.h> | 
|---|
|  | 25 |  | 
|---|
| [6f0841] | 26 | #include "Atom/atom.hpp" | 
|---|
| [073a9e4] | 27 | #include "Descriptors/AtomTypeDescriptor.hpp" | 
|---|
| [3bdb6d] | 28 | #include "Element/element.hpp" | 
|---|
|  | 29 | #include "Element/periodentafel.hpp" | 
|---|
| [4fbca9c] | 30 | #include "Parser/TremoloParser.hpp" | 
|---|
| [765f16] | 31 | #include "Parser/ChangeTracker.hpp" | 
|---|
| [073a9e4] | 32 | #include "World.hpp" | 
|---|
|  | 33 | #include "WorldTime.hpp" | 
|---|
| [4fbca9c] | 34 |  | 
|---|
|  | 35 | #ifdef HAVE_TESTRUNNER | 
|---|
|  | 36 | #include "UnitTestMain.hpp" | 
|---|
|  | 37 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
|  | 38 |  | 
|---|
|  | 39 | using namespace std; | 
|---|
|  | 40 |  | 
|---|
|  | 41 | // Registers the fixture into the 'registry' | 
|---|
|  | 42 | CPPUNIT_TEST_SUITE_REGISTRATION( ParserTremoloUnitTest ); | 
|---|
|  | 43 |  | 
|---|
| [4d4d33] | 44 | static string Tremolo_Atomdata1 = "\ | 
|---|
| [305e7e] | 45 | # ATOMDATA\tId\tname\ttype\tx=3\n"; | 
|---|
| [4d4d33] | 46 | static string Tremolo_Atomdata2 = "\ | 
|---|
|  | 47 | #\n\ | 
|---|
| [305e7e] | 48 | #ATOMDATA Id name type x=3\n\ | 
|---|
| [4d4d33] | 49 | 1 hydrogen H 3.0 4.5 0.1\n\ | 
|---|
|  | 50 | \n"; | 
|---|
|  | 51 | static string Tremolo_invalidkey = "\ | 
|---|
|  | 52 | #\n\ | 
|---|
| [305e7e] | 53 | #ATOMDATA Id name foo type x=3\n\ | 
|---|
| [4d4d33] | 54 | \n\n"; | 
|---|
|  | 55 | static string Tremolo_velocity = "\ | 
|---|
|  | 56 | #\n\ | 
|---|
| [305e7e] | 57 | #ATOMDATA Id name type u=3\n\ | 
|---|
| [4d4d33] | 58 | 1 hydrogen H 3.0 4.5 0.1\n\ | 
|---|
|  | 59 | \n"; | 
|---|
|  | 60 | static string Tremolo_neighbours = "#\n\ | 
|---|
| [305e7e] | 61 | #ATOMDATA Id type neighbors=2\n\ | 
|---|
| [4d4d33] | 62 | 1 H 3 0\n\ | 
|---|
|  | 63 | 2 H 3 0\n\ | 
|---|
|  | 64 | 3 O 1 2\n"; | 
|---|
|  | 65 | static string Tremolo_improper = "\ | 
|---|
|  | 66 | #\n\ | 
|---|
| [305e7e] | 67 | #ATOMDATA Id type imprData\n\ | 
|---|
| [4d4d33] | 68 | 8 H 9-10\n\ | 
|---|
|  | 69 | 9 H 10-8,8-10\n\ | 
|---|
|  | 70 | 10 O -\n"; | 
|---|
|  | 71 | static string Tremolo_torsion = "\ | 
|---|
|  | 72 | #\n\ | 
|---|
| [305e7e] | 73 | #ATOMDATA Id type torsion\n\ | 
|---|
| [4d4d33] | 74 | 8 H 9-10\n\ | 
|---|
|  | 75 | 9 H 10-8,8-10\n\ | 
|---|
|  | 76 | 10 O -\n"; | 
|---|
|  | 77 | static string Tremolo_full = "\ | 
|---|
| [305e7e] | 78 | # 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\n\ | 
|---|
| [4d4d33] | 79 | 0\t0\t0\t0\t0\t0\t0\t0\t1\t0\t0\t0\t0\t0\t-\t0\tH\t-\t-\t-\t0\t0\t0\t0\t0\t0\t0\t0\t-\t\n"; | 
|---|
| [4fbca9c] | 80 |  | 
|---|
|  | 81 | void ParserTremoloUnitTest::setUp() { | 
|---|
|  | 82 | World::getInstance(); | 
|---|
|  | 83 |  | 
|---|
| [765f16] | 84 | parser = new FormatParser<tremolo>(); | 
|---|
|  | 85 |  | 
|---|
| [4fbca9c] | 86 | // we need hydrogens and oxygens in the following tests | 
|---|
|  | 87 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL); | 
|---|
|  | 88 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL); | 
|---|
|  | 89 | } | 
|---|
|  | 90 |  | 
|---|
| [765f16] | 91 | void ParserTremoloUnitTest::tearDown() | 
|---|
|  | 92 | { | 
|---|
|  | 93 | delete parser; | 
|---|
| [4fbca9c] | 94 | ChangeTracker::purgeInstance(); | 
|---|
|  | 95 | World::purgeInstance(); | 
|---|
|  | 96 | } | 
|---|
|  | 97 |  | 
|---|
|  | 98 | /************************************ tests ***********************************/ | 
|---|
|  | 99 |  | 
|---|
|  | 100 | void ParserTremoloUnitTest::readTremoloPreliminaryCommentsTest() { | 
|---|
|  | 101 | cout << "Testing the tremolo parser." << endl; | 
|---|
|  | 102 | stringstream input, output; | 
|---|
|  | 103 |  | 
|---|
|  | 104 | // Atomdata beginning with "# ATOMDATA" | 
|---|
| [73916f] | 105 | { | 
|---|
|  | 106 | input << Tremolo_Atomdata1; | 
|---|
| [765f16] | 107 | parser->load(&input); | 
|---|
| [73916f] | 108 | std::vector<atom *> atoms = World::getInstance().getAllAtoms(); | 
|---|
| [765f16] | 109 | parser->save(&output, atoms); | 
|---|
| [4d4d33] | 110 | //    std::cout << output.str() << std::endl; | 
|---|
|  | 111 | //    std::cout << Tremolo_Atomdata1 << std::endl; | 
|---|
| [73916f] | 112 | CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str()); | 
|---|
|  | 113 | input.clear(); | 
|---|
|  | 114 | output.clear(); | 
|---|
|  | 115 | } | 
|---|
| [4fbca9c] | 116 |  | 
|---|
|  | 117 | // Atomdata beginning with "#ATOMDATA" | 
|---|
| [73916f] | 118 | { | 
|---|
|  | 119 | input << Tremolo_Atomdata2; | 
|---|
| [765f16] | 120 | parser->load(&input); | 
|---|
| [73916f] | 121 | std::vector<atom *> atoms = World::getInstance().getAllAtoms(); | 
|---|
| [765f16] | 122 | parser->save(&output, atoms); | 
|---|
| [4d4d33] | 123 | std::cout << output.str() << std::endl; | 
|---|
| [73916f] | 124 | CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos); | 
|---|
|  | 125 | input.clear(); | 
|---|
|  | 126 | output.clear(); | 
|---|
|  | 127 | } | 
|---|
| [4fbca9c] | 128 |  | 
|---|
|  | 129 | // Invalid key in Atomdata line | 
|---|
|  | 130 | input << Tremolo_invalidkey; | 
|---|
| [765f16] | 131 | parser->load(&input); | 
|---|
| [73916f] | 132 | //TODO: prove invalidity | 
|---|
| [4fbca9c] | 133 | input.clear(); | 
|---|
|  | 134 | } | 
|---|
|  | 135 |  | 
|---|
|  | 136 | void ParserTremoloUnitTest::readTremoloCoordinatesTest() { | 
|---|
|  | 137 | stringstream input; | 
|---|
|  | 138 |  | 
|---|
|  | 139 | // One simple data line | 
|---|
|  | 140 | input << Tremolo_Atomdata2; | 
|---|
| [765f16] | 141 | parser->load(&input); | 
|---|
| [4fbca9c] | 142 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->at(0) == 3.0); | 
|---|
|  | 143 | input.clear(); | 
|---|
|  | 144 | } | 
|---|
|  | 145 |  | 
|---|
|  | 146 | void ParserTremoloUnitTest::readTremoloVelocityTest() { | 
|---|
|  | 147 | stringstream input; | 
|---|
|  | 148 |  | 
|---|
|  | 149 | // One simple data line | 
|---|
|  | 150 | input << Tremolo_velocity; | 
|---|
| [765f16] | 151 | parser->load(&input); | 
|---|
| [bce72c] | 152 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->getAtomicVelocity()[0] == 3.0); | 
|---|
| [4fbca9c] | 153 | input.clear(); | 
|---|
|  | 154 | } | 
|---|
|  | 155 |  | 
|---|
|  | 156 | void ParserTremoloUnitTest::readTremoloNeighborInformationTest() { | 
|---|
|  | 157 | stringstream input; | 
|---|
|  | 158 |  | 
|---|
|  | 159 | // Neighbor data | 
|---|
|  | 160 | input << Tremolo_neighbours; | 
|---|
| [765f16] | 161 | parser->load(&input); | 
|---|
| [4fbca9c] | 162 |  | 
|---|
|  | 163 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); | 
|---|
|  | 164 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))-> | 
|---|
| [073a9e4] | 165 | IsBondedTo(WorldTime::getTime(), World::getInstance().getAtom(AtomByType(1)))); | 
|---|
| [4fbca9c] | 166 | input.clear(); | 
|---|
|  | 167 | } | 
|---|
|  | 168 |  | 
|---|
|  | 169 | void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() { | 
|---|
|  | 170 | stringstream input, output; | 
|---|
|  | 171 |  | 
|---|
|  | 172 | // Neighbor data | 
|---|
| [73916f] | 173 | { | 
|---|
|  | 174 | input << Tremolo_improper; | 
|---|
| [765f16] | 175 | parser->load(&input); | 
|---|
| [73916f] | 176 | std::vector<atom *> atoms = World::getInstance().getAllAtoms(); | 
|---|
| [765f16] | 177 | parser->save(&output, atoms); | 
|---|
| [73916f] | 178 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); | 
|---|
| [4d4d33] | 179 | std::cout << output.str() << std::endl; | 
|---|
| [73916f] | 180 | CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos); | 
|---|
|  | 181 | input.clear(); | 
|---|
|  | 182 | output.clear(); | 
|---|
|  | 183 | } | 
|---|
| [4fbca9c] | 184 | } | 
|---|
|  | 185 |  | 
|---|
|  | 186 | void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() { | 
|---|
|  | 187 | stringstream input, output; | 
|---|
|  | 188 |  | 
|---|
|  | 189 | // Neighbor data | 
|---|
| [73916f] | 190 | { | 
|---|
|  | 191 | input << Tremolo_torsion; | 
|---|
| [765f16] | 192 | parser->load(&input); | 
|---|
| [73916f] | 193 | std::vector<atom *> atoms = World::getInstance().getAllAtoms(); | 
|---|
| [765f16] | 194 | parser->save(&output, atoms); | 
|---|
| [73916f] | 195 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); | 
|---|
| [4d4d33] | 196 | std::cout << output.str() << std::endl; | 
|---|
| [73916f] | 197 | CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos); | 
|---|
|  | 198 | input.clear(); | 
|---|
|  | 199 | output.clear(); | 
|---|
|  | 200 | } | 
|---|
| [4fbca9c] | 201 | } | 
|---|
|  | 202 |  | 
|---|
|  | 203 | void ParserTremoloUnitTest::writeTremoloTest() { | 
|---|
|  | 204 | stringstream output; | 
|---|
|  | 205 |  | 
|---|
|  | 206 | // with the maximum number of fields and minimal information, default values are printed | 
|---|
| [73916f] | 207 | { | 
|---|
|  | 208 | atom* newAtom = World::getInstance().createAtom(); | 
|---|
|  | 209 | newAtom->setType(1); | 
|---|
| [765f16] | 210 | parser->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"); | 
|---|
| [73916f] | 211 | std::vector<atom *> atoms = World::getInstance().getAllAtoms(); | 
|---|
| [765f16] | 212 | parser->save(&output, atoms); | 
|---|
| [73916f] | 213 | CPPUNIT_ASSERT(output.str() == Tremolo_full); | 
|---|
|  | 214 | } | 
|---|
| [4fbca9c] | 215 |  | 
|---|
|  | 216 | cout << "testing the tremolo parser is done" << endl; | 
|---|
|  | 217 | } | 
|---|
| [765f16] | 218 |  | 
|---|