Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/analysisbondsunittest.cpp

    r220cf37 r6056f1  
    1515#include <stdio.h>
    1616
    17 #include "analysis_bonds.hpp"
    18 #include "analysisbondsunittest.hpp"
    1917#include "atom.hpp"
    2018#include "bond.hpp"
     
    2321#include "molecule.hpp"
    2422#include "periodentafel.hpp"
     23#include "analysisbondsunittest.hpp"
    2524
    2625/********************************************** Test classes **************************************/
     
    4241  hydrogen = new element;
    4342  hydrogen->Z = 1;
    44   hydrogen->Valence = 1;
    45   hydrogen->NoValenceOrbitals = 1;
    4643  strcpy(hydrogen->name, "hydrogen");
    4744  strcpy(hydrogen->symbol, "H");
    4845  carbon = new element;
    49   carbon->Z = 1;
    50   carbon->Valence = 4;
    51   carbon->NoValenceOrbitals = 4;
     46  carbon->Z = 2;
    5247  strcpy(carbon->name, "carbon");
    5348  strcpy(carbon->symbol, "C");
     
    6358  Walker = new atom();
    6459  Walker->type = hydrogen;
    65   Walker->node->Init(1.5, 0., 1.5 );
     60  Walker->node->Init(1., 0., 1. );
    6661  TestMolecule->AddAtom(Walker);
    6762  Walker = new atom();
    6863  Walker->type = hydrogen;
    69   Walker->node->Init(0., 1.5, 1.5 );
     64  Walker->node->Init(0., 1., 1. );
    7065  TestMolecule->AddAtom(Walker);
    7166  Walker = new atom();
    7267  Walker->type = hydrogen;
    73   Walker->node->Init(1.5, 1.5, 0. );
     68  Walker->node->Init(1., 1., 0. );
    7469  TestMolecule->AddAtom(Walker);
    7570  Walker = new atom();
     
    7772  Walker->node->Init(0., 0., 0. );
    7873  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);
    8374
    8475  // check that TestMolecule was correctly constructed
    85   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 5 );
     76  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    8677
    8778  // create a small file with table
     
    9182  test << "H\t1.\t1.2\n";
    9283  test << "C\t1.2\t1.5\n";
    93   test.close();
    9484  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);
    10285};
    10386
     
    117100};
    118101
    119 /** UnitTest for GetMaxMinMeanBondCount().
     102/** UnitTest for AnalysisBondsTest::LoadBondLengthTable().
    120103 */
    121 void AnalysisBondsTest::GetMaxMinMeanBondCountTest()
     104void AnalysisBondsTest::BondsTest()
    122105{
    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 );
     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 );
    130112
    131113};
    132 
    133 /** UnitTest for MinMaxBondDistanceBetweenElements().
    134  */
    135 void 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 
    165114
    166115/********************************************** Main routine **************************************/
Note: See TracChangeset for help on using the changeset viewer.