Changeset be97a8 for src/unittests


Ignore:
Timestamp:
Jul 20, 2010, 1:01:11 PM (15 years ago)
Author:
Frederik Heber <heber@…>
Branches:
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
Children:
3d078d, 4b6777, c644a5
Parents:
ba9f5b (diff), 818eda (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'StructureRefactoring' into stable

Conflicts:

test_all.sh

  • test_all.sh was modified by Till in StructureRefactoring (these changes taken over).
  • World::setDomain() was missing OBSERVE macro.
  • MapOfActions: "molecule-by-name" needs String not Molecule.
  • TESTFIX: Tesselations/defs.in - paths changed such that @srcdir@ may be absolute.
  • TESTFIX: Tesselations/heptan/1.5/NonConvexEnvelope.dat - exchanged due to same surface but different polygon triangulation.
  • TESTFIX: Domain/4 molecule-by-id changed from 208 to 207 due to different handling of molecule ids.
Location:
src/unittests
Files:
4 added
11 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/ActOnAllUnitTest.cpp

    rba9f5b rbe97a8  
    1414#include "../test/ActOnAlltest.hpp"
    1515#include "ActOnAllUnitTest.hpp"
    16 #include "memoryallocator.hpp"
    1716#include "vector.hpp"
    1817
  • src/unittests/LineUnittest.cpp

    rba9f5b rbe97a8  
    1717
    1818#include <iostream>
     19#include <cmath>
    1920
    2021using namespace std;
     
    352353  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
    353354}
     355
     356void LineUnittest::sphereIntersectionTest(){
     357  {
     358    std::vector<Vector> res = la1->getSphereIntersections();
     359    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
     360    CPPUNIT_ASSERT(testDirection(res[0],e1));
     361    CPPUNIT_ASSERT(testDirection(res[1],e1));
     362    CPPUNIT_ASSERT(res[0]!=res[1]);
     363  }
     364
     365  {
     366    std::vector<Vector> res = la2->getSphereIntersections();
     367    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
     368    CPPUNIT_ASSERT(testDirection(res[0],e2));
     369    CPPUNIT_ASSERT(testDirection(res[1],e2));
     370    CPPUNIT_ASSERT(res[0]!=res[1]);
     371  }
     372
     373  {
     374    std::vector<Vector> res = la3->getSphereIntersections();
     375    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
     376    CPPUNIT_ASSERT(testDirection(res[0],e3));
     377    CPPUNIT_ASSERT(testDirection(res[1],e3));
     378    CPPUNIT_ASSERT(res[0]!=res[1]);
     379  }
     380
     381  {
     382    std::vector<Vector> res = lp1->getSphereIntersections();
     383    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
     384    CPPUNIT_ASSERT((res[0]==e1) || (res[0]==e2));
     385    CPPUNIT_ASSERT((res[1]==e1) || (res[1]==e2));
     386    CPPUNIT_ASSERT(res[0]!=res[1]);
     387  }
     388
     389  {
     390    std::vector<Vector> res = lp2->getSphereIntersections();
     391    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
     392    CPPUNIT_ASSERT((res[0]==e2) || (res[0]==e3));
     393    CPPUNIT_ASSERT((res[1]==e2) || (res[1]==e3));
     394    CPPUNIT_ASSERT(res[0]!=res[1]);
     395  }
     396
     397  {
     398    std::vector<Vector> res = lp3->getSphereIntersections();
     399    CPPUNIT_ASSERT_EQUAL(res.size(),(size_t)2);
     400    CPPUNIT_ASSERT((res[0]==e3) || (res[0]==e1));
     401    CPPUNIT_ASSERT((res[1]==e3) || (res[1]==e1));
     402    CPPUNIT_ASSERT(res[0]!=res[1]);
     403  }
     404}
  • src/unittests/LineUnittest.hpp

    rba9f5b rbe97a8  
    2222  CPPUNIT_TEST ( intersectionTest );
    2323  CPPUNIT_TEST ( rotationTest );
     24  CPPUNIT_TEST ( sphereIntersectionTest );
    2425  CPPUNIT_TEST_SUITE_END();
    2526
     
    3334  void intersectionTest();
    3435  void rotationTest();
     36  void sphereIntersectionTest();
    3537
    3638private:
  • src/unittests/Makefile.am

    rba9f5b rbe97a8  
    3131  LogUnitTest \
    3232  manipulateAtomsTest \
    33   MemoryUsageObserverUnitTest \
    34   MemoryAllocatorUnitTest \
     33  MatrixUnittest \
    3534  MoleculeDescriptorTest \
    3635  ObserverTest \
     
    3837  periodentafelTest \
    3938  PlaneUnittest \
     39  ShapeUnittest \
    4040  SingletonTest \
    4141  StackClassUnitTest \
     
    7575  listofbondsunittest.cpp \
    7676  logunittest.cpp \
     77  MatrixUnittest.cpp \
    7778  manipulateAtomsTest.cpp \
    78   memoryallocatorunittest.cpp  \
    79   memoryusageobserverunittest.cpp \
    8079  MoleculeDescriptorTest.cpp \
    8180  ObserverTest.cpp \
     
    8382  periodentafelTest.cpp \
    8483  PlaneUnittest.cpp \
     84  ShapeUnittest.cpp \
    8585  SingletonTest.cpp \
    8686  stackclassunittest.cpp \
     
    112112  logunittest.hpp \
    113113  manipulateAtomsTest.hpp \
    114   memoryallocatorunittest.hpp  \
    115   memoryusageobserverunittest.hpp \
     114  MatrixUnittest.hpp \
    116115  MoleculeDescriptorTest.hpp \
    117116  periodentafelTest.hpp \
     
    189188manipulateAtomsTest_LDADD = ${ALLLIBS}
    190189
    191 MemoryAllocatorUnitTest_SOURCES = UnitTestMain.cpp ../memoryallocator.hpp ../memoryallocator.cpp ../memoryusageobserver.cpp ../memoryusageobserver.hpp memoryallocatorunittest.cpp memoryallocatorunittest.hpp
    192 MemoryAllocatorUnitTest_LDADD = ${ALLLIBS}
    193 
    194 MemoryUsageObserverUnitTest_SOURCES = UnitTestMain.cpp ../memoryallocator.hpp ../memoryusageobserver.cpp ../memoryusageobserver.hpp memoryusageobserverunittest.cpp memoryusageobserverunittest.hpp
    195 MemoryUsageObserverUnitTest_LDADD = ${ALLLIBS}
     190MatrixUnittest_SOURCES = UnitTestMain.cpp MatrixUnittest.cpp MatrixUnittest.hpp
     191MatrixUnittest_LDADD = ${ALLLIBS}
    196192
    197193MoleculeDescriptorTest_SOURCES = UnitTestMain.cpp MoleculeDescriptorTest.cpp MoleculeDescriptorTest.hpp
     
    210206PlaneUnittest_LDADD = ${ALLLIBS}
    211207
     208ShapeUnittest_SOURCES = UnitTestMain.cpp ShapeUnittest.cpp ShapeUnittest.hpp
     209ShapeUnittest_LDADD = ${ALLLIBS}
     210
    212211SingletonTest_SOURCES = UnitTestMain.cpp SingletonTest.cpp SingletonTest.hpp
    213212SingletonTest_LDADD = ${ALLLIBS} $(BOOST_LIB) ${BOOST_THREAD_LIB}
     
    225224Tesselation_InOutsideUnitTest_LDADD = ${ALLLIBS}
    226225
    227 TestRunner_SOURCES = TestRunnerMain.cpp ../memoryallocator.hpp ../memoryallocator.cpp ../memoryusageobserver.cpp ../memoryusageobserver.hpp $(TESTSOURCES) $(TESTHEADERS)
     226TestRunner_SOURCES = TestRunnerMain.cpp $(TESTSOURCES) $(TESTHEADERS)
    228227TestRunner_LDADD = ${ALLLIBS}
    229228
  • src/unittests/ObserverTest.cpp

    rba9f5b rbe97a8  
    182182};
    183183
    184 class ObservableCollection : public Observable {
     184class ObservableSet : public Observable {
    185185public:
    186186  typedef std::set<SimpleObservable*> set;
     
    188188  typedef set::const_iterator const_iterator;
    189189
    190   ObservableCollection(int _num) :
     190  ObservableSet(int _num) :
    191191    Observable("ObservableCollection"),
    192192    num(_num)
     
    199199  }
    200200
    201   ~ObservableCollection(){
     201  ~ObservableSet(){
    202202    set::iterator iter;
    203203    for(iter=theSet.begin(); iter!=theSet.end(); ++iter ){
    204204      delete (*iter);
     205    }
     206  }
     207
     208  iterator begin(){
     209    return iterator(theSet.begin(),this);
     210  }
     211
     212  iterator end(){
     213    return iterator(theSet.end(),this);
     214  }
     215
     216  const int num;
     217
     218private:
     219  set theSet;
     220};
     221
     222class ObservableMap : public Observable {
     223public:
     224  typedef std::map<int,SimpleObservable*> set;
     225  typedef ObservedIterator<set> iterator;
     226  typedef set::const_iterator const_iterator;
     227
     228  ObservableMap(int _num) :
     229    Observable("ObservableCollection"),
     230    num(_num)
     231  {
     232    for(int i=0; i<num; ++i){
     233      SimpleObservable *content = new SimpleObservable();
     234      content->signOn(this);
     235      theSet.insert(make_pair(i,content));
     236    }
     237  }
     238
     239  ~ObservableMap(){
     240    set::iterator iter;
     241    for(iter=theSet.begin(); iter!=theSet.end(); ++iter ){
     242      delete iter->second;
    205243    }
    206244  }
     
    231269  blockObservable = new BlockObservable();
    232270  notificationObservable = new NotificationObservable();
    233   collection = new ObservableCollection(5);
     271  obsset = new ObservableSet(5);
     272  obsmap = new ObservableMap(5);
    234273
    235274  observer1 = new UpdateCountObserver();
     
    249288  delete blockObservable;
    250289  delete notificationObservable;
    251   delete collection;
     290  delete obsset;
     291  delete obsmap;
    252292
    253293  delete observer1;
     
    268308  simpleObservable2->signOn(observer4);
    269309
     310  CPPUNIT_ASSERT_EQUAL( 0, observer1->updates );
     311  CPPUNIT_ASSERT_EQUAL( 0, observer2->updates );
     312  CPPUNIT_ASSERT_EQUAL( 0, observer3->updates );
     313  CPPUNIT_ASSERT_EQUAL( 0, observer4->updates );
     314
     315
    270316  simpleObservable1->changeMethod();
    271317  CPPUNIT_ASSERT_EQUAL( 1, observer1->updates );
     
    292338void ObserverTest::doesBlockUpdateTest() {
    293339  callObservable->signOn(observer1);
     340  CPPUNIT_ASSERT_EQUAL( 0, observer1->updates );
    294341
    295342  callObservable->changeMethod1();
     
    311358  CPPUNIT_ASSERT_EQUAL( 2, observer1->updates );
    312359  CPPUNIT_ASSERT_EQUAL( 2, observer2->updates );
     360}
     361
     362void ObserverTest::outsideLockTest(){
     363  callObservable->signOn(observer1);
     364  CPPUNIT_ASSERT_EQUAL( 0, observer1->updates );
     365
     366  {
     367    LOCK_OBSERVABLE(*callObservable);
     368    CPPUNIT_ASSERT_EQUAL( 0, observer1->updates );
     369  }
     370  // lock is gone now, observer should have notified
     371  CPPUNIT_ASSERT_EQUAL( 1, observer1->updates );
    313372}
    314373
     
    341400  int i = 0;
    342401  // test the general iterator methods
    343   for(ObservableCollection::iterator iter=collection->begin(); iter!=collection->end();++iter){
    344     CPPUNIT_ASSERT(i< collection->num);
     402  for(ObservableSet::iterator iter=obsset->begin(); iter!=obsset->end();++iter){
     403    CPPUNIT_ASSERT(i< obsset->num);
    345404    i++;
    346405  }
    347406
    348407  i=0;
    349   for(ObservableCollection::const_iterator iter=collection->begin(); iter!=collection->end();++iter){
    350     CPPUNIT_ASSERT(i<collection->num);
    351     i++;
    352   }
    353 
    354   collection->signOn(observer1);
     408  for(ObservableSet::const_iterator iter=obsset->begin(); iter!=obsset->end();++iter){
     409    CPPUNIT_ASSERT(i<obsset->num);
     410    i++;
     411  }
     412
     413  obsset->signOn(observer1);
    355414  {
    356415    // we construct this out of the loop, so the iterator dies at the end of
    357416    // the scope and not the end of the loop (allows more testing)
    358     ObservableCollection::iterator iter;
    359     for(iter=collection->begin(); iter!=collection->end(); ++iter){
     417    ObservableSet::iterator iter;
     418    for(iter=obsset->begin(); iter!=obsset->end(); ++iter){
    360419      (*iter)->changeMethod();
    361420    }
     
    367426
    368427  // when using a const_iterator no changes should be propagated
    369   for(ObservableCollection::const_iterator iter = collection->begin(); iter!=collection->end();++iter);
     428  for(ObservableSet::const_iterator iter = obsset->begin(); iter!=obsset->end();++iter);
    370429  CPPUNIT_ASSERT_EQUAL( 1, observer1->updates);
    371   collection->signOff(observer1);
     430
     431  // we need to test the operator-> as well
     432  obsmap->signOn(observer2);
     433  {
     434    // we construct this out of the loop, so the iterator dies at the end of
     435    // the scope and not the end of the loop (allows more testing)
     436    ObservableMap::iterator iter;
     437    for(iter=obsmap->begin(); iter!=obsmap->end(); ++iter){
     438      iter->second->changeMethod();
     439    }
     440    // At this point no change should have been propagated
     441    CPPUNIT_ASSERT_EQUAL( 0, observer2->updates);
     442  }
     443  // After the Iterator has died the propagation should take place
     444  CPPUNIT_ASSERT_EQUAL( 1, observer2->updates);
     445
     446
     447  obsset->signOff(observer1);
     448  obsmap->signOff(observer2);
    372449}
    373450
  • src/unittests/ObserverTest.hpp

    rba9f5b rbe97a8  
    1717class CallObservable;
    1818class SuperObservable;
    19 class ObservableCollection;
     19class ObservableSet;
     20class ObservableMap;
    2021class BlockObservable;
    2122class NotificationObservable;
     
    2728  CPPUNIT_TEST ( doesBlockUpdateTest );
    2829  CPPUNIT_TEST ( doesSubObservableTest );
     30  CPPUNIT_TEST ( outsideLockTest );
    2931  CPPUNIT_TEST ( doesNotifyTest );
    3032  CPPUNIT_TEST ( doesReportTest );
     
    4042  void doesBlockUpdateTest();
    4143  void doesSubObservableTest();
     44  void outsideLockTest();
    4245  void doesNotifyTest();
    4346  void doesReportTest();
     
    6063  SuperObservable *superObservable;
    6164  NotificationObservable *notificationObservable;
    62   ObservableCollection *collection;
     65  ObservableSet *obsset;
     66  ObservableMap *obsmap;
    6367
    6468};
  • src/unittests/PlaneUnittest.cpp

    rba9f5b rbe97a8  
    1111#include <cppunit/extensions/TestFactoryRegistry.h>
    1212#include <cppunit/ui/text/TestRunner.h>
     13
     14#include <cmath>
    1315
    1416#ifdef HAVE_TESTRUNNER
  • src/unittests/linearsystemofequationsunittest.cpp

    rba9f5b rbe97a8  
    1212#include <cppunit/extensions/TestFactoryRegistry.h>
    1313#include <cppunit/ui/text/TestRunner.h>
     14#include <cmath>
    1415
    1516#include "linearsystemofequationsunittest.hpp"
  • src/unittests/tesselation_insideoutsideunittest.cpp

    rba9f5b rbe97a8  
    1717#include "tesselation.hpp"
    1818#include "tesselation_insideoutsideunittest.hpp"
     19#include "verbose.hpp"
    1920
    2021#ifdef HAVE_TESTRUNNER
  • src/unittests/vectorunittest.cpp

    rba9f5b rbe97a8  
    1515#include "defs.hpp"
    1616#include "log.hpp"
    17 #include "memoryusageobserver.hpp"
    1817#include "vector.hpp"
    1918#include "vector_ops.hpp"
     
    2120#include "Plane.hpp"
    2221#include "Exceptions/LinearDependenceException.hpp"
     22#include "Matrix.hpp"
    2323
    2424#ifdef HAVE_TESTRUNNER
     
    214214  CPPUNIT_ASSERT(testVector.ScalarProduct(three) < MYEPSILON);
    215215}
    216 
    217 
    218 /**
    219  * UnitTest for Vector::IsInParallelepiped().
    220  */
    221 void VectorTest::IsInParallelepipedTest()
    222 {
    223   double parallelepiped[NDIM*NDIM];
    224   parallelepiped[0] = 1;
    225   parallelepiped[1] = 0;
    226   parallelepiped[2] = 0;
    227   parallelepiped[3] = 0;
    228   parallelepiped[4] = 1;
    229   parallelepiped[5] = 0;
    230   parallelepiped[6] = 0;
    231   parallelepiped[7] = 0;
    232   parallelepiped[8] = 1;
    233 
    234   fixture = zero;
    235   CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    236   fixture = Vector(2.5,2.5,2.5);
    237   CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    238   fixture = Vector(1.,1.,1.);
    239   CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    240   fixture = Vector(3.5,3.5,3.5);
    241   CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    242   fixture = Vector(2.,2.,2.);
    243   CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    244   fixture = Vector(2.,3.,2.);
    245   CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    246   fixture = Vector(-2.,2.,-1.);
    247   CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) );
    248 }
    249 
  • src/unittests/vectorunittest.hpp

    rba9f5b rbe97a8  
    2727    CPPUNIT_TEST ( ProjectionTest );
    2828    CPPUNIT_TEST ( NormalsTest );
    29     CPPUNIT_TEST ( IsInParallelepipedTest );
    3029    CPPUNIT_TEST_SUITE_END();
    3130
     
    4544    void LineIntersectionTest();
    4645    void VectorRotationTest();
    47     void IsInParallelepipedTest();
    4846
    4947private:
Note: See TracChangeset for help on using the changeset viewer.