| [bcf653] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
| [6d608d] | 4 |  * Copyright (C)  2010-2012 University of Bonn. All rights reserved.
 | 
|---|
| [bcf653] | 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
| [5630bd] | 8 | /*
 | 
|---|
| [7a0340] | 9 |  * RealSpaceMatrixUnitTest.cpp
 | 
|---|
| [5630bd] | 10 |  *
 | 
|---|
 | 11 |  *  Created on: Jul 7, 2010
 | 
|---|
 | 12 |  *      Author: crueger
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
| [bf3817] | 15 | // include config.h
 | 
|---|
 | 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 17 | #include <config.h>
 | 
|---|
 | 18 | #endif
 | 
|---|
 | 19 | 
 | 
|---|
| [5630bd] | 20 | #include <cppunit/CompilerOutputter.h>
 | 
|---|
 | 21 | #include <cppunit/extensions/TestFactoryRegistry.h>
 | 
|---|
 | 22 | #include <cppunit/ui/text/TestRunner.h>
 | 
|---|
 | 23 | 
 | 
|---|
| [31fb1d] | 24 | #include <cmath>
 | 
|---|
| [9b410d] | 25 | #include <limits>
 | 
|---|
| [31fb1d] | 26 | 
 | 
|---|
| [7a0340] | 27 | #include "RealSpaceMatrixUnitTest.hpp"
 | 
|---|
| [06aedc] | 28 | 
 | 
|---|
| [c2e567] | 29 | // include headers that implement a archive in simple text format
 | 
|---|
 | 30 | #include <boost/archive/text_oarchive.hpp>
 | 
|---|
 | 31 | #include <boost/archive/text_iarchive.hpp>
 | 
|---|
 | 32 | 
 | 
|---|
| [50c35d] | 33 | #include "CodePatterns/Assert.hpp"
 | 
|---|
 | 34 | 
 | 
|---|
| [bf4b9f] | 35 | #include "defs.hpp"
 | 
|---|
 | 36 | #include "Exceptions.hpp"
 | 
|---|
| [c2e567] | 37 | #include "MatrixContent.hpp"
 | 
|---|
| [bf4b9f] | 38 | #include "RealSpaceMatrix.hpp"
 | 
|---|
 | 39 | #include "Vector.hpp"
 | 
|---|
| [5630bd] | 40 | 
 | 
|---|
 | 41 | #ifdef HAVE_TESTRUNNER
 | 
|---|
 | 42 | #include "UnitTestMain.hpp"
 | 
|---|
 | 43 | #endif /*HAVE_TESTRUNNER*/
 | 
|---|
 | 44 | 
 | 
|---|
 | 45 | // Registers the fixture into the 'registry'
 | 
|---|
| [7a0340] | 46 | CPPUNIT_TEST_SUITE_REGISTRATION( RealSpaceMatrixTest );
 | 
|---|
| [5630bd] | 47 | 
 | 
