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