- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/analysisbondsunittest.cpp
r49e1ae r6056f1 14 14 #include <iostream> 15 15 #include <stdio.h> 16 #include <cstring>17 16 18 #include "analysis_bonds.hpp"19 #include "analysisbondsunittest.hpp"20 17 #include "atom.hpp" 21 18 #include "bond.hpp" … … 24 21 #include "molecule.hpp" 25 22 #include "periodentafel.hpp" 23 #include "analysisbondsunittest.hpp" 26 24 27 25 /********************************************** Test classes **************************************/ … … 43 41 hydrogen = new element; 44 42 hydrogen->Z = 1; 45 hydrogen->Valence = 1;46 hydrogen->NoValenceOrbitals = 1;47 43 strcpy(hydrogen->name, "hydrogen"); 48 44 strcpy(hydrogen->symbol, "H"); 49 45 carbon = new element; 50 carbon->Z = 1; 51 carbon->Valence = 4; 52 carbon->NoValenceOrbitals = 4; 46 carbon->Z = 2; 53 47 strcpy(carbon->name, "carbon"); 54 48 strcpy(carbon->symbol, "C"); … … 64 58 Walker = new atom(); 65 59 Walker->type = hydrogen; 66 Walker->node->Init(1. 5, 0., 1.5);60 Walker->node->Init(1., 0., 1. ); 67 61 TestMolecule->AddAtom(Walker); 68 62 Walker = new atom(); 69 63 Walker->type = hydrogen; 70 Walker->node->Init(0., 1. 5, 1.5);64 Walker->node->Init(0., 1., 1. ); 71 65 TestMolecule->AddAtom(Walker); 72 66 Walker = new atom(); 73 67 Walker->type = hydrogen; 74 Walker->node->Init(1. 5, 1.5, 0. );68 Walker->node->Init(1., 1., 0. ); 75 69 TestMolecule->AddAtom(Walker); 76 70 Walker = new atom(); … … 78 72 Walker->node->Init(0., 0., 0. ); 79 73 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);84 74 85 75 // check that TestMolecule was correctly constructed 86 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 5);76 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 ); 87 77 88 78 // create a small file with table … … 92 82 test << "H\t1.\t1.2\n"; 93 83 test << "C\t1.2\t1.5\n"; 94 test.close();95 84 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);103 85 }; 104 86 … … 118 100 }; 119 101 120 /** UnitTest for GetMaxMinMeanBondCount().102 /** UnitTest for AnalysisBondsTest::LoadBondLengthTable(). 121 103 */ 122 void AnalysisBondsTest:: GetMaxMinMeanBondCountTest()104 void AnalysisBondsTest::BondsTest() 123 105 { 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 ); 131 112 132 113 }; 133 134 /** UnitTest for MinMaxBondDistanceBetweenElements().135 */136 void AnalysisBondsTest::MinMeanMaxBondDistanceBetweenElementsTest()137 {138 double Min = 20.; // check that initialization resets these arbitrary values139 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-H148 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-C154 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 166 114 167 115 /********************************************** Main routine **************************************/
Note:
See TracChangeset
for help on using the changeset viewer.