Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/analysisbondsunittest.cpp

    r6056f1 r49e1ae  
    1414#include <iostream>
    1515#include <stdio.h>
     16#include <cstring>
    1617
     18#include "analysis_bonds.hpp"
     19#include "analysisbondsunittest.hpp"
    1720#include "atom.hpp"
    1821#include "bond.hpp"
     
    2124#include "molecule.hpp"
    2225#include "periodentafel.hpp"
    23 #include "analysisbondsunittest.hpp"
    2426
    2527/********************************************** Test classes **************************************/
     
    4143  hydrogen = new element;
    4244  hydrogen->Z = 1;
     45  hydrogen->Valence = 1;
     46  hydrogen->NoValenceOrbitals = 1;
    4347  strcpy(hydrogen->name, "hydrogen");
    4448  strcpy(hydrogen->symbol, "H");
    4549  carbon = new element;
    46   carbon->Z = 2;
     50  carbon->Z = 1;
     51  carbon->Valence = 4;
     52  carbon->NoValenceOrbitals = 4;
    4753  strcpy(carbon->name, "carbon");
    4854  strcpy(carbon->symbol, "C");
     
    5864  Walker = new atom();
    5965  Walker->type = hydrogen;
    60   Walker->node->Init(1., 0., 1. );
     66  Walker->node->Init(1.5, 0., 1.5 );
    6167  TestMolecule->AddAtom(Walker);
    6268  Walker = new atom();
    6369  Walker->type = hydrogen;
    64   Walker->node->Init(0., 1., 1. );
     70  Walker->node->Init(0., 1.5, 1.5 );
    6571  TestMolecule->AddAtom(Walker);
    6672  Walker = new atom();
    6773  Walker->type = hydrogen;
    68   Walker->node->Init(1., 1., 0. );
     74  Walker->node->Init(1.5, 1.5, 0. );
    6975  TestMolecule->AddAtom(Walker);
    7076  Walker = new atom();
     
    7278  Walker->node->Init(0., 0., 0. );
    7379  TestMolecule->AddAtom(Walker);
     80  Walker = new atom();
     81  Walker->type = carbon;
     82  Walker->node->Init(0.5, 0.5, 0.5 );
     83  TestMolecule->AddAtom(Walker);
    7484
    7585  // check that TestMolecule was correctly constructed
    76   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
     86  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 5 );
    7787
    7888  // create a small file with table
     
    8292  test << "H\t1.\t1.2\n";
    8393  test << "C\t1.2\t1.5\n";
     94  test.close();
    8495  BG = new BondGraph(true);
     96
     97  CPPUNIT_ASSERT_EQUAL( true , BG->LoadBondLengthTable(*filename) );
     98  CPPUNIT_ASSERT_EQUAL( 1., BG->GetBondLength(0,0) );
     99  CPPUNIT_ASSERT_EQUAL( 1.2, BG->GetBondLength(0,1) );
     100  CPPUNIT_ASSERT_EQUAL( 1.5, BG->GetBondLength(1,1) );
     101
     102  BG->ConstructBondGraph(TestMolecule);
    85103};
    86104
     
    100118};
    101119
    102 /** UnitTest for AnalysisBondsTest::LoadBondLengthTable().
     120/** UnitTest for GetMaxMinMeanBondCount().
    103121 */
    104 void AnalysisBondsTest::BondsTest()
     122void AnalysisBondsTest::GetMaxMinMeanBondCountTest()
    105123{
    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 );
     124  double Min = 20.; // check that initialization resets these arbitrary values
     125  double Mean = 200.;
     126  double Max = 1e-6;
     127  GetMaxMinMeanBondCount(TestMolecule, Min, Mean, Max);
     128  CPPUNIT_ASSERT_EQUAL( 1., Min );
     129  CPPUNIT_ASSERT_EQUAL( 1.6, Mean );
     130  CPPUNIT_ASSERT_EQUAL( 4., Max );
    112131
    113132};
     133
     134/** UnitTest for MinMaxBondDistanceBetweenElements().
     135 */
     136void AnalysisBondsTest::MinMeanMaxBondDistanceBetweenElementsTest()
     137{
     138  double Min = 20.; // check that initialization resets these arbitrary values
     139  double Mean = 2e+6;
     140  double Max = 1e-6;
     141  double Min2 = 20.;
     142  double Mean2 = 2e+6;
     143  double Max2 = 1e-6;
     144  const double maxbondlength = sqrt(1.*1. + 1.*1. + .5*.5);
     145  const double minbondlength = sqrt(.5*.5 + .5*.5 + .5*.5);
     146  const double meanbondlength = (minbondlength+3.*maxbondlength)/4.;
     147  // check bond lengths C-H
     148  MinMeanMaxBondDistanceBetweenElements(TestMolecule, hydrogen, carbon, Min, Mean, Max);
     149  CPPUNIT_ASSERT_EQUAL( minbondlength , Min );
     150  CPPUNIT_ASSERT_EQUAL( meanbondlength , Mean );
     151  CPPUNIT_ASSERT_EQUAL( maxbondlength , Max );
     152
     153  // check that elements are symmetric, i.e. C-H == H-C
     154  MinMeanMaxBondDistanceBetweenElements(TestMolecule, carbon, hydrogen, Min2, Mean2, Max2);
     155  CPPUNIT_ASSERT_EQUAL( Min , Min2 );
     156  CPPUNIT_ASSERT_EQUAL( Mean , Mean2 );
     157  CPPUNIT_ASSERT_EQUAL( Max , Max2 );
     158
     159  // check no bond case (no bonds H-H in system!)
     160  MinMeanMaxBondDistanceBetweenElements(TestMolecule, hydrogen, hydrogen, Min, Mean, Max);
     161  CPPUNIT_ASSERT_EQUAL( 0. , Min );
     162  CPPUNIT_ASSERT_EQUAL( 0. , Mean );
     163  CPPUNIT_ASSERT_EQUAL( 0. , Max );
     164};
     165
    114166
    115167/********************************************** Main routine **************************************/
Note: See TracChangeset for help on using the changeset viewer.