source: src/Atom/unittests/CopyAtomsInterfaceUnitTest.cpp@ 78ad7d

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 78ad7d was 9e1d01, checked in by Frederik Heber <heber@…>, 13 years ago

Added CopyAtoms structure.

  • this creates a copy of a vector of atoms with as much depth as desired by the user.
  • this is a hierarchy of functors that each add additional functionality such as also re-creating the bonds, ...
  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 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 * CopyAtomsInterfaceUnitTest.cpp
10 *
11 * Created on: Mar 17, 2012
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CopyAtomsInterfaceUnitTest.hpp"
21
22#include <cppunit/CompilerOutputter.h>
23#include <cppunit/extensions/TestFactoryRegistry.h>
24#include <cppunit/ui/text/TestRunner.h>
25#include <iostream>
26
27#include "CodePatterns/Log.hpp"
28
29#include "Atom/atom.hpp"
30#include "Atom/CopyAtoms/CopyAtomsInterface.hpp"
31#include "Atom/CopyAtoms/CopyAtoms_Simple.hpp"
32#include "Atom/CopyAtoms/CopyAtoms_withBonds.hpp"
33#include "Bond/bond.hpp"
34#include "World.hpp"
35
36#ifdef HAVE_TESTRUNNER
37#include "UnitTestMain.hpp"
38#endif /*HAVE_TESTRUNNER*/
39
40/********************************************** Test classes **************************************/
41// Registers the fixture into the 'registry'
42CPPUNIT_TEST_SUITE_REGISTRATION( CopyAtomsInterfaceTest );
43
44// set up and tear down
45void CopyAtomsInterfaceTest::setUp()
46{
47 setVerbosity(5);
48
49 for(int i=0;i<ATOM_COUNT;++i){
50 atoms[i]= World::getInstance().createAtom();
51 atomIds[i]= atoms[i]->getId();
52 }
53}
54
55void CopyAtomsInterfaceTest::tearDown()
56{
57 World::purgeInstance();
58}
59
60/** Unit test on whether CopyAtomsInterface::operator() works as expected.
61 *
62 */
63void CopyAtomsInterfaceTest::CopyAtomsInterfaceOperatorTest()
64{
65 CopyAtomsInterface copyMethod;
66 CopyAtomsInterface::AtomVector atomVec(atoms, atoms+ATOM_COUNT);
67
68 copyMethod(atomVec);
69
70 CPPUNIT_ASSERT_EQUAL( (size_t)2, World::getInstance().getAllAtoms().size() );
71 CPPUNIT_ASSERT_EQUAL( (size_t)2, atomVec.size() );
72 CPPUNIT_ASSERT_EQUAL( (size_t)2, copyMethod.CopiedAtoms.size() );
73 CPPUNIT_ASSERT_EQUAL( (atom *) NULL, copyMethod.CopiedAtoms[0] );
74}
75
76/** Unit test on whether CopyAtoms_Simple::operator() works as expected.
77 *
78 */
79void CopyAtomsInterfaceTest::CopyAtoms_SimpleOperatorTest()
80{
81 CopyAtoms_Simple copyMethod;
82 CopyAtomsInterface::AtomVector atomVec(atoms, atoms+ATOM_COUNT);
83
84 copyMethod(atomVec);
85
86 CPPUNIT_ASSERT_EQUAL( (size_t)4, World::getInstance().getAllAtoms().size() );
87 CPPUNIT_ASSERT_EQUAL( (size_t)2, atomVec.size() );
88 CPPUNIT_ASSERT_EQUAL( (size_t)2, copyMethod.CopiedAtoms.size() );
89 CPPUNIT_ASSERT( copyMethod.CopiedAtoms[0] != NULL );
90}
91
92/** Unit test on whether CopyAtoms_withBonds::operator() works as expected.
93 *
94 */
95void CopyAtomsInterfaceTest::CopyAtoms_withBondsOperatorTest()
96{
97 CopyAtoms_withBonds copyMethod;
98 {
99 CopyAtomsInterface::AtomVector atomVec(atoms, atoms+ATOM_COUNT);
100 CPPUNIT_ASSERT_EQUAL( (size_t)2, atomVec.size() );
101
102 copyMethod(atomVec);
103
104 CPPUNIT_ASSERT_EQUAL( (size_t)4, World::getInstance().getAllAtoms().size() );
105 CPPUNIT_ASSERT_EQUAL( (size_t)2, copyMethod.CopiedAtoms.size() );
106 CPPUNIT_ASSERT( copyMethod.CopiedAtoms[0] != NULL );
107 CPPUNIT_ASSERT( copyMethod.CopiedAtoms[1] != NULL );
108 CPPUNIT_ASSERT_EQUAL( copyMethod.CopiedAtoms, copyMethod.getCopiedAtoms() );
109 }
110
111 // create bonds
112 {
113 atoms[0]->addBond( (size_t)0, atoms[1]);
114 const BondList & ListOfBonds = atoms[0]->getListOfBonds();
115 CPPUNIT_ASSERT( !ListOfBonds.empty() );
116 const bond * const _bond = *ListOfBonds.begin();
117 CPPUNIT_ASSERT( _bond->GetOtherAtom(atoms[0]) == atoms[1] );
118 }
119 {
120 CopyAtomsInterface::AtomVector atomVec(atoms, atoms+ATOM_COUNT);
121 CPPUNIT_ASSERT_EQUAL( (size_t)2, atomVec.size() );
122
123 copyMethod(atomVec);
124
125 CPPUNIT_ASSERT_EQUAL( (size_t)6, World::getInstance().getAllAtoms().size() );
126 CPPUNIT_ASSERT_EQUAL( (size_t)2, copyMethod.CopiedAtoms.size() );
127 CPPUNIT_ASSERT( copyMethod.CopiedAtoms[0] != NULL );
128 CPPUNIT_ASSERT( copyMethod.CopiedAtoms[1] != NULL );
129 const BondList & ListOfBonds = copyMethod.CopiedAtoms[0]->getListOfBonds();
130 CPPUNIT_ASSERT( !ListOfBonds.empty() );
131 const bond * const _bond = *ListOfBonds.begin();
132 CPPUNIT_ASSERT( _bond->GetOtherAtom(copyMethod.CopiedAtoms[0]) == copyMethod.CopiedAtoms[1] );
133 }
134}
135
136
Note: See TracBrowser for help on using the repository browser.