|---|
| [7a0340] | 48 | void RealSpaceMatrixTest::setUp(){
 | 
|---|
| [50c35d] | 49 |   // failing asserts should be thrown
 | 
|---|
 | 50 |   ASSERT_DO(Assert::Throw);
 | 
|---|
 | 51 | 
 | 
|---|
| [cca9ef] | 52 |   zero = new RealSpaceMatrix();
 | 
|---|
| [3bc926] | 53 |   for(int i =NDIM;i--;) {
 | 
|---|
 | 54 |     for(int j =NDIM;j--;) {
 | 
|---|
 | 55 |       zero->at(i,j)=0.;
 | 
|---|
 | 56 |     }
 | 
|---|
 | 57 |   }
 | 
|---|
| [cca9ef] | 58 |   one = new RealSpaceMatrix();
 | 
|---|
| [5630bd] | 59 |   for(int i =NDIM;i--;){
 | 
|---|
 | 60 |     one->at(i,i)=1.;
 | 
|---|
 | 61 |   }
 | 
|---|
| [cca9ef] | 62 |   full=new RealSpaceMatrix();
 | 
|---|
| [5630bd] | 63 |   for(int i=NDIM;i--;){
 | 
|---|
 | 64 |     for(int j=NDIM;j--;){
 | 
|---|
 | 65 |       full->at(i,j)=1.;
 | 
|---|
 | 66 |     }
 | 
|---|
 | 67 |   }
 | 
|---|
| [cca9ef] | 68 |   diagonal = new RealSpaceMatrix();
 | 
|---|
| [5630bd] | 69 |   for(int i=NDIM;i--;){
 | 
|---|
 | 70 |     diagonal->at(i,i)=i+1.;
 | 
|---|
 | 71 |   }
 | 
|---|
| [cca9ef] | 72 |   perm1 = new RealSpaceMatrix();
 | 
|---|
| [407782] | 73 |   perm1->column(0) = unitVec[0];
 | 
|---|
 | 74 |   perm1->column(1) = unitVec[2];
 | 
|---|
 | 75 |   perm1->column(2) = unitVec[1];
 | 
|---|
| [5630bd] | 76 | 
 | 
|---|
 | 77 | 
 | 
|---|
| [cca9ef] | 78 |   perm2 = new RealSpaceMatrix();
 | 
|---|
| [407782] | 79 |   perm2->column(0) = unitVec[1];
 | 
|---|
 | 80 |   perm2->column(1) = unitVec[0];
 | 
|---|
 | 81 |   perm2->column(2) = unitVec[2];
 | 
|---|
| [5630bd] | 82 | 
 | 
|---|
| [cca9ef] | 83 |   perm3 = new RealSpaceMatrix();
 | 
|---|
| [407782] | 84 |   perm3->column(0) = unitVec[1];
 | 
|---|
 | 85 |   perm3->column(1) = unitVec[2];
 | 
|---|
 | 86 |   perm3->column(2) = unitVec[0];
 | 
|---|
| [5630bd] | 87 | 
 | 
|---|
| [cca9ef] | 88 |   perm4 = new RealSpaceMatrix();
 | 
|---|
| [407782] | 89 |   perm4->column(0) = unitVec[2];
 | 
|---|
 | 90 |   perm4->column(1) = unitVec[1];
 | 
|---|
 | 91 |   perm4->column(2) = unitVec[0];
 | 
|---|
| [5630bd] | 92 | 
 | 
|---|
| [cca9ef] | 93 |   perm5 = new RealSpaceMatrix();
 | 
|---|
| [407782] | 94 |   perm5->column(0) = unitVec[2];
 | 
|---|
 | 95 |   perm5->column(1) = unitVec[0];
 | 
|---|
 | 96 |   perm5->column(2) = unitVec[1];
 | 
|---|
| [5630bd] | 97 | 
 | 
|---|
 | 98 | }
 | 
|---|
| [7a0340] | 99 | void RealSpaceMatrixTest::tearDown(){
 | 
|---|
| [5630bd] | 100 |   delete zero;
 | 
|---|
 | 101 |   delete one;
 | 
|---|
 | 102 |   delete full;
 | 
|---|
 | 103 |   delete diagonal;
 | 
|---|
 | 104 |   delete perm1;
 | 
|---|
 | 105 |   delete perm2;
 | 
|---|
 | 106 |   delete perm3;
 | 
|---|
 | 107 |   delete perm4;
 | 
|---|
 | 108 |   delete perm5;
 | 
|---|
 | 109 | }
 | 
|---|
 | 110 | 
 | 
|---|
| [7a0340] | 111 | void RealSpaceMatrixTest::AccessTest(){
 | 
|---|
| [cca9ef] | 112 |   RealSpaceMatrix mat;
 | 
|---|
| [5630bd] | 113 |   for(int i=NDIM;i--;){
 | 
|---|
 | 114 |     for(int j=NDIM;j--;){
 | 
|---|
 | 115 |       CPPUNIT_ASSERT_EQUAL(mat.at(i,j),0.);
 | 
|---|
 | 116 |     }
 | 
|---|
 | 117 |   }
 | 
|---|
 | 118 |   int k=1;
 | 
|---|
 | 119 |   for(int i=NDIM;i--;){
 | 
|---|
 | 120 |     for(int j=NDIM;j--;){
 | 
|---|
 | 121 |       mat.at(i,j)=k++;
 | 
|---|
 | 122 |     }
 | 
|---|
 | 123 |   }
 | 
|---|
 | 124 |   k=1;
 | 
|---|
 | 125 |   for(int i=NDIM;i--;){
 | 
|---|
 | 126 |     for(int j=NDIM;j--;){
 | 
|---|
 | 127 |       CPPUNIT_ASSERT_EQUAL(mat.at(i,j),(double)k);
 | 
|---|
 | 128 |       ++k;
 | 
|---|
 | 129 |     }
 | 
|---|
 | 130 |   }
 | 
|---|
 | 131 | }
 | 
|---|
 | 132 | 
 | 
