source: src/unittests/DescriptorUnittest.cpp@ e6fdbe

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 e6fdbe was 9b6b2f, checked in by Frederik Heber <heber@…>, 15 years ago

Tests now work with Eclipse ECUT's TestRunner.

  • new switch in configure.ac: --enable-ecut
  • all tests are compiled as single test as before
  • and a new TestRunner test suite that combines all test into a single executable which can be run as CppUnit program in Eclipse (and then gives JUnit like output).
  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 * DescriptorUnittest.cpp
3 *
4 * Created on: Feb 9, 2010
5 * Author: crueger
6 */
7
8#include "DescriptorUnittest.hpp"
9
10#include <cppunit/CompilerOutputter.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12#include <cppunit/ui/text/TestRunner.h>
13#include <iostream>
14
15#include <Descriptors/AtomDescriptor.hpp>
16#include <Descriptors/AtomIdDescriptor.hpp>
17
18#include "World.hpp"
19#include "atom.hpp"
20
21#ifdef HAVE_TESTRUNNER
22#include "UnitTestMain.hpp"
23#endif /*HAVE_TESTRUNNER*/
24
25/********************************************** Test classes **************************************/
26// Registers the fixture into the 'registry'
27CPPUNIT_TEST_SUITE_REGISTRATION( DescriptorUnittest );
28
29// some stubs
30class AtomStub : public atom {
31public:
32 AtomStub(int _id) :
33 atom(),
34 id(_id)
35 {}
36
37 virtual int getId(){
38 return id;
39 }
40
41private:
42 int id;
43};
44
45
46// set up and tear down
47void DescriptorUnittest::setUp(){
48 World::get();
49 for(int i=0;i<ATOM_COUNT;++i){
50 atoms[i]= new AtomStub(i);
51 }
52}
53void DescriptorUnittest::tearDown(){
54 World::destroy();
55 for(int i=0;i<ATOM_COUNT;++i){
56 delete atoms[i];
57 }
58}
59
60// some helper functions
61bool hasAll(std::vector<atom*> atoms,int min, int max, std::set<int> excluded = std::set<int>()){
62 for(int i=min;i<max;++i){
63 if(!excluded.count(i)){
64 std::vector<atom*>::iterator iter;
65 bool res=false;
66 for(iter=atoms.begin();iter!=atoms.end();++iter){
67 res |= (*iter)->getId() == i;
68 }
69 if(!res) {
70 cout << "Atom " << i << " missing in returned list" << endl;
71 return false;
72 }
73 }
74 }
75 return true;
76}
77
78bool hasNoDuplicates(std::vector<atom*> atoms){
79 std::set<int> found;
80 std::vector<atom*>::iterator iter;
81 for(iter=atoms.begin();iter!=atoms.end();++iter){
82 int id = (*iter)->getId();
83 if(found.count(id))
84 return false;
85 found.insert(id);
86 }
87 return true;
88}
89
90
91void DescriptorUnittest::AtomBaseSetsTest(){
92 std::vector<atom*> allAtoms = World::get()->getAllAtoms(AllAtoms());
93 CPPUNIT_ASSERT_EQUAL( true , hasAll(allAtoms,0,ATOM_COUNT));
94 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(allAtoms));
95
96 std::vector<atom*> noAtoms = World::get()->getAllAtoms(NoAtoms());
97 CPPUNIT_ASSERT_EQUAL( true , noAtoms.empty());
98}
99void DescriptorUnittest::AtomIdTest(){
100 // test Atoms from boundaries and middle of the set
101 atom* testAtom;
102 testAtom = World::get()->getAtom(AtomById(0));
103 CPPUNIT_ASSERT_EQUAL( 0, testAtom->getId());
104 testAtom = World::get()->getAtom(AtomById(ATOM_COUNT/2));
105 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtom->getId());
106 testAtom = World::get()->getAtom(AtomById(ATOM_COUNT-1));
107 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT-1, testAtom->getId());
108
109 // test from outside of set
110 testAtom = World::get()->getAtom(AtomById(ATOM_COUNT));
111 CPPUNIT_ASSERT(!testAtom);
112}
113void DescriptorUnittest::AtomCalcTest(){
114 // test some elementary set operations
115 {
116 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()||NoAtoms());
117 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT));
118 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
119 }
120
121 {
122 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||AllAtoms());
123 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT));
124 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
125 }
126
127 {
128 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()&&AllAtoms());
129 CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
130 }
131
132 {
133 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&NoAtoms());
134 CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
135 }
136
137 {
138 std::vector<atom*> testAtoms = World::get()->getAllAtoms(!AllAtoms());
139 CPPUNIT_ASSERT_EQUAL( true , testAtoms.empty());
140 }
141
142 {
143 std::vector<atom*> testAtoms = World::get()->getAllAtoms(!NoAtoms());
144 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT));
145 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
146 }
147
148 // exclude and include some atoms
149 {
150 std::vector<atom*> testAtoms = World::get()->getAllAtoms(AllAtoms()&&(!AtomById(ATOM_COUNT/2)));
151 std::set<int> excluded;
152 excluded.insert(ATOM_COUNT/2);
153 CPPUNIT_ASSERT_EQUAL( true , hasAll(testAtoms,0,ATOM_COUNT,excluded));
154 CPPUNIT_ASSERT_EQUAL( true , hasNoDuplicates(testAtoms));
155 CPPUNIT_ASSERT_EQUAL( (size_t)(ATOM_COUNT-1), testAtoms.size());
156 }
157
158 {
159 std::vector<atom*> testAtoms = World::get()->getAllAtoms(NoAtoms()||(AtomById(ATOM_COUNT/2)));
160 CPPUNIT_ASSERT_EQUAL( (size_t)1, testAtoms.size());
161 CPPUNIT_ASSERT_EQUAL( ATOM_COUNT/2, testAtoms[0]->getId());
162 }
163}
Note: See TracBrowser for help on using the repository browser.