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