Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/unittests/analysisbondsunittest.cpp

    r49e1ae r6056f1  
    1414#include <iostream>
    1515#include <stdio.h>
    16 #include <cstring>
    1716
    18 #include "analysis_bonds.hpp"
    19 #include "analysisbondsunittest.hpp"
    2017#include "atom.hpp"
    2118#include "bond.hpp"
     
    2421#include "molecule.hpp"
    2522#include "periodentafel.hpp"
     23#include "analysisbondsunittest.hpp"
    2624
    2725/********************************************** Test classes **************************************/
     
    4341  hydrogen = new element;
    4442  hydrogen->Z = 1;
    45   hydrogen->Valence = 1;
    46   hydrogen->NoValenceOrbitals = 1;
    4743  strcpy(hydrogen->name, "hydrogen");
    4844  strcpy(hydrogen->symbol, "H");
    4945  carbon = new element;
    50   carbon->Z = 1;
    51   carbon->Valence = 4;
    52   carbon->NoValenceOrbitals = 4;
     46  carbon->Z = 2;
    5347  strcpy(carbon->name, "carbon");
    5448  strcpy(carbon->symbol, "C");
     
    6458  Walker = new atom();
    6559  Walker->type = hydrogen;
    66   Walker->node->Init(1.5, 0., 1.5 );
     60  Walker->node->Init(1., 0., 1. );
    6761  TestMolecule->AddAtom(Walker);
    6862  Walker = new atom();
    6963  Walker->type = hydrogen;
    70   Walker->node->Init(0., 1.5, 1.5 );
     64  Walker->node->Init(0., 1., 1. );
    7165  TestMolecule->AddAtom(Walker);
    7266  Walker = new atom();
    7367  Walker->type = hydrogen;
    74   Walker->node->Init(1.5, 1.5, 0. );
     68  Walker->node->Init(1., 1., 0. );
    7569  TestMolecule->AddAtom(Walker);
    7670  Walker = new atom();
     
    7872  Walker->node->Init(0., 0., 0. );
    7973  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);
    8474
    8575  // check that TestMolecule was correctly constructed
    86   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 5 );
     76  CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    8777
    8878  // create a small file with table
     
    9282  test << "H\t1.\t1.2\n";
    9383  test << "C\t1.2\t1.5\n";
    94   test.close();
    9584  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);
    10385};
    10486
     
    118100};
    119101
    120 /** UnitTest for GetMaxMinMeanBondCount().
     102/** UnitTest for AnalysisBondsTest::LoadBondLengthTable().
    121103 */
    122 void AnalysisBondsTest::GetMaxMinMeanBondCountTest()
     104void AnalysisBondsTest::BondsTest()
    123105{
    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 );
     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 );
    131112
    132113};
    133 
    134 /** UnitTest for MinMaxBondDistanceBetweenElements().
    135  */
    136 void 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 
    166114
    167115/********************************************** Main routine **************************************/
Note: See TracChangeset for help on using the changeset viewer.