1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010 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 "atom.hpp"
|
---|
27 | #include "Descriptors/AtomTypeDescriptor.hpp"
|
---|
28 | #include "Element/element.hpp"
|
---|
29 | #include "Element/periodentafel.hpp"
|
---|
30 | #include "Parser/TremoloParser.hpp"
|
---|
31 | #include "Parser/ChangeTracker.hpp"
|
---|
32 | #include "World.hpp"
|
---|
33 | #include "WorldTime.hpp"
|
---|
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 |
|
---|
44 | static string Tremolo_Atomdata1 = "\
|
---|
45 | # ATOMDATA\tId\tname\ttype\tx=3\n";
|
---|
46 | static string Tremolo_Atomdata2 = "\
|
---|
47 | #\n\
|
---|
48 | #ATOMDATA Id name type x=3\n\
|
---|
49 | 1 hydrogen H 3.0 4.5 0.1\n\
|
---|
50 | \n";
|
---|
51 | static string Tremolo_invalidkey = "\
|
---|
52 | #\n\
|
---|
53 | #ATOMDATA Id name foo type x=3\n\
|
---|
54 | \n\n";
|
---|
55 | static string Tremolo_velocity = "\
|
---|
56 | #\n\
|
---|
57 | #ATOMDATA Id name type u=3\n\
|
---|
58 | 1 hydrogen H 3.0 4.5 0.1\n\
|
---|
59 | \n";
|
---|
60 | static string Tremolo_neighbours = "#\n\
|
---|
61 | #ATOMDATA Id type neighbors=2\n\
|
---|
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\
|
---|
67 | #ATOMDATA Id type imprData\n\
|
---|
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\
|
---|
73 | #ATOMDATA Id type torsion\n\
|
---|
74 | 8 H 9-10\n\
|
---|
75 | 9 H 10-8,8-10\n\
|
---|
76 | 10 O -\n";
|
---|
77 | static string Tremolo_full = "\
|
---|
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\
|
---|
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";
|
---|
80 |
|
---|
81 | void ParserTremoloUnitTest::setUp() {
|
---|
82 | World::getInstance();
|
---|
83 |
|
---|
84 | parser = new FormatParser<tremolo>();
|
---|
85 |
|
---|
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 |
|
---|
91 | void ParserTremoloUnitTest::tearDown()
|
---|
92 | {
|
---|
93 | delete parser;
|
---|
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"
|
---|
105 | {
|
---|
106 | input << Tremolo_Atomdata1;
|
---|
107 | parser->load(&input);
|
---|
108 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
---|
109 | parser->save(&output, atoms);
|
---|
110 | // std::cout << output.str() << std::endl;
|
---|
111 | // std::cout << Tremolo_Atomdata1 << std::endl;
|
---|
112 | CPPUNIT_ASSERT(Tremolo_Atomdata1 == output.str());
|
---|
113 | input.clear();
|
---|
114 | output.clear();
|
---|
115 | }
|
---|
116 |
|
---|
117 | // Atomdata beginning with "#ATOMDATA"
|
---|
118 | {
|
---|
119 | input << Tremolo_Atomdata2;
|
---|
120 | parser->load(&input);
|
---|
121 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
---|
122 | parser->save(&output, atoms);
|
---|
123 | std::cout << output.str() << std::endl;
|
---|
124 | CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
|
---|
125 | input.clear();
|
---|
126 | output.clear();
|
---|
127 | }
|
---|
128 |
|
---|
129 | // Invalid key in Atomdata line
|
---|
130 | input << Tremolo_invalidkey;
|
---|
131 | parser->load(&input);
|
---|
132 | //TODO: prove invalidity
|
---|
133 | input.clear();
|
---|
134 | }
|
---|
135 |
|
---|
136 | void ParserTremoloUnitTest::readTremoloCoordinatesTest() {
|
---|
137 | stringstream input;
|
---|
138 |
|
---|
139 | // One simple data line
|
---|
140 | input << Tremolo_Atomdata2;
|
---|
141 | parser->load(&input);
|
---|
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;
|
---|
151 | parser->load(&input);
|
---|
152 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->getAtomicVelocity()[0] == 3.0);
|
---|
153 | input.clear();
|
---|
154 | }
|
---|
155 |
|
---|
156 | void ParserTremoloUnitTest::readTremoloNeighborInformationTest() {
|
---|
157 | stringstream input;
|
---|
158 |
|
---|
159 | // Neighbor data
|
---|
160 | input << Tremolo_neighbours;
|
---|
161 | parser->load(&input);
|
---|
162 |
|
---|
163 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
164 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
|
---|
165 | IsBondedTo(WorldTime::getTime(), World::getInstance().getAtom(AtomByType(1))));
|
---|
166 | input.clear();
|
---|
167 | }
|
---|
168 |
|
---|
169 | void ParserTremoloUnitTest::readAndWriteTremoloImprDataInformationTest() {
|
---|
170 | stringstream input, output;
|
---|
171 |
|
---|
172 | // Neighbor data
|
---|
173 | {
|
---|
174 | input << Tremolo_improper;
|
---|
175 | parser->load(&input);
|
---|
176 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
---|
177 | parser->save(&output, atoms);
|
---|
178 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
179 | std::cout << output.str() << std::endl;
|
---|
180 | CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
|
---|
181 | input.clear();
|
---|
182 | output.clear();
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | void ParserTremoloUnitTest::readAndWriteTremoloTorsionInformationTest() {
|
---|
187 | stringstream input, output;
|
---|
188 |
|
---|
189 | // Neighbor data
|
---|
190 | {
|
---|
191 | input << Tremolo_torsion;
|
---|
192 | parser->load(&input);
|
---|
193 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
---|
194 | parser->save(&output, atoms);
|
---|
195 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
196 | std::cout << output.str() << std::endl;
|
---|
197 | CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
|
---|
198 | input.clear();
|
---|
199 | output.clear();
|
---|
200 | }
|
---|
201 | }
|
---|
202 |
|
---|
203 | void ParserTremoloUnitTest::writeTremoloTest() {
|
---|
204 | stringstream output;
|
---|
205 |
|
---|
206 | // with the maximum number of fields and minimal information, default values are printed
|
---|
207 | {
|
---|
208 | atom* newAtom = World::getInstance().createAtom();
|
---|
209 | newAtom->setType(1);
|
---|
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");
|
---|
211 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
---|
212 | parser->save(&output, atoms);
|
---|
213 | CPPUNIT_ASSERT(output.str() == Tremolo_full);
|
---|
214 | }
|
---|
215 |
|
---|
216 | cout << "testing the tremolo parser is done" << endl;
|
---|
217 | }
|
---|
218 |
|
---|