source: src/unittests/ParserUnitTest.cpp@ 43dad6

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 43dad6 was 4eb4fe, checked in by Frederik Heber <heber@…>, 15 years ago

"-e <db path>" not necessary anymore.

Removed necessity of specifying path to databases (this was one check of molecuilder/test/testsuite.at which cannot be fulfilled anymore with boost::program_options)
For this to work a great number of small changes have been necessary:

class periodentafel:

  • all .db files merged into const char * arrays in elements_db.cpp
  • periodentafel rewritten:
  • FindElement(), AskElement() and EnterElement return element * const instead of const element * (i.e. the contents of the pointer is const (the element) not the pointer itself which is very vexatious (i.e. FindElement() yields const element * which can subsequently not be used for RemoveElement(), ...)
  • parsedElems is not needed anymore. Instead we operate on map elements directly
  • new unittest periodentafelTest which is made friend of periodentafel to be able to access private loading functions directly

A number of unit tests had to be changed (all that create elements during setUp() which is now unnecessary)

Some of the analysis_bonds function's signatures were changed in the process:

Finally, the respective tests are removed from molecuilder/tests/testsuite.at.

  • Property mode set to 100644
File size: 5.6 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 World::getInstance();
34}
35
36void ParserUnitTest::tearDown() {
37 World::purgeInstance();
38}
39
40/************************************ tests ***********************************/
41
42void ParserUnitTest::rewriteAnXyzTest() {
43 cout << "Testing the XYZ parser." << endl;
44 XyzParser* testParser = new XyzParser();
45 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";
46 stringstream input;
47 input << waterXyz;
48 testParser->load(&input);
49
50 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
51
52 string newWaterXyz = "";
53 stringstream output;
54 testParser->save(&output);
55 newWaterXyz = output.str();
56
57 CPPUNIT_ASSERT(waterXyz == newWaterXyz);
58}
59
60void ParserUnitTest::readTremoloPreliminaryCommentsTest() {
61 cout << "Testing the tremolo parser." << endl;
62 TremoloParser* testParser = new TremoloParser();
63 stringstream input, output;
64 string waterTremolo;
65
66 // Atomdata beginning with "# ATOMDATA"
67 waterTremolo = "# ATOMDATA\tId\tname\tType\tx=3\n";
68 input << waterTremolo;
69 testParser->load(&input);
70 testParser->save(&output);
71 CPPUNIT_ASSERT(waterTremolo == output.str());
72 input.clear();
73 output.clear();
74
75 // Atomdata beginning with "#ATOMDATA"
76 waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
77 input << waterTremolo;
78 testParser->load(&input);
79 testParser->save(&output);
80 CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
81 input.clear();
82 output.clear();
83
84 // Invalid key in Atomdata line
85 waterTremolo = "#\n#ATOMDATA Id name foo Type x=3\n\n\n";
86 input << waterTremolo;
87 testParser->load(&input);
88 //TODO: proove invalidity
89 input.clear();
90}
91
92void ParserUnitTest::readTremoloCoordinatesTest() {
93 TremoloParser* testParser = new TremoloParser();
94 stringstream input;
95 string waterTremolo;
96
97 // One simple data line
98 waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
99 input << waterTremolo;
100 testParser->load(&input);
101 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->x[0] == 3.0);
102 input.clear();
103}
104
105void ParserUnitTest::readTremoloVelocityTest() {
106 TremoloParser* testParser = new TremoloParser();
107 stringstream input;
108 string waterTremolo;
109
110 // One simple data line
111 waterTremolo = "#\n#ATOMDATA Id name Type u=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
112 input << waterTremolo;
113 testParser->load(&input);
114 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->v[0] == 3.0);
115 input.clear();
116}
117
118void ParserUnitTest::readTremoloNeighborInformationTest() {
119 TremoloParser* testParser = new TremoloParser();
120 stringstream input;
121 string waterTremolo;
122
123 // Neighbor data
124 waterTremolo = "#\n#ATOMDATA Id Type neighbors=2\n1 H 3 0\n2 H 3 0\n3 O 1 2\n";
125 input << waterTremolo;
126 testParser->load(&input);
127
128 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
129 CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
130 IsBondedTo(World::getInstance().getAtom(AtomByType(1))));
131 input.clear();
132}
133
134void ParserUnitTest::readAndWriteTremoloImprDataInformationTest() {
135 TremoloParser* testParser = new TremoloParser();
136 stringstream input, output;
137 string waterTremolo;
138
139 // Neighbor data
140 waterTremolo = "#\n#ATOMDATA Id Type imprData\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n";
141 input << waterTremolo;
142 testParser->load(&input);
143 testParser->save(&output);
144 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
145 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
146 input.clear();
147 output.clear();
148}
149
150void ParserUnitTest::readAndWriteTremoloTorsionInformationTest() {
151 TremoloParser* testParser = new TremoloParser();
152 stringstream input, output;
153 string waterTremolo;
154
155 // Neighbor data
156 waterTremolo = "#\n#ATOMDATA Id Type torsion\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n";
157 input << waterTremolo;
158 testParser->load(&input);
159 testParser->save(&output);
160 CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
161 CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
162 input.clear();
163 output.clear();
164}
165
166void ParserUnitTest::writeTremoloTest() {
167 TremoloParser* testParser = new TremoloParser();
168 stringstream output;
169
170 // with the maximum number of fields and minimal information, default values are printed
171 atom* newAtom = World::getInstance().createAtom();
172 newAtom->type = World::getInstance().getPeriode()->FindElement(1);
173 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");
174 testParser->save(&output);
175 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");
176
177 cout << "testing the tremolo parser is done" << endl;
178}
Note: See TracBrowser for help on using the repository browser.