|---|
| [7a0340] | 133 | void RealSpaceMatrixTest::VectorTest(){
 | 
|---|
| [cca9ef] | 134 |   RealSpaceMatrix mat;
 | 
|---|
| [5630bd] | 135 |   for(int i=NDIM;i--;){
 | 
|---|
 | 136 |     CPPUNIT_ASSERT_EQUAL(mat.row(i),zeroVec);
 | 
|---|
 | 137 |     CPPUNIT_ASSERT_EQUAL(mat.column(i),zeroVec);
 | 
|---|
 | 138 |   }
 | 
|---|
 | 139 |   CPPUNIT_ASSERT_EQUAL(mat.diagonal(),zeroVec);
 | 
|---|
 | 140 | 
 | 
|---|
| [9eb7580] | 141 |   mat.setIdentity();
 | 
|---|
| [407782] | 142 |   CPPUNIT_ASSERT_EQUAL(mat.row(0),unitVec[0]);
 | 
|---|
 | 143 |   CPPUNIT_ASSERT_EQUAL(mat.row(1),unitVec[1]);
 | 
|---|
 | 144 |   CPPUNIT_ASSERT_EQUAL(mat.row(2),unitVec[2]);
 | 
|---|
 | 145 |   CPPUNIT_ASSERT_EQUAL(mat.column(0),unitVec[0]);
 | 
|---|
 | 146 |   CPPUNIT_ASSERT_EQUAL(mat.column(1),unitVec[1]);
 | 
|---|
 | 147 |   CPPUNIT_ASSERT_EQUAL(mat.column(2),unitVec[2]);
 | 
|---|
| [5630bd] | 148 | 
 | 
|---|
 | 149 |   Vector t1=Vector(1.,1.,1.);
 | 
|---|
 | 150 |   Vector t2=Vector(2.,2.,2.);
 | 
|---|
 | 151 |   Vector t3=Vector(3.,3.,3.);
 | 
|---|
 | 152 |   Vector t4=Vector(1.,2.,3.);
 | 
|---|
 | 153 | 
 | 
|---|
 | 154 |   mat.row(0)=t1;
 | 
|---|
 | 155 |   mat.row(1)=t2;
 | 
|---|
 | 156 |   mat.row(2)=t3;
 | 
|---|
 | 157 |   CPPUNIT_ASSERT_EQUAL(mat.row(0),t1);
 | 
|---|
 | 158 |   CPPUNIT_ASSERT_EQUAL(mat.row(1),t2);
 | 
|---|
 | 159 |   CPPUNIT_ASSERT_EQUAL(mat.row(2),t3);
 | 
|---|
 | 160 |   CPPUNIT_ASSERT_EQUAL(mat.column(0),t4);
 | 
|---|
 | 161 |   CPPUNIT_ASSERT_EQUAL(mat.column(1),t4);
 | 
|---|
 | 162 |   CPPUNIT_ASSERT_EQUAL(mat.column(2),t4);
 | 
|---|
 | 163 |   CPPUNIT_ASSERT_EQUAL(mat.diagonal(),t4);
 | 
|---|
 | 164 |   for(int i=NDIM;i--;){
 | 
|---|
 | 165 |     for(int j=NDIM;j--;){
 | 
|---|
 | 166 |       CPPUNIT_ASSERT_EQUAL(mat.at(i,j),i+1.);
 | 
|---|
 | 167 |     }
 | 
|---|
 | 168 |   }
 | 
|---|
 | 169 | 
 | 
|---|
 | 170 |   mat.column(0)=t1;
 | 
|---|
 | 171 |   mat.column(1)=t2;
 | 
|---|
 | 172 |   mat.column(2)=t3;
 | 
|---|
 | 173 |   CPPUNIT_ASSERT_EQUAL(mat.column(0),t1);
 | 
|---|
 | 174 |   CPPUNIT_ASSERT_EQUAL(mat.column(1),t2);
 | 
|---|
 | 175 |   CPPUNIT_ASSERT_EQUAL(mat.column(2),t3);
 | 
|---|
 | 176 |   CPPUNIT_ASSERT_EQUAL(mat.row(0),t4);
 | 
|---|
 | 177 |   CPPUNIT_ASSERT_EQUAL(mat.row(1),t4);
 | 
|---|
 | 178 |   CPPUNIT_ASSERT_EQUAL(mat.row(2),t4);
 | 
|---|
 | 179 |   CPPUNIT_ASSERT_EQUAL(mat.diagonal(),t4);
 | 
|---|
 | 180 |   for(int i=NDIM;i--;){
 | 
|---|
 | 181 |     for(int j=NDIM;j--;){
 | 
|---|
 | 182 |       CPPUNIT_ASSERT_EQUAL(mat.at(i,j),j+1.);
 | 
|---|
 | 183 |     }
 | 
|---|
 | 184 |   }
 | 
|---|
 | 185 | }
 | 
