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