source: src/unittests/ParserUnitTest.cpp@ b9b604

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since b9b604 was b9b604, checked in by Frederik Heber <heber@…>, 15 years ago

Merge branch 'StateAndFormatParser' into CommandLineActionMapping

Conflicts:

molecuilder/src/Makefile.am
molecuilder/src/tesselation.cpp
molecuilder/src/unittests/Makefile.am

The following conflicts had to be resolved:

  • molecuilder/src/Makefile.am had an old version of the HEADER definition which would not be merged automatically. ${PARSERHEADER} was missing.
  • molecuilder/src/unittests/Makefile.am had an blank line too much
  • TesselPoint::TesselPoint() had an older version where TesselPoint::Name was initialized to "-" instead of NULL. The latter should be correct due to missing delete(Name) in destructor.
  • compilation errors arose due to the private nature of Vector::x[] introduced in the branch VectorRefactoring. This has been fixed in XyzParser, TremoloParser and the ParserUnitTest.
  • ParserUnitTest runs fine.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 5.8 KB
Line 
1/*
2 * ParserUnitTest.cpp
3 *
4 * Created on: Mar 3, 2010
5 * Author: metzler
6 */
7
8#include "ParserUnitTest.hpp"
9
10#include <cppunit/CompilerOutputter.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12#include <cppunit/ui/text/TestRunner.h>
13
14#include "Parser/XyzParser.hpp"
15#include "Parser/TremoloParser.hpp"
16#include "World.hpp"
17#include "atom.hpp"
18#include "element.hpp"
19#include "periodentafel.hpp"
20#include "Descriptors/AtomTypeDescriptor.hpp"
21
22#ifdef HAVE_TESTRUNNER
23#include "UnitTestMain.hpp"
24#endif /*HAVE_TESTRUNNER*/
25
26using namespace std;
27
28// Registers the fixture into the 'registry'
29CPPUNIT_TEST_SUITE_REGISTRATION( ParserUnitTest );
30
31
32void ParserUnitTest::setUp() {
33 element* oxygen = new element();
34 oxygen->symbol[0] = 'O';
35 oxygen->Z = 8;
36 World::getInstance().getPeriode()->AddElement(oxygen);
37
38 element* hydrogen = new element();
39 hydrogen->symbol[0] = 'H';
40 hydrogen->Z = 1;
41 World::getInstance().getPeriode()->AddElement(hydrogen);
42}
43
44void ParserUnitTest::tearDown() {
45 World::purgeInstance();
46}
47
48/************************************ tests ***********************************/
49
50void ParserUnitTest::rewriteAnXyzTest() {
51 cout << "Testing the XYZ parser." << endl;
52 XyzParser* testParser = new XyzParser();
53 string waterXyz = "3\nH2O: water molecule\nO\t0.000000\t0.000000\t0.000000\nH\t0.758602\t0.000000\t0.504284\nH\t0.758602\t0.000000\t-0.504284\n";
54 stringstream input;
55 input << waterXyz;
56 testParser->load(&input);
57
58 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
59
60 string newWaterXyz = "";
61 stringstream output;
62 testParser->save(&output);
63 newWaterXyz = output.str();
64
65 CPPUNIT_ASSERT(waterXyz == newWaterXyz);
66}
67
68void ParserUnitTest::readTremoloPreliminaryCommentsTest() {
69 cout << "Testing the tremolo parser." << endl;
70 TremoloParser* testParser = new TremoloParser();
71 stringstream input, output;
72 string waterTremolo;
73
74 // Atomdata beginning with "# ATOMDATA"
75 waterTremolo = "# ATOMDATA\tId\tname\tType\tx=3\n";
76 input << waterTremolo;
77 testParser->load(&input);
78 testParser->save(&output);
79 CPPUNIT_ASSERT(waterTremolo == output.str());
80 input.clear();
81 output.clear();
82
83 // Atomdata beginning with "#ATOMDATA"
84 waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
85 input << waterTremolo;
86 testParser->load(&input);
87 testParser->save(&output);
88 CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
89 input.clear();
90 output.clear();
91
92 // Invalid key in Atomdata line
93 waterTremolo = "#\n#ATOMDATA Id name foo Type x=3\n\n\n";
94 input << waterTremolo;
95 testParser->load(&input);
96 //TODO: proove invalidity
97 input.clear();
98}
99
100void ParserUnitTest::readTremoloCoordinatesTest() {
101 TremoloParser* testParser = new TremoloParser();
102 stringstream input;
103 string waterTremolo;
104
105 // One simple data line
106 waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
107 input << waterTremolo;
108 testParser->load(&input);
109 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->x[0] == 3.0);
110 input.clear();
111}
112
113void ParserUnitTest::readTremoloVelocityTest() {
114 TremoloParser* testParser = new TremoloParser();
115 stringstream input;
116 string waterTremolo;
117
118 // One simple data line
119 waterTremolo = "#\n#ATOMDATA Id name Type u=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
120 input << waterTremolo;
121 testParser->load(&input);
122 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->v[0] == 3.0);
123 input.clear();
124}
125
126void ParserUnitTest::readTremoloNeighborInformationTest() {
127 TremoloParser* testParser = new TremoloParser();
128 stringstream input;
129 string waterTremolo;
130
131 // Neighbor data
132 waterTremolo = "#\n#ATOMDATA Id Type neighbors=2\n1 H 3 0\n2 H 3 0\n3 O 1 2\n";
133 input << waterTremolo;
134 testParser->load(&input);
135
136 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
137 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
138 IsBondedTo(World::getInstance().getAtom(AtomByType(1))));
139 input.clear();
140}
141
142void ParserUnitTest::readAndWriteTremoloImprDataInformationTest() {
143 TremoloParser* testParser = new TremoloParser();
144 stringstream input, output;
145 string waterTremolo;
146
147 // Neighbor data
148 waterTremolo = "#\n#ATOMDATA Id Type imprData\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n";
149 input << waterTremolo;
150 testParser->load(&input);
151 testParser->save(&output);
152 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
153 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
154 input.clear();
155 output.clear();
156}
157
158void ParserUnitTest::readAndWriteTremoloTorsionInformationTest() {
159 TremoloParser* testParser = new TremoloParser();
160 stringstream input, output;
161 string waterTremolo;
162
163 // Neighbor data
164 waterTremolo = "#\n#ATOMDATA Id Type torsion\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n";
165 input << waterTremolo;
166 testParser->load(&input);
167 testParser->save(&output);
168 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
169 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
170 input.clear();
171 output.clear();
172}
173
174void ParserUnitTest::writeTremoloTest() {
175 TremoloParser* testParser = new TremoloParser();
176 stringstream output;
177
178 // with the maximum number of fields and minimal information, default values are printed
179 atom* newAtom = World::getInstance().createAtom();
180 newAtom->type = World::getInstance().getPeriode()->FindElement(1);
181 testParser->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");
182 testParser->save(&output);
183 CPPUNIT_ASSERT(output.str() == "# 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\n0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t-\t0\tH\t-\t-\t-\t0\t0\t0\t0\t0\t0\t0\t0\t-\t\n");
184
185 cout << "testing the tremolo parser is done" << endl;
186}
Note: See TracBrowser for help on using the repository browser.