|---|
 | 186 | 
 | 
|---|
| [7a0340] | 187 | void RealSpaceMatrixTest::TransposeTest(){
 | 
|---|
| [cca9ef] | 188 |   RealSpaceMatrix res;
 | 
|---|
| [31fb1d] | 189 | 
 | 
|---|
 | 190 |   // transpose of unit is unit
 | 
|---|
| [9eb7580] | 191 |   res.setIdentity();
 | 
|---|
| [3bc926] | 192 |   res.transpose();
 | 
|---|
| [31fb1d] | 193 |   CPPUNIT_ASSERT_EQUAL(res,*one);
 | 
|---|
 | 194 | 
 | 
|---|
 | 195 |   // transpose of transpose is same matrix
 | 
|---|
| [9eb7580] | 196 |   res.setZero();
 | 
|---|
| [31fb1d] | 197 |   res.set(2,2, 1.);
 | 
|---|
 | 198 |   CPPUNIT_ASSERT_EQUAL(res.transpose().transpose(),res);
 | 
|---|
 | 199 | }
 | 
|---|
 | 200 | 
 | 
|---|
| [7a0340] | 201 | void RealSpaceMatrixTest::OperationTest(){
 | 
|---|
| [cca9ef] | 202 |   RealSpaceMatrix res;
 | 
|---|
| [5630bd] | 203 | 
 | 
|---|
 | 204 |   res =(*zero) *(*zero);
 | 
|---|
| [9b410d] | 205 |   //std::cout << *zero << " times " << *zero << " is " << res << std::endl;
 | 
|---|
| [5630bd] | 206 |   CPPUNIT_ASSERT_EQUAL(res,*zero);
 | 
|---|
 | 207 |   res =(*zero) *(*one);
 | 
|---|
 | 208 |   CPPUNIT_ASSERT_EQUAL(res,*zero);
 | 
|---|
 | 209 |   res =(*zero) *(*full);
 | 
|---|
 | 210 |   CPPUNIT_ASSERT_EQUAL(res,*zero);
 | 
|---|
 | 211 |   res =(*zero) *(*diagonal);
 | 
|---|
 | 212 |   CPPUNIT_ASSERT_EQUAL(res,*zero);
 | 
|---|
 | 213 |   res =(*zero) *(*perm1);
 | 
|---|
 | 214 |   CPPUNIT_ASSERT_EQUAL(res,*zero);
 | 
|---|
 | 215 |   res =(*zero) *(*perm2);
 | 
|---|
 | 216 |   CPPUNIT_ASSERT_EQUAL(res,*zero);
 | 
|---|
 | 217 |   res =(*zero) *(*perm3);
 | 
|---|
 | 218 |   CPPUNIT_ASSERT_EQUAL(res,*zero);
 | 
|---|
 | 219 |   res =(*zero) *(*perm4);
 | 
|---|
 | 220 |   CPPUNIT_ASSERT_EQUAL(res,*zero);
 | 
|---|
 | 221 |   res =(*zero) *(*perm5);
 | 
|---|
 | 222 |   CPPUNIT_ASSERT_EQUAL(res,*zero);
 | 
|---|
 | 223 | 
 | 
|---|
 | 224 |   res =(*one)*(*one);
 | 
|---|
 | 225 |   CPPUNIT_ASSERT_EQUAL(res,*one);
 | 
|---|
 | 226 |   res =(*one)*(*full);
 | 
|---|
 | 227 |   CPPUNIT_ASSERT_EQUAL(res,*full);
 | 
|---|
 | 228 |   res =(*one)*(*diagonal);
 | 
|---|
 | 229 |   CPPUNIT_ASSERT_EQUAL(res,*diagonal);
 | 
|---|
 | 230 |   res =(*one)*(*perm1);
 | 
|---|
 | 231 |   CPPUNIT_ASSERT_EQUAL(res,*perm1);
 | 
|---|
 | 232 |   res =(*one)*(*perm2);
 | 
|---|
 | 233 |   CPPUNIT_ASSERT_EQUAL(res,*perm2);
 | 
|---|
 | 234 |   res =(*one)*(*perm3);
 | 
|---|
 | 235 |   CPPUNIT_ASSERT_EQUAL(res,*perm3);
 | 
|---|
 | 236 |   res =(*one)*(*perm4);
 | 
|---|
 | 237 |   CPPUNIT_ASSERT_EQUAL(res,*perm4);
 | 
|---|
 | 238 |   res =(*one)*(*perm5);
 | 
|---|
 | 239 |   CPPUNIT_ASSERT_EQUAL(res,*perm5);
 | 
|---|
 | 240 | 
 | 
|---|
 | 241 |   res = (*full)*(*perm1);
 | 
|---|
 | 242 |   CPPUNIT_ASSERT_EQUAL(res,*full);
 | 
|---|
 | 243 |   res = (*full)*(*perm2);
 | 
|---|
 | 244 |   CPPUNIT_ASSERT_EQUAL(res,*full);
 | 
|---|
 | 245 |   res = (*full)*(*perm3);
 | 
|---|
 | 246 |   CPPUNIT_ASSERT_EQUAL(res,*full);
 | 
|---|
 | 247 |   res = (*full)*(*perm4);
 | 
|---|
 | 248 |   CPPUNIT_ASSERT_EQUAL(res,*full);
 | 
|---|
 | 249 |   res = (*full)*(*perm5);
 | 
|---|
 | 250 |   CPPUNIT_ASSERT_EQUAL(res,*full);
 | 
|---|
 | 251 | 
 | 
|---|
 | 252 |   res = (*diagonal)*(*perm1);
 | 
|---|
| [407782] | 253 |   CPPUNIT_ASSERT_EQUAL(res.column(0),unitVec[0]);
 | 
|---|
 | 254 |   CPPUNIT_ASSERT_EQUAL(res.column(1),3*unitVec[2]);
 | 
|---|
 | 255 |   CPPUNIT_ASSERT_EQUAL(res.column(2),2*unitVec[1]);
 | 
|---|
| [5630bd] | 256 |   res = (*diagonal)*(*perm2);
 | 
|---|
| [407782] | 257 |   CPPUNIT_ASSERT_EQUAL(res.column(0),2*unitVec[1]);
 | 
|---|
 | 258 |   CPPUNIT_ASSERT_EQUAL(res.column(1),unitVec[0]);
 | 
|---|
 | 259 |   CPPUNIT_ASSERT_EQUAL(res.column(2),3*unitVec[2]);
 | 
|---|
| [5630bd] | 260 |   res = (*diagonal)*(*perm3);
 | 
|---|
| [407782] | 261 |   CPPUNIT_ASSERT_EQUAL(res.column(0),2*unitVec[1]);
 | 
|---|
 | 262 |   CPPUNIT_ASSERT_EQUAL(res.column(1),3*unitVec[2]);
 | 
|---|
 | 263 |   CPPUNIT_ASSERT_EQUAL(res.column(2),unitVec[0]);
 | 
|---|
| [5630bd] | 264 |   res = (*diagonal)*(*perm4);
 | 
|---|
| [407782] | 265 |   CPPUNIT_ASSERT_EQUAL(res.column(0),3*unitVec[2]);
 | 
|---|
 | 266 |   CPPUNIT_ASSERT_EQUAL(res.column(1),2*unitVec[1]);
 | 
|---|
 | 267 |   CPPUNIT_ASSERT_EQUAL(res.column(2),unitVec[0]);
 | 
|---|
| [5630bd] | 268 |   res = (*diagonal)*(*perm5);
 | 
|---|
| [407782] | 269 |   CPPUNIT_ASSERT_EQUAL(res.column(0),3*unitVec[2]);
 | 
|---|
 | 270 |   CPPUNIT_ASSERT_EQUAL(res.column(1),unitVec[0]);
 | 
|---|
 | 271 |   CPPUNIT_ASSERT_EQUAL(res.column(2),2*unitVec[1]);
 | 
|---|
| [5630bd] | 272 | }
 | 
