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