Changeset 220cf37 for src/unittests


Ignore:
Timestamp:
Nov 7, 2009, 12:25:32 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:
9a7186
Parents:
b9947d
git-author:
Frederik Heber <heber@…> (11/07/09 12:18:56)
git-committer:
Frederik Heber <heber@…> (11/07/09 12:25:32)
Message:

Two new bond analysis functions.

Location:
src/unittests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/analysisbondsunittest.cpp

    rb9947d r220cf37  
    1515#include <stdio.h>
    1616
     17#include "analysis_bonds.hpp"
     18#include "analysisbondsunittest.hpp"
    1719#include "atom.hpp"
    1820#include "bond.hpp"
     
    2123#include "molecule.hpp"
    2224#include "periodentafel.hpp"
    23 #include "analysisbondsunittest.hpp"
    2425
    2526/********************************************** Test classes **************************************/
     
    4142  hydrogen = new element;
    4243  hydrogen->Z = 1;
     44  hydrogen->Valence = 1;
     45  hydrogen->NoValenceOrbitals = 1;
    4346  strcpy(hydrogen->name, "hydrogen");
    4447  strcpy(hydrogen->symbol, "H");
    4548  carbon = new element;
    4649  carbon->Z = 1;
     50  carbon->Valence = 4;
     51  carbon->NoValenceOrbitals = 4;
    4752  strcpy(carbon->name, "carbon");
    4853  strcpy(carbon->symbol, "C");
     
    5863  Walker = new atom();
    5964  Walker->type = hydrogen;
    60   Walker->node->Init(1., 0., 1. );
     65  Walker->node->Init(1.5, 0., 1.5 );
    6166  TestMolecule->AddAtom(Walker);
    6267  Walker = new atom();
    6368  Walker->type = hydrogen;
    64   Walker->node->Init(0., 1., 1. );
     69  Walker->node->Init(0., 1.5, 1.5 );
    6570  TestMolecule->AddAtom(Walker);
    6671  Walker = new atom();
    6772  Walker->type = hydrogen;
    68   Walker->node->Init(1., 1., 0. );
     73  Walker->node->Init(1.5, 1.5, 0. );
    6974  TestMolecule->AddAtom(Walker);
    7075  Walker = new atom();
     
    7277  Walker->node->Init(0., 0., 0. );
    7378  TestMolecule->AddAtom(Walker);
     79  Walker = new atom();
     80  Walker->type = carbon;
     81  Walker->node->Init(0.5, 0.5, 0.5 );
     82  TestMolecule->AddAtom(Walker);
    7483
    7584  // check that TestMolecule was correctly constructed
    76   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
     85  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 5 );
    7786
    7887  // create a small file with table
     
    8291  test << "H\t1.\t1.2\n";
    8392  test << "C\t1.2\t1.5\n";
     93  test.close();
    8494  BG = new BondGraph(true);
     95
     96  CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
     97  CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
     98  CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,1) );
     99  CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(1,1) );
     100
     101  BG->ConstructBondGraph(TestMolecule);
    85102};
    86103
     
    100117};
    101118
    102 /** UnitTest for AnalysisBondsTest::LoadBondLengthTable().
     119/** UnitTest for GetMaxMinMeanBondCount().
    103120 */
    104 void AnalysisBondsTest::BondsTest()
     121void AnalysisBondsTest::GetMaxMinMeanBondCountTest()
    105122{
    106   CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
    107   CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
    108   CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,1) );
    109   CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(1,1) );
    110 
    111   CPPUNIT_ASSERT_EQUAL( true , true );
     123  double Min = 20.; // check that initialization resets these arbitrary values
     124  double Mean = 200.;
     125  double Max = 1e-6;
     126  GetMaxMinMeanBondCount(TestMolecule, Min, Mean, Max);
     127  CPPUNIT_ASSERT_EQUAL( 1., Min );
     128  CPPUNIT_ASSERT_EQUAL( 1.6, Mean );
     129  CPPUNIT_ASSERT_EQUAL( 4., Max );
    112130
    113131};
     132
     133/** UnitTest for MinMaxBondDistanceBetweenElements().
     134 */
     135void AnalysisBondsTest::MinMeanMaxBondDistanceBetweenElementsTest()
     136{
     137  double Min = 20.; // check that initialization resets these arbitrary values
     138  double Mean = 2e+6;
     139  double Max = 1e-6;
     140  double Min2 = 20.;
     141  double Mean2 = 2e+6;
     142  double Max2 = 1e-6;
     143  const double maxbondlength = sqrt(1.*1. + 1.*1. + .5*.5);
     144  const double minbondlength = sqrt(.5*.5 + .5*.5 + .5*.5);
     145  const double meanbondlength = (minbondlength+3.*maxbondlength)/4.;
     146  // check bond lengths C-H
     147  MinMeanMaxBondDistanceBetweenElements(TestMolecule, hydrogen, carbon, Min, Mean, Max);
     148  CPPUNIT_ASSERT_EQUAL( minbondlength , Min );
     149  CPPUNIT_ASSERT_EQUAL( meanbondlength , Mean );
     150  CPPUNIT_ASSERT_EQUAL( maxbondlength , Max );
     151
     152  // check that elements are symmetric, i.e. C-H == H-C
     153  MinMeanMaxBondDistanceBetweenElements(TestMolecule, carbon, hydrogen, Min2, Mean2, Max2);
     154  CPPUNIT_ASSERT_EQUAL( Min , Min2 );
     155  CPPUNIT_ASSERT_EQUAL( Mean , Mean2 );
     156  CPPUNIT_ASSERT_EQUAL( Max , Max2 );
     157
     158  // check no bond case (no bonds H-H in system!)
     159  MinMeanMaxBondDistanceBetweenElements(TestMolecule, hydrogen, hydrogen, Min, Mean, Max);
     160  CPPUNIT_ASSERT_EQUAL( 0. , Min );
     161  CPPUNIT_ASSERT_EQUAL( 0. , Mean );
     162  CPPUNIT_ASSERT_EQUAL( 0. , Max );
     163};
     164
    114165
    115166/********************************************** Main routine **************************************/
  • src/unittests/analysisbondsunittest.hpp

    rb9947d r220cf37  
    1111#include <cppunit/extensions/HelperMacros.h>
    1212
    13 #include "bondgraph.hpp"
    14 
     13class BondGraph;
    1514class element;
    1615class molecule;
     
    2221{
    2322    CPPUNIT_TEST_SUITE( AnalysisBondsTest) ;
    24     CPPUNIT_TEST ( BondsTest );
     23    CPPUNIT_TEST ( GetMaxMinMeanBondCountTest );
     24    CPPUNIT_TEST ( MinMeanMaxBondDistanceBetweenElementsTest );
    2525    CPPUNIT_TEST_SUITE_END();
    2626
     
    2828      void setUp();
    2929      void tearDown();
    30       void BondsTest();
     30      void GetMaxMinMeanBondCountTest();
     31      void MinMeanMaxBondDistanceBetweenElementsTest();
    3132
    3233private:
Note: See TracChangeset for help on using the changeset viewer.