|---|
 | 273 | 
 | 
|---|
| [7a0340] | 274 | void RealSpaceMatrixTest::RotationTest(){
 | 
|---|
| [cca9ef] | 275 |   RealSpaceMatrix res;
 | 
|---|
 | 276 |   RealSpaceMatrix inverse;
 | 
|---|
| [50c35d] | 277 |   Vector fixture;
 | 
|---|
| [31fb1d] | 278 | 
 | 
|---|
 | 279 |   // zero rotation angles yields unity matrix
 | 
|---|
| [9eb7580] | 280 |   res.setRotation(0,0,0);
 | 
|---|
| [31fb1d] | 281 |   CPPUNIT_ASSERT_EQUAL(*one, res);
 | 
|---|
 | 282 | 
 | 
|---|
 | 283 |   // arbitrary rotation matrix has det = 1
 | 
|---|
| [9eb7580] | 284 |   res.setRotation(M_PI/3.,1.,M_PI/7.);
 | 
|---|
| [819cbe] | 285 |   CPPUNIT_ASSERT(fabs(res.determinant() - 1.) <= LINALG_MYEPSILON());
 | 
|---|
| [31fb1d] | 286 | 
 | 
|---|
 | 287 |   // inverse is rotation matrix with negative angles
 | 
|---|
| [9eb7580] | 288 |   res.setRotation(M_PI/3.,0.,0.);
 | 
|---|
 | 289 |   inverse.setRotation(-M_PI/3.,0.,0.);
 | 
|---|
| [31fb1d] | 290 |   CPPUNIT_ASSERT_EQUAL(*one, res * inverse);
 | 
|---|
 | 291 | 
 | 
|---|
 | 292 |   // ... or transposed
 | 
|---|
| [9eb7580] | 293 |   res.setRotation(M_PI/3.,0.,0.);
 | 
|---|
| [26108c] | 294 |   CPPUNIT_ASSERT_EQUAL(inverse, res.transposed());
 | 
|---|
| [50c35d] | 295 | 
 | 
|---|
 | 296 |   // check arbitrary axis
 | 
|---|
 | 297 |   res.setRotation(unitVec[0], M_PI/3.);
 | 
|---|
 | 298 |   inverse.setRotation(M_PI/3.,0.,0.);
 | 
|---|
 | 299 |   CPPUNIT_ASSERT_EQUAL( res, inverse);
 | 
|---|
 | 300 |   res.setRotation(unitVec[1], M_PI/3.);
 | 
|---|
 | 301 |   inverse.setRotation(0., M_PI/3.,0.);
 | 
|---|
 | 302 |   CPPUNIT_ASSERT_EQUAL( res, inverse);
 | 
|---|
 | 303 |   res.setRotation(unitVec[2], M_PI/3.);
 | 
|---|
 | 304 |   inverse.setRotation(0.,0.,M_PI/3.);
 | 
|---|
 | 305 |   CPPUNIT_ASSERT_EQUAL( res, inverse);
 | 
|---|
 | 306 | 
 | 
|---|
 | 307 |   // check axis not normalized throws
 | 
|---|
 | 308 | #ifndef NDEBUG
 | 
|---|
 | 309 |   CPPUNIT_ASSERT_THROW( res.setRotation(unitVec[0]+unitVec[1], M_PI/3.),Assert::AssertionFailure);
 | 
|---|
 | 310 | #endif
 | 
|---|
 | 311 | 
 | 
|---|
 | 312 |   // check arbitrary axis and det=1
 | 
|---|
 | 313 |   fixture = (unitVec[0]+unitVec[1]).getNormalized();
 | 
|---|
 | 314 |   res.setRotation(fixture, M_PI/3.);
 | 
|---|
 | 315 |   CPPUNIT_ASSERT(fabs(res.determinant() - 1.) <= LINALG_MYEPSILON());
 | 
|---|
 | 316 |   fixture = (unitVec[1]+unitVec[2]).getNormalized();
 | 
|---|
 | 317 |   res.setRotation(fixture, M_PI/3.);
 | 
|---|
 | 318 |   CPPUNIT_ASSERT(fabs(res.determinant() - 1.) <= LINALG_MYEPSILON());
 | 
|---|
 | 319 |   fixture = (unitVec[1]+unitVec[2]).getNormalized();
 | 
|---|
 | 320 |   res.setRotation(fixture, M_PI/3.);
 | 
|---|
 | 321 |   CPPUNIT_ASSERT(fabs(res.determinant() - 1.) <= LINALG_MYEPSILON());
 | 
|---|
| [31fb1d] | 322 | }
 | 
