source: src/unittests/FormulaUnitTest.cpp@ 343c5a

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 343c5a was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 10.9 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * FormulaUnitTest.cpp
25 *
26 * Created on: Jul 21, 2010
27 * Author: crueger
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include <cppunit/CompilerOutputter.h>
36#include <cppunit/extensions/TestFactoryRegistry.h>
37#include <cppunit/ui/text/TestRunner.h>
38
39#include <iostream>
40
41#include "Formula.hpp"
42#include "World.hpp"
43
44#include "FormulaUnitTest.hpp"
45
46#ifdef HAVE_TESTRUNNER
47#include "UnitTestMain.hpp"
48#endif /*HAVE_TESTRUNNER*/
49
50CPPUNIT_TEST_SUITE_REGISTRATION( FormulaUnittest );
51
52void FormulaUnittest::setUp()
53{
54 // failing asserts should be thrown
55 ASSERT_DO(Assert::Throw);
56}
57
58void FormulaUnittest::tearDown()
59{
60 World::purgeInstance();
61}
62
63void FormulaUnittest::baseTest(){
64 Formula formula;
65 CPPUNIT_ASSERT_EQUAL(formula.getElementCount(),(unsigned int)0);
66 CPPUNIT_ASSERT(formula.begin()==formula.end());
67
68 // test some one letter element names
69 formula += "H";
70 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)1);
71 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)0);
72 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
73 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
74 CPPUNIT_ASSERT_EQUAL(formula.getElementCount(),(unsigned int)1);
75 CPPUNIT_ASSERT(formula.begin()!=formula.end());
76 formula += "H";
77 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)2);
78 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)0);
79 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
80 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
81 CPPUNIT_ASSERT_EQUAL(formula.getElementCount(),(unsigned int)1);
82 CPPUNIT_ASSERT(formula.begin()!=formula.end());
83 formula += "O";
84 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)2);
85 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)1);
86 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
87 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
88 CPPUNIT_ASSERT_EQUAL(formula.getElementCount(),(unsigned int)2);
89 CPPUNIT_ASSERT(formula.begin()!=formula.end());
90
91 // test copy constructor
92 Formula formula2=formula;
93 CPPUNIT_ASSERT_EQUAL(formula2["H"],(unsigned int)2);
94 CPPUNIT_ASSERT_EQUAL(formula2["O"],(unsigned int)1);
95 CPPUNIT_ASSERT_EQUAL(formula2["C"],(unsigned int)0);
96 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
97 CPPUNIT_ASSERT_EQUAL(formula2.getElementCount(),(unsigned int)2);
98 CPPUNIT_ASSERT(formula2.begin()!=formula2.end());
99
100 // test Assignment operator
101 formula2=Formula();
102 CPPUNIT_ASSERT_EQUAL(formula2["H"],(unsigned int)0);
103 CPPUNIT_ASSERT_EQUAL(formula2["O"],(unsigned int)0);
104 CPPUNIT_ASSERT_EQUAL(formula2["C"],(unsigned int)0);
105 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
106 CPPUNIT_ASSERT_EQUAL(formula2.getElementCount(),(unsigned int)0);
107 CPPUNIT_ASSERT(formula2.begin()==formula2.end());
108
109 // test comparison
110 CPPUNIT_ASSERT(formula!=formula2);
111 Formula formula3;
112 formula3 += "H";
113 formula3 += "H";
114 formula3 += "O";
115 CPPUNIT_ASSERT(formula==formula3);
116
117 // inequality
118 formula3 += "O";
119 CPPUNIT_ASSERT(formula!=formula3);
120
121 // after removing it should be fine again
122 formula3 -= "O";
123 CPPUNIT_ASSERT(formula==formula3);
124
125 // add something from the far end, to test resizing
126 formula3 += "Rh";
127 CPPUNIT_ASSERT(formula!=formula3);
128 formula3 -= "Rh";
129 CPPUNIT_ASSERT(formula==formula3);
130
131 // removal of elements
132 formula -= "H";
133 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)1);
134 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)1);
135 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
136 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
137 CPPUNIT_ASSERT_EQUAL(formula.getElementCount(),(unsigned int)2);
138 CPPUNIT_ASSERT(formula.begin()!=formula.end());
139
140 formula -= "O";
141 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)1);
142 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)0);
143 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
144 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
145 CPPUNIT_ASSERT_EQUAL(formula.getElementCount(),(unsigned int)1);
146 CPPUNIT_ASSERT(formula.begin()!=formula.end());
147
148 formula -= "H";
149 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)0);
150 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)0);
151 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
152 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
153 CPPUNIT_ASSERT_EQUAL(formula.getElementCount(),(unsigned int)0);
154 CPPUNIT_ASSERT(formula.begin()==formula.end());
155}
156
157void FormulaUnittest::parseTest(){
158 {
159 Formula formula("");
160 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)0);
161 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)0);
162 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
163 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
164 }
165 {
166 Formula formula("H");
167 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)1);
168 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)0);
169 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
170 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
171 }
172 {
173 Formula formula("H2");
174 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)2);
175 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)0);
176 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
177 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
178 }
179 {
180 Formula formula("H2O");
181 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)2);
182 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)1);
183 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
184 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
185 }
186 {
187 Formula formula("CH3COOH");
188 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)4);
189 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)2);
190 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)2);
191 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
192 }
193 {
194 Formula formula("CH3COONa");
195 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)3);
196 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)2);
197 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)2);
198 CPPUNIT_ASSERT_EQUAL(formula["Na"],(unsigned int)1);
199 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
200 }
201 {
202 Formula formula("NaCH3COO");
203 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)3);
204 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)2);
205 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)2);
206 CPPUNIT_ASSERT_EQUAL(formula["Na"],(unsigned int)1);
207 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
208 }
209 {
210 Formula formula("Na2CO3");
211 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)0);
212 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)3);
213 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)1);
214 CPPUNIT_ASSERT_EQUAL(formula["Na"],(unsigned int)2);
215 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
216 }
217 {
218 Formula formula("CH2(COOH)2");
219 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)4);
220 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)4);
221 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)3);
222 CPPUNIT_ASSERT_EQUAL(formula["Na"],(unsigned int)0);
223 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
224 }
225 {
226 Formula formula("K4[Fe(CN)6]");
227 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)0);
228 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)0);
229 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)6);
230 CPPUNIT_ASSERT_EQUAL(formula["Na"],(unsigned int)0);
231 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
232 CPPUNIT_ASSERT_EQUAL(formula["K"],(unsigned int)4);
233 CPPUNIT_ASSERT_EQUAL(formula["Fe"],(unsigned int)1);
234 CPPUNIT_ASSERT_EQUAL(formula["N"],(unsigned int)6);
235 }
236 {
237 Formula formula("[CrCl3(H2O)3]");
238 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)6);
239 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)3);
240 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)0);
241 CPPUNIT_ASSERT_EQUAL(formula["Na"],(unsigned int)0);
242 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
243 CPPUNIT_ASSERT_EQUAL(formula["Cr"],(unsigned int)1);
244 CPPUNIT_ASSERT_EQUAL(formula["Cl"],(unsigned int)3);
245 }
246 {
247 Formula formula("Mg3[Fe(CN)6]2");
248 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)0);
249 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)0);
250 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)12);
251 CPPUNIT_ASSERT_EQUAL(formula["Na"],(unsigned int)0);
252 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
253 CPPUNIT_ASSERT_EQUAL(formula["Mg"],(unsigned int)3);
254 CPPUNIT_ASSERT_EQUAL(formula["Fe"],(unsigned int)2);
255 CPPUNIT_ASSERT_EQUAL(formula["N"],(unsigned int)12);
256 }
257 {
258 Formula formula("Na[Fe((HO2CCH2)2NCH2CH2N(CH2CO2H)2)]");
259 CPPUNIT_ASSERT_EQUAL(formula["H"],(unsigned int)16);
260 CPPUNIT_ASSERT_EQUAL(formula["O"],(unsigned int)8);
261 CPPUNIT_ASSERT_EQUAL(formula["C"],(unsigned int)10);
262 CPPUNIT_ASSERT_EQUAL(formula["Na"],(unsigned int)1);
263 CPPUNIT_ASSERT_EQUAL(formula["He"],(unsigned int)0);
264 CPPUNIT_ASSERT_EQUAL(formula["Mg"],(unsigned int)0);
265 CPPUNIT_ASSERT_EQUAL(formula["Fe"],(unsigned int)1);
266 CPPUNIT_ASSERT_EQUAL(formula["N"],(unsigned int)2);
267 }
268 {
269 CPPUNIT_ASSERT_THROW(Formula formula("74107"),FormulaStringParseException);
270 CPPUNIT_ASSERT_THROW(Formula formula(" "),FormulaStringParseException);
271 CPPUNIT_ASSERT_THROW(Formula formula("nAcL"),FormulaStringParseException);
272 CPPUNIT_ASSERT_THROW(Formula formula("NAcL"),FormulaStringParseException);
273 CPPUNIT_ASSERT_THROW(Formula formula("Na Cl"),FormulaStringParseException);
274 CPPUNIT_ASSERT_THROW(Formula formula("1NaCl"),FormulaStringParseException);
275 CPPUNIT_ASSERT_THROW(Formula formula("Mag"),FormulaStringParseException);
276 CPPUNIT_ASSERT_THROW(Formula formula("AgCl)"),FormulaStringParseException);
277 CPPUNIT_ASSERT_THROW(Formula formula("(Na"),FormulaStringParseException);
278 CPPUNIT_ASSERT_THROW(Formula formula("(Mag)"),FormulaStringParseException);
279 CPPUNIT_ASSERT_THROW(Formula formula("MgCl2)"),FormulaStringParseException);
280 CPPUNIT_ASSERT_THROW(Formula formula("((MgCl2)"),FormulaStringParseException);
281 CPPUNIT_ASSERT_THROW(Formula formula("(MgCl2))"),FormulaStringParseException);
282 CPPUNIT_ASSERT_THROW(Formula formula("(MgCl2]"),FormulaStringParseException);
283 CPPUNIT_ASSERT_THROW(Formula formula("[MgCl2)"),FormulaStringParseException);
284 CPPUNIT_ASSERT_THROW(Formula formula("N(aCl"),FormulaStringParseException);
285 CPPUNIT_ASSERT_THROW(Formula formula("Na()Cl"),FormulaStringParseException);
286 }
287
288
289}
Note: See TracBrowser for help on using the repository browser.