|---|
| [5630bd] | 323 | 
 | 
|---|
| [7a0340] | 324 | void RealSpaceMatrixTest::InvertTest(){
 | 
|---|
| [5630bd] | 325 |   CPPUNIT_ASSERT_THROW(zero->invert(),NotInvertibleException);
 | 
|---|
 | 326 |   CPPUNIT_ASSERT_THROW(full->invert(),NotInvertibleException);
 | 
|---|
 | 327 | 
 | 
|---|
| [cca9ef] | 328 |   RealSpaceMatrix res;
 | 
|---|
| [5630bd] | 329 |   res = (*one)*one->invert();
 | 
|---|
 | 330 |   CPPUNIT_ASSERT_EQUAL(res,*one);
 | 
|---|
 | 331 |   res = (*diagonal)*diagonal->invert();
 | 
|---|
 | 332 |   CPPUNIT_ASSERT_EQUAL(res,*one);
 | 
|---|
 | 333 |   res = (*perm1)*perm1->invert();
 | 
|---|
 | 334 |   CPPUNIT_ASSERT_EQUAL(res,*one);
 | 
|---|
 | 335 |   res = (*perm2)*perm2->invert();
 | 
|---|
 | 336 |   CPPUNIT_ASSERT_EQUAL(res,*one);
 | 
|---|
 | 337 |   res = (*perm3)*perm3->invert();
 | 
|---|
 | 338 |   CPPUNIT_ASSERT_EQUAL(res,*one);
 | 
|---|
 | 339 |   res = (*perm4)*perm4->invert();
 | 
|---|
 | 340 |   CPPUNIT_ASSERT_EQUAL(res,*one);
 | 
|---|
 | 341 |   res = (*perm5)*perm5->invert();
 | 
|---|
 | 342 |   CPPUNIT_ASSERT_EQUAL(res,*one);
 | 
|---|
 | 343 | }
 | 
|---|
 | 344 | 
 | 
|---|
 | 345 | 
 | 
|---|
| [7a0340] | 346 | void RealSpaceMatrixTest::DeterminantTest(){
 | 
|---|
| [5630bd] | 347 |   CPPUNIT_ASSERT_EQUAL(zero->determinant(),0.);
 | 
|---|
 | 348 |   CPPUNIT_ASSERT_EQUAL(one->determinant(),1.);
 | 
|---|
 | 349 |   CPPUNIT_ASSERT_EQUAL(diagonal->determinant(),6.);
 | 
|---|
 | 350 |   CPPUNIT_ASSERT_EQUAL(full->determinant(),0.);
 | 
|---|
 | 351 |   CPPUNIT_ASSERT_EQUAL(perm1->determinant(),-1.);
 | 
|---|
 | 352 |   CPPUNIT_ASSERT_EQUAL(perm2->determinant(),-1.);
 | 
|---|
 | 353 |   CPPUNIT_ASSERT_EQUAL(perm3->determinant(),1.);
 | 
|---|
 | 354 |   CPPUNIT_ASSERT_EQUAL(perm4->determinant(),-1.);
 | 
|---|
 | 355 |   CPPUNIT_ASSERT_EQUAL(perm5->determinant(),1.);
 | 
|---|
 | 356 | }
 | 
|---|
 | 357 | 
 | 
|---|
| [7a0340] | 358 | void RealSpaceMatrixTest::VecMultTest(){
 | 
|---|
| [407782] | 359 |   CPPUNIT_ASSERT_EQUAL((*zero)*unitVec[0],zeroVec);
 | 
|---|
 | 360 |   CPPUNIT_ASSERT_EQUAL((*zero)*unitVec[1],zeroVec);
 | 
|---|
 | 361 |   CPPUNIT_ASSERT_EQUAL((*zero)*unitVec[2],zeroVec);
 | 
|---|
| [5630bd] | 362 |   CPPUNIT_ASSERT_EQUAL((*zero)*zeroVec,zeroVec);
 | 
|---|
 | 363 | 
 | 
|---|
| [407782] | 364 |   CPPUNIT_ASSERT_EQUAL((*one)*unitVec[0],unitVec[0]);
 | 
|---|
 | 365 |   CPPUNIT_ASSERT_EQUAL((*one)*unitVec[1],unitVec[1]);
 | 
|---|
 | 366 |   CPPUNIT_ASSERT_EQUAL((*one)*unitVec[2],unitVec[2]);
 | 
|---|
| [5630bd] | 367 |   CPPUNIT_ASSERT_EQUAL((*one)*zeroVec,zeroVec);
 | 
|---|
 | 368 | 
 | 
|---|
| [407782] | 369 |   CPPUNIT_ASSERT_EQUAL((*diagonal)*unitVec[0],unitVec[0]);
 | 
|---|
 | 370 |   CPPUNIT_ASSERT_EQUAL((*diagonal)*unitVec[1],2*unitVec[1]);
 | 
|---|
 | 371 |   CPPUNIT_ASSERT_EQUAL((*diagonal)*unitVec[2],3*unitVec[2]);
 | 
|---|
| [5630bd] | 372 |   CPPUNIT_ASSERT_EQUAL((*diagonal)*zeroVec,zeroVec);
 | 
|---|
 | 373 | 
 | 
|---|
| [407782] | 374 |   CPPUNIT_ASSERT_EQUAL((*perm1)*unitVec[0],unitVec[0]);
 | 
|---|
 | 375 |   CPPUNIT_ASSERT_EQUAL((*perm1)*unitVec[1],unitVec[2]);
 | 
|---|
 | 376 |   CPPUNIT_ASSERT_EQUAL((*perm1)*unitVec[2],unitVec[1]);
 | 
|---|
| [5630bd] | 377 |   CPPUNIT_ASSERT_EQUAL((*perm1)*zeroVec,zeroVec);
 | 
|---|
 | 378 | 
 | 
|---|
| [407782] | 379 |   CPPUNIT_ASSERT_EQUAL((*perm2)*unitVec[0],unitVec[1]);
 | 
|---|
 | 380 |   CPPUNIT_ASSERT_EQUAL((*perm2)*unitVec[1],unitVec[0]);
 | 
|---|
 | 381 |   CPPUNIT_ASSERT_EQUAL((*perm2)*unitVec[2],unitVec[2]);
 | 
|---|
| [5630bd] | 382 |   CPPUNIT_ASSERT_EQUAL((*perm2)*zeroVec,zeroVec);
 | 
|---|
 | 383 | 
 | 
|---|
| [407782] | 384 |   CPPUNIT_ASSERT_EQUAL((*perm3)*unitVec[0],unitVec[1]);
 | 
|---|
 | 385 |   CPPUNIT_ASSERT_EQUAL((*perm3)*unitVec[1],unitVec[2]);
 | 
|---|
 | 386 |   CPPUNIT_ASSERT_EQUAL((*perm3)*unitVec[2],unitVec[0]);
 | 
|---|
| [5630bd] | 387 |   CPPUNIT_ASSERT_EQUAL((*perm3)*zeroVec,zeroVec);
 | 
|---|
 | 388 | 
 | 
|---|
| [407782] | 389 |   CPPUNIT_ASSERT_EQUAL((*perm4)*unitVec[0],unitVec[2]);
 | 
|---|
 | 390 |   CPPUNIT_ASSERT_EQUAL((*perm4)*unitVec[1],unitVec[1]);
 | 
|---|
 | 391 |   CPPUNIT_ASSERT_EQUAL((*perm4)*unitVec[2],unitVec[0]);
 | 
|---|
| [5630bd] | 392 |   CPPUNIT_ASSERT_EQUAL((*perm4)*zeroVec,zeroVec);
 | 
|---|
 | 393 | 
 | 
|---|
| [407782] | 394 |   CPPUNIT_ASSERT_EQUAL((*perm5)*unitVec[0],unitVec[2]);
 | 
|---|
 | 395 |   CPPUNIT_ASSERT_EQUAL((*perm5)*unitVec[1],unitVec[0]);
 | 
|---|
 | 396 |   CPPUNIT_ASSERT_EQUAL((*perm5)*unitVec[2],unitVec[1]);
 | 
|---|
| [5630bd] | 397 |   CPPUNIT_ASSERT_EQUAL((*perm5)*zeroVec,zeroVec);
 | 
|---|
 | 398 | 
 | 
|---|
 | 399 |   Vector t = Vector(1.,2.,3.);
 | 
|---|
 | 400 |   CPPUNIT_ASSERT_EQUAL((*perm1)*t,Vector(1,3,2));
 | 
|---|
 | 401 |   CPPUNIT_ASSERT_EQUAL((*perm2)*t,Vector(2,1,3));
 | 
|---|
 | 402 |   CPPUNIT_ASSERT_EQUAL((*perm3)*t,Vector(3,1,2));
 | 
|---|
 | 403 |   CPPUNIT_ASSERT_EQUAL((*perm4)*t,Vector(3,2,1));
 | 
|---|
 | 404 |   CPPUNIT_ASSERT_EQUAL((*perm5)*t,Vector(2,3,1));
 | 
|---|
 | 405 | }
 | 
|---|
| [c2e567] | 406 | 
 | 
|---|
 | 407 | void RealSpaceMatrixTest::SerializationTest()
 | 
|---|
 | 408 | {
 | 
|---|
 | 409 |   // write element to stream
 | 
|---|
 | 410 |   std::stringstream stream;
 | 
|---|
 | 411 |   boost::archive::text_oarchive oa(stream);
 | 
|---|
 | 412 |   oa << diagonal;
 | 
|---|
 | 413 | 
 | 
|---|
 | 414 |   //std::cout << "Contents of archive is " << stream.str() << std::endl;
 | 
|---|
 | 415 | 
 | 
|---|
 | 416 |   // create and open an archive for input
 | 
|---|
 | 417 |   boost::archive::text_iarchive ia(stream);
 | 
|---|
 | 418 |   // read class state from archive
 | 
|---|
 | 419 |   RealSpaceMatrix *newm;
 | 
|---|
 | 420 | 
 | 
|---|
 | 421 |   ia >> newm;
 | 
|---|
 | 422 | 
 | 
|---|
 | 423 |   CPPUNIT_ASSERT (*diagonal == *newm);
 | 
|---|
 | 424 | }
 | 
|---|