Changeset 0d4424 for src/unittests
- Timestamp:
- Dec 4, 2010, 11:54:32 PM (14 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- c134d9
- Parents:
- cca9ef
- git-author:
- Frederik Heber <heber@…> (11/15/10 14:02:38)
- git-committer:
- Frederik Heber <heber@…> (12/04/10 23:54:32)
- Location:
- src/unittests
- Files:
-
- 1 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
src/unittests/Makefile.am
rcca9ef r0d4424 22 22 CountBondsUnitTest \ 23 23 FormulaUnittest \ 24 GSLMatrixSymmetricUnitTest \25 GSLMatrixUnitTest \26 24 GSLVectorUnitTest \ 27 25 InfoUnitTest \ … … 32 30 LogUnitTest \ 33 31 manipulateAtomsTest \ 32 MatrixContentSymmetricUnitTest \ 33 MatrixContentUnitTest \ 34 34 MatrixUnittest \ 35 35 MenuDescriptionUnitTest \ … … 82 82 CountBondsUnitTest.cpp \ 83 83 FormulaUnittest.cpp \ 84 gslmatrixsymmetricunittest.cpp \85 gslmatrixunittest.cpp \86 84 gslvectorunittest.cpp \ 87 85 infounittest.cpp \ … … 91 89 listofbondsunittest.cpp \ 92 90 logunittest.cpp \ 91 MatrixContentSymmetricUnittest.cpp \ 92 MatrixContentUnittest.cpp \ 93 93 MatrixUnittest.cpp \ 94 94 manipulateAtomsTest.cpp \ … … 122 122 CountBondsUnitTest.hpp \ 123 123 FormulaUnittest.hpp \ 124 gslmatrixsymmetricunittest.hpp \125 gslmatrixunittest.hpp \126 124 gslvectorunittest.hpp \ 127 125 infounittest.hpp \ … … 132 130 logunittest.hpp \ 133 131 manipulateAtomsTest.hpp \ 132 MatrixContentSymmetricUnittest.hpp \ 133 MatrixContentUnittest.hpp \ 134 134 MatrixUnittest.hpp \ 135 135 MenuDescriptionUnitTest.hpp \ … … 187 187 FormulaUnittest_LDADD = ${ALLLIBS} 188 188 189 GSLMatrixSymmetricUnitTest_SOURCES = UnitTestMain.cpp gslmatrixsymmetricunittest.cpp gslmatrixsymmetricunittest.hpp 190 GSLMatrixSymmetricUnitTest_LDADD = ${ALLLIBS}191 192 GSLMatrixUnitTest_SOURCES = UnitTestMain.cpp gslmatrixunittest.cpp gslmatrixunittest.hpp193 GSLMatrixUnitTest_LDADD = ${ALLLIBS}189 MatrixContentSymmetricUnitTest_SOURCES = UnitTestMain.cpp MatrixContentSymmetricUnittest.cpp MatrixContentSymmetricUnittest 190 MatrixContentSymmetricUnitTest_LDADD = ${ALLLIBS} 191 192 MatrixContentUnitTest_SOURCES = UnitTestMain.cpp MatrixContentUnittest.cpp MatrixContentUnittest.hpp 193 MatrixContentUnitTest_LDADD = ${ALLLIBS} 194 194 195 195 GSLVectorUnitTest_SOURCES = UnitTestMain.cpp gslvectorunittest.cpp gslvectorunittest.hpp -
src/unittests/MatrixContentSymmetricUnittest.cpp
rcca9ef r0d4424 7 7 8 8 /* 9 * gslmatrixunittest.cpp9 * MatrixContentSymmetricUnittest.cpp 10 10 * 11 11 * Created on: Jan 8, 2010 … … 24 24 #include <cppunit/ui/text/TestRunner.h> 25 25 26 #include "gslmatrixsymmetricunittest.hpp" 26 #include "MatrixContentSymmetricUnittest.hpp" 27 28 #include "LinearAlgebra/MatrixContent.hpp" 27 29 28 30 #ifdef HAVE_TESTRUNNER … … 33 35 34 36 // Registers the fixture into the 'registry' 35 CPPUNIT_TEST_SUITE_REGISTRATION( GSLMatrixSymmetricTest );36 37 38 void GSLMatrixSymmetricTest::setUp()39 { 40 m = new GSLMatrix(3,3);41 }; 42 43 void GSLMatrixSymmetricTest::tearDown()37 CPPUNIT_TEST_SUITE_REGISTRATION( MatrixContentSymmetricTest ); 38 39 40 void MatrixContentSymmetricTest::setUp() 41 { 42 m = new MatrixContent(3,3); 43 }; 44 45 void MatrixContentSymmetricTest::tearDown() 44 46 { 45 47 delete(m); … … 49 51 * 50 52 */ 51 void GSLMatrixSymmetricTest::AccessTest()53 void MatrixContentSymmetricTest::AccessTest() 52 54 { 53 55 // check whether all elements are initially zero 54 56 for (int i=0;i<3;i++) 55 57 for (int j=0;j<3;j++) 56 CPPUNIT_ASSERT_EQUAL( 0., m-> Get(i,j) );58 CPPUNIT_ASSERT_EQUAL( 0., m->at(i,j) ); 57 59 58 60 // set 59 61 for (int i=0;i<3;i++) 60 62 for (int j=0;j<3;j++) 61 m-> Set(i,j, i*3+j );63 m->set(i,j, i*3+j ); 62 64 63 65 // and check … … 65 67 for (int i=0;i<3;i++) 66 68 for (int j=0;j<3;j++) { 67 CPPUNIT_ASSERT_EQUAL( (double)(i*3+j), m-> Get(i,j) );69 CPPUNIT_ASSERT_EQUAL( (double)(i*3+j), m->at(i,j) ); 68 70 ptr = m->Pointer(i,j); 69 71 CPPUNIT_ASSERT_EQUAL( (double)(i*3+j), *ptr ); … … 73 75 for (int i=0;i<3;i++) 74 76 for (int j=0;j<3;j++) 75 m-> Set(i,j, i*3+j );76 GSLMatrix *dest = new GSLMatrix(3,3);77 m->set(i,j, i*3+j ); 78 MatrixContent *dest = new MatrixContent(3,3); 77 79 *dest = *m; 78 80 for (int i=0;i<3;i++) 79 81 for (int j=0;j<3;j++) 80 CPPUNIT_ASSERT_EQUAL( dest-> Get(i,j), m->Get(i,j) );82 CPPUNIT_ASSERT_EQUAL( dest->at(i,j), m->at(i,j) ); 81 83 delete(dest); 82 84 83 85 // out of bounds 84 //CPPUNIT_ASSERT_EQUAL(0., v-> Get(4,2) );85 //CPPUNIT_ASSERT_EQUAL(0., v-> Get(2,17) );86 //CPPUNIT_ASSERT_EQUAL(0., v-> Get(1024,140040) );87 //CPPUNIT_ASSERT_EQUAL(0., v-> Get(-1,0) );88 //CPPUNIT_ASSERT_EQUAL(0., v-> Get(0,-1) );89 //CPPUNIT_ASSERT_EQUAL(0., v-> Get(-1,-1) );86 //CPPUNIT_ASSERT_EQUAL(0., v->at(4,2) ); 87 //CPPUNIT_ASSERT_EQUAL(0., v->at(2,17) ); 88 //CPPUNIT_ASSERT_EQUAL(0., v->at(1024,140040) ); 89 //CPPUNIT_ASSERT_EQUAL(0., v->at(-1,0) ); 90 //CPPUNIT_ASSERT_EQUAL(0., v->at(0,-1) ); 91 //CPPUNIT_ASSERT_EQUAL(0., v->at(-1,-1) ); 90 92 }; 91 93 … … 93 95 * 94 96 */ 95 void GSLMatrixSymmetricTest::InitializationTest()97 void MatrixContentSymmetricTest::InitializationTest() 96 98 { 97 99 // set zero 98 m-> SetZero();99 for (int i=0;i<3;i++) 100 for (int j=0;j<3;j++) 101 CPPUNIT_ASSERT_EQUAL( 0., m-> Get(i,j) );100 m->setZero(); 101 for (int i=0;i<3;i++) 102 for (int j=0;j<3;j++) 103 CPPUNIT_ASSERT_EQUAL( 0., m->at(i,j) ); 102 104 103 105 // set all 104 m-> SetAll(1.5);105 for (int i=0;i<3;i++) 106 for (int j=0;j<3;j++) 107 CPPUNIT_ASSERT_EQUAL( 1.5, m-> Get(i,j) );106 m->setValue(1.5); 107 for (int i=0;i<3;i++) 108 for (int j=0;j<3;j++) 109 CPPUNIT_ASSERT_EQUAL( 1.5, m->at(i,j) ); 108 110 109 111 // set basis 110 m-> SetIdentity();111 for (int i=0;i<3;i++) 112 for (int j=0;j<3;j++) 113 CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , m-> Get(i,j) );112 m->setIdentity(); 113 for (int i=0;i<3;i++) 114 for (int j=0;j<3;j++) 115 CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , m->at(i,j) ); 114 116 115 117 // set from array … … 117 119 0., 1., 0., 118 120 0., 0., 1. }; 119 m-> SetFromDoubleArray(array);120 for (int i=0;i<3;i++) 121 for (int j=0;j<3;j++) 122 CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , m-> Get(i,j) );121 m->setFromDoubleArray(array); 122 for (int i=0;i<3;i++) 123 for (int j=0;j<3;j++) 124 CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , m->at(i,j) ); 123 125 124 126 }; … … 127 129 * 128 130 */ 129 void GSLMatrixSymmetricTest::CopyTest()131 void MatrixContentSymmetricTest::CopyTest() 130 132 { 131 133 // set basis 132 GSLMatrix*dest = NULL;134 MatrixContent *dest = NULL; 133 135 for (int i=0;i<3;i++) { 134 m-> SetAll(i);135 dest = new GSLMatrix(m);136 for (int j=0;j<3;j++) 137 CPPUNIT_ASSERT_EQUAL( m-> Get(i,j) , dest->Get(i,j) );136 m->setValue(i); 137 dest = new MatrixContent(m); 138 for (int j=0;j<3;j++) 139 CPPUNIT_ASSERT_EQUAL( m->at(i,j) , dest->at(i,j) ); 138 140 139 141 delete(dest); … … 144 146 * 145 147 */ 146 void GSLMatrixSymmetricTest::ExchangeTest()148 void MatrixContentSymmetricTest::ExchangeTest() 147 149 { 148 150 // set to 1,1,1,2, ... 149 151 for (int i=0;i<3;i++) 150 152 for (int j=0;j<3;j++) 151 m-> Set(i,j, i+1 );153 m->set(i,j, i+1 ); 152 154 153 155 // swap such that nothing happens … … 155 157 for (int i=0;i<3;i++) 156 158 for (int j=0;j<3;j++) 157 CPPUNIT_ASSERT_EQUAL( (double)i+1., m-> Get(i,j) );159 CPPUNIT_ASSERT_EQUAL( (double)i+1., m->at(i,j) ); 158 160 159 161 // swap two rows … … 163 165 switch (j) { 164 166 case 0: 165 CPPUNIT_ASSERT_EQUAL( 1., m-> Get(j,i) );167 CPPUNIT_ASSERT_EQUAL( 1., m->at(j,i) ); 166 168 break; 167 169 case 1: 168 CPPUNIT_ASSERT_EQUAL( 3., m-> Get(j,i) );170 CPPUNIT_ASSERT_EQUAL( 3., m->at(j,i) ); 169 171 break; 170 172 case 2: 171 CPPUNIT_ASSERT_EQUAL( 2., m-> Get(j,i) );173 CPPUNIT_ASSERT_EQUAL( 2., m->at(j,i) ); 172 174 break; 173 175 default: 174 CPPUNIT_ASSERT_EQUAL( -1., m-> Get(i,j) );176 CPPUNIT_ASSERT_EQUAL( -1., m->at(i,j) ); 175 177 } 176 178 // check that op is reversable … … 178 180 for (int i=0;i<3;i++) 179 181 for (int j=0;j<3;j++) 180 CPPUNIT_ASSERT_EQUAL( (double)i+1., m-> Get(i,j) );182 CPPUNIT_ASSERT_EQUAL( (double)i+1., m->at(i,j) ); 181 183 182 184 // set to 1,2,3,1, ... 183 185 for (int i=0;i<3;i++) 184 186 for (int j=0;j<3;j++) 185 m-> Set(i,j, j+1. );187 m->set(i,j, j+1. ); 186 188 187 189 // swap such that nothing happens … … 189 191 for (int i=0;i<3;i++) 190 192 for (int j=0;j<3;j++) 191 CPPUNIT_ASSERT_EQUAL( (double)j+1., m-> Get(i,j) );193 CPPUNIT_ASSERT_EQUAL( (double)j+1., m->at(i,j) ); 192 194 193 195 // swap two columns … … 197 199 switch (j) { 198 200 case 0: 199 CPPUNIT_ASSERT_EQUAL( 3., m-> Get(i,j) );201 CPPUNIT_ASSERT_EQUAL( 3., m->at(i,j) ); 200 202 break; 201 203 case 1: 202 CPPUNIT_ASSERT_EQUAL( 2., m-> Get(i,j) );204 CPPUNIT_ASSERT_EQUAL( 2., m->at(i,j) ); 203 205 break; 204 206 case 2: 205 CPPUNIT_ASSERT_EQUAL( 1., m-> Get(i,j) );207 CPPUNIT_ASSERT_EQUAL( 1., m->at(i,j) ); 206 208 break; 207 209 default: 208 CPPUNIT_ASSERT_EQUAL( -1., m-> Get(i,j) );210 CPPUNIT_ASSERT_EQUAL( -1., m->at(i,j) ); 209 211 } 210 212 // check that op is reversable … … 212 214 for (int i=0;i<3;i++) 213 215 for (int j=0;j<3;j++) 214 CPPUNIT_ASSERT_EQUAL( (double)j+1., m->Get(i,j) ); 215 216 217 // set to 1,2,3,4, ... 218 for (int i=0;i<3;i++) 219 for (int j=0;j<3;j++) 220 m->Set(i,j, 3*i+j+1 ); 216 CPPUNIT_ASSERT_EQUAL( (double)j+1., m->at(i,j) ); 217 218 219 // set to 1,2,3, ... 220 MatrixContent *n = new MatrixContent(3,3); 221 for (int i=0;i<3;i++) 222 for (int j=0;j<3;j++) { 223 m->set(i,j, 3*i+j+1 ); 224 n->set(i,j, 3*j+i+1 ); 225 } 221 226 // transpose 222 m->Transpose(); 223 for (int i=0;i<3;i++) 224 for (int j=0;j<3;j++) 225 CPPUNIT_ASSERT_EQUAL( (double)(3*i+j+1), m->Get(j,i) ); 227 MatrixContent res = ((const MatrixContent)*m).transpose(); 228 CPPUNIT_ASSERT( *n == res ); 226 229 // second transpose 227 m->Transpose(); 228 for (int i=0;i<3;i++) 229 for (int j=0;j<3;j++) 230 CPPUNIT_ASSERT_EQUAL( (double)(3*i+j+1), m->Get(i,j) ); 230 res.transpose(); 231 CPPUNIT_ASSERT( *m == res ); 231 232 }; 232 233 … … 234 235 * 235 236 */ 236 void GSLMatrixSymmetricTest::PropertiesTest()237 void MatrixContentSymmetricTest::PropertiesTest() 237 238 { 238 239 // is zero 239 m-> SetZero();240 m->setZero(); 240 241 CPPUNIT_ASSERT_EQUAL( true, m->IsNull() ); 241 242 CPPUNIT_ASSERT_EQUAL( false, m->IsPositive() ); … … 244 245 245 246 // is positive 246 m-> SetAll(0.5);247 m->setValue(0.5); 247 248 CPPUNIT_ASSERT_EQUAL( false, m->IsNull() ); 248 249 CPPUNIT_ASSERT_EQUAL( true, m->IsPositive() ); … … 251 252 252 253 // is negative 253 m-> SetAll(-0.1);254 m->setValue(-0.1); 254 255 CPPUNIT_ASSERT_EQUAL( false, m->IsNull() ); 255 256 CPPUNIT_ASSERT_EQUAL( false, m->IsPositive() ); … … 261 262 0., 1., 1., 262 263 0., 0., 1. }; 263 m-> SetFromDoubleArray(array);264 m->setFromDoubleArray(array); 264 265 CPPUNIT_ASSERT_EQUAL( true, m->IsPositiveDefinite() ); 265 266 266 267 //determinant 267 m-> SetIdentity();268 m->setIdentity(); 268 269 CPPUNIT_ASSERT_EQUAL( 1., m->Determinant() ); 269 270 270 m-> SetZero();271 m->setZero(); 271 272 CPPUNIT_ASSERT_EQUAL( 0., m->Determinant() ); 272 273 273 m-> Set( 0, 0, 1.);274 m-> Set( 1, 1, 1.);275 m-> Set( 2, 1, 1.);274 m->set( 0, 0, 1.); 275 m->set( 1, 1, 1.); 276 m->set( 2, 1, 1.); 276 277 CPPUNIT_ASSERT_EQUAL( 0., m->Determinant() ); 277 278 … … 279 280 -3., 1., 1., 280 281 1., 5.5, 1. }; 281 m-> SetFromDoubleArray(array2);282 m->setFromDoubleArray(array2); 282 283 CPPUNIT_ASSERT_EQUAL( -26.5, m->Determinant() ); 283 284 }; -
src/unittests/MatrixContentSymmetricUnittest.hpp
rcca9ef r0d4424 1 1 /* 2 * gslmatrixunittest.hpp2 * MatrixContentSymmetricUnittest.hpp 3 3 * 4 4 * Created on: Jan 8, 2010 … … 6 6 */ 7 7 8 #ifndef GSLMATRIXUNITTEST_HPP_9 #define GSLMATRIXUNITTEST_HPP_8 #ifndef MATRIXCONTENTSYMMETRICUNITTEST_HPP_ 9 #define MATRIXCONTENTSYMMETRICUNITTEST_HPP_ 10 10 11 11 #include <cppunit/extensions/HelperMacros.h> 12 12 13 #include "LinearAlgebra/gslmatrix.hpp" 13 class MatrixContent; 14 14 15 15 /********************************************** Test classes **************************************/ 16 16 17 class GSLMatrixSymmetricTest : public CppUnit::TestFixture17 class MatrixContentSymmetricTest : public CppUnit::TestFixture 18 18 { 19 CPPUNIT_TEST_SUITE( GSLMatrixSymmetricTest) ;19 CPPUNIT_TEST_SUITE( MatrixContentSymmetricTest) ; 20 20 CPPUNIT_TEST (AccessTest ); 21 21 CPPUNIT_TEST (InitializationTest ); … … 36 36 37 37 private: 38 GSLMatrix*m;38 MatrixContent *m; 39 39 }; 40 40 41 41 42 #endif /* GSLMATRIXUNITTEST_HPP_ */42 #endif /* MATRIXCONTENTSYMMETRICUNITTEST_HPP_ */ -
src/unittests/MatrixContentUnittest.cpp
rcca9ef r0d4424 7 7 8 8 /* 9 * gslmatrixunittest.cpp9 * MatrixContentUnittest.cpp 10 10 * 11 11 * Created on: Jan 8, 2010 … … 24 24 #include <cppunit/ui/text/TestRunner.h> 25 25 26 #include "gslmatrixunittest.hpp" 26 #include "MatrixContentUnittest.hpp" 27 28 #include "LinearAlgebra/MatrixContent.hpp" 27 29 28 30 #ifdef HAVE_TESTRUNNER … … 33 35 34 36 // Registers the fixture into the 'registry' 35 CPPUNIT_TEST_SUITE_REGISTRATION( GSLMatrixTest );36 37 38 void GSLMatrixTest::setUp()39 { 40 m = new GSLMatrix(4,3);41 }; 42 43 void GSLMatrixTest::tearDown()37 CPPUNIT_TEST_SUITE_REGISTRATION( MatrixContentTest ); 38 39 40 void MatrixContentTest::setUp() 41 { 42 m = new MatrixContent(4,3); 43 }; 44 45 void MatrixContentTest::tearDown() 44 46 { 45 47 delete(m); … … 49 51 * 50 52 */ 51 void GSLMatrixTest::AccessTest()53 void MatrixContentTest::AccessTest() 52 54 { 53 55 // check whether all elements are initially zero 54 56 for (int i=0;i<4;i++) 55 57 for (int j=0;j<3;j++) 56 CPPUNIT_ASSERT_EQUAL( 0., m-> Get(i,j) );58 CPPUNIT_ASSERT_EQUAL( 0., m->at(i,j) ); 57 59 58 60 // set 59 61 for (int i=0;i<4;i++) 60 62 for (int j=0;j<3;j++) 61 m-> Set(i,j, i*3+j );63 m->set(i,j, i*3+j ); 62 64 63 65 // and check … … 65 67 for (int i=0;i<4;i++) 66 68 for (int j=0;j<3;j++) { 67 CPPUNIT_ASSERT_EQUAL( (double)(i*3+j), m-> Get(i,j) );69 CPPUNIT_ASSERT_EQUAL( (double)(i*3+j), m->at(i,j) ); 68 70 ptr = m->Pointer(i,j); 69 71 CPPUNIT_ASSERT_EQUAL( (double)(i*3+j), *ptr ); … … 73 75 for (int i=0;i<4;i++) 74 76 for (int j=0;j<3;j++) 75 m-> Set(i,j, i*3+j );76 GSLMatrix *dest = new GSLMatrix(4,3);77 m->set(i,j, i*3+j ); 78 MatrixContent *dest = new MatrixContent(4,3); 77 79 *dest = *m; 78 80 for (int i=0;i<4;i++) 79 81 for (int j=0;j<3;j++) 80 CPPUNIT_ASSERT_EQUAL( dest-> Get(i,j), m->Get(i,j) );82 CPPUNIT_ASSERT_EQUAL( dest->at(i,j), m->at(i,j) ); 81 83 delete(dest); 82 84 83 85 // out of bounds 84 //CPPUNIT_ASSERT_EQUAL(0., v-> Get(5,2) );85 //CPPUNIT_ASSERT_EQUAL(0., v-> Get(2,17) );86 //CPPUNIT_ASSERT_EQUAL(0., v-> Get(1024,140040) );87 //CPPUNIT_ASSERT_EQUAL(0., v-> Get(-1,0) );88 //CPPUNIT_ASSERT_EQUAL(0., v-> Get(0,-1) );89 //CPPUNIT_ASSERT_EQUAL(0., v-> Get(-1,-1) );86 //CPPUNIT_ASSERT_EQUAL(0., v->at(5,2) ); 87 //CPPUNIT_ASSERT_EQUAL(0., v->at(2,17) ); 88 //CPPUNIT_ASSERT_EQUAL(0., v->at(1024,140040) ); 89 //CPPUNIT_ASSERT_EQUAL(0., v->at(-1,0) ); 90 //CPPUNIT_ASSERT_EQUAL(0., v->at(0,-1) ); 91 //CPPUNIT_ASSERT_EQUAL(0., v->at(-1,-1) ); 90 92 }; 91 93 … … 93 95 * 94 96 */ 95 void GSLMatrixTest::InitializationTest()97 void MatrixContentTest::InitializationTest() 96 98 { 97 99 // set zero 98 m-> SetZero();99 for (int i=0;i<4;i++) 100 for (int j=0;j<3;j++) 101 CPPUNIT_ASSERT_EQUAL( 0., m-> Get(i,j) );100 m->setZero(); 101 for (int i=0;i<4;i++) 102 for (int j=0;j<3;j++) 103 CPPUNIT_ASSERT_EQUAL( 0., m->at(i,j) ); 102 104 103 105 // set all 104 m-> SetAll(1.5);105 for (int i=0;i<4;i++) 106 for (int j=0;j<3;j++) 107 CPPUNIT_ASSERT_EQUAL( 1.5, m-> Get(i,j) );106 m->setValue(1.5); 107 for (int i=0;i<4;i++) 108 for (int j=0;j<3;j++) 109 CPPUNIT_ASSERT_EQUAL( 1.5, m->at(i,j) ); 108 110 109 111 // set basis 110 m-> SetIdentity();111 for (int i=0;i<4;i++) 112 for (int j=0;j<3;j++) 113 CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , m-> Get(i,j) );112 m->setIdentity(); 113 for (int i=0;i<4;i++) 114 for (int j=0;j<3;j++) 115 CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , m->at(i,j) ); 114 116 115 117 // set from array … … 118 120 0., 0., 1., 119 121 0., 0., 0. }; 120 m-> SetFromDoubleArray(array);121 for (int i=0;i<4;i++) 122 for (int j=0;j<3;j++) 123 CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , m-> Get(i,j) );122 m->setFromDoubleArray(array); 123 for (int i=0;i<4;i++) 124 for (int j=0;j<3;j++) 125 CPPUNIT_ASSERT_EQUAL( i == j ? 1. : 0. , m->at(i,j) ); 124 126 125 127 }; … … 128 130 * 129 131 */ 130 void GSLMatrixTest::CopyTest()132 void MatrixContentTest::CopyTest() 131 133 { 132 134 // set basis 133 GSLMatrix*dest = NULL;135 MatrixContent *dest = NULL; 134 136 for (int i=0;i<4;i++) { 135 m-> SetAll(i);136 dest = new GSLMatrix(m);137 for (int j=0;j<3;j++) 138 CPPUNIT_ASSERT_EQUAL( m-> Get(i,j) , dest->Get(i,j) );137 m->setValue(i); 138 dest = new MatrixContent(m); 139 for (int j=0;j<3;j++) 140 CPPUNIT_ASSERT_EQUAL( m->at(i,j) , dest->at(i,j) ); 139 141 140 142 delete(dest); … … 145 147 * 146 148 */ 147 void GSLMatrixTest::ExchangeTest()149 void MatrixContentTest::ExchangeTest() 148 150 { 149 151 // set to 1,1,1,2, ... 150 152 for (int i=0;i<4;i++) 151 153 for (int j=0;j<3;j++) 152 m-> Set(i,j, i+1 );154 m->set(i,j, i+1 ); 153 155 154 156 // swap such that nothing happens … … 156 158 for (int i=0;i<4;i++) 157 159 for (int j=0;j<3;j++) 158 CPPUNIT_ASSERT_EQUAL( (double)i+1., m-> Get(i,j) );160 CPPUNIT_ASSERT_EQUAL( (double)i+1., m->at(i,j) ); 159 161 160 162 // swap two rows … … 164 166 switch (i) { 165 167 case 0: 166 CPPUNIT_ASSERT_EQUAL( 1., m-> Get(i,j) );168 CPPUNIT_ASSERT_EQUAL( 1., m->at(i,j) ); 167 169 break; 168 170 case 1: 169 CPPUNIT_ASSERT_EQUAL( 3., m-> Get(i,j) );171 CPPUNIT_ASSERT_EQUAL( 3., m->at(i,j) ); 170 172 break; 171 173 case 2: 172 CPPUNIT_ASSERT_EQUAL( 2., m-> Get(i,j) );174 CPPUNIT_ASSERT_EQUAL( 2., m->at(i,j) ); 173 175 break; 174 176 case 3: 175 CPPUNIT_ASSERT_EQUAL( 4., m-> Get(i,j) );177 CPPUNIT_ASSERT_EQUAL( 4., m->at(i,j) ); 176 178 break; 177 179 default: 178 CPPUNIT_ASSERT_EQUAL( -1., m-> Get(i,j) );180 CPPUNIT_ASSERT_EQUAL( -1., m->at(i,j) ); 179 181 } 180 182 // check that op is reversable … … 182 184 for (int i=0;i<4;i++) 183 185 for (int j=0;j<3;j++) 184 CPPUNIT_ASSERT_EQUAL( (double)i+1., m-> Get(i,j) );186 CPPUNIT_ASSERT_EQUAL( (double)i+1., m->at(i,j) ); 185 187 186 188 // set to 1,2,3,1, ... 187 189 for (int i=0;i<4;i++) 188 190 for (int j=0;j<3;j++) 189 m-> Set(i,j, j+1. );191 m->set(i,j, j+1. ); 190 192 191 193 // swap such that nothing happens … … 193 195 for (int i=0;i<4;i++) 194 196 for (int j=0;j<3;j++) 195 CPPUNIT_ASSERT_EQUAL( (double)j+1., m-> Get(i,j) );197 CPPUNIT_ASSERT_EQUAL( (double)j+1., m->at(i,j) ); 196 198 197 199 // swap two columns … … 201 203 switch (j) { 202 204 case 0: 203 CPPUNIT_ASSERT_EQUAL( 3., m-> Get(i,j) );205 CPPUNIT_ASSERT_EQUAL( 3., m->at(i,j) ); 204 206 break; 205 207 case 1: 206 CPPUNIT_ASSERT_EQUAL( 2., m-> Get(i,j) );208 CPPUNIT_ASSERT_EQUAL( 2., m->at(i,j) ); 207 209 break; 208 210 case 2: 209 CPPUNIT_ASSERT_EQUAL( 1., m-> Get(i,j) );211 CPPUNIT_ASSERT_EQUAL( 1., m->at(i,j) ); 210 212 break; 211 213 default: 212 CPPUNIT_ASSERT_EQUAL( -1., m-> Get(i,j) );214 CPPUNIT_ASSERT_EQUAL( -1., m->at(i,j) ); 213 215 } 214 216 // check that op is reversable … … 216 218 for (int i=0;i<4;i++) 217 219 for (int j=0;j<3;j++) 218 CPPUNIT_ASSERT_EQUAL( (double)j+1., m-> Get(i,j) );220 CPPUNIT_ASSERT_EQUAL( (double)j+1., m->at(i,j) ); 219 221 220 222 221 223 // set to 1,2,3,4, ... 222 for (int i=0;i<4;i++) 223 for (int j=0;j<3;j++) 224 m->Set(i,j, 3*i+j+1 ); 224 MatrixContent *n = new MatrixContent(3,4); 225 for (int i=0;i<4;i++) 226 for (int j=0;j<3;j++) { 227 m->set(i,j, 3*i+j+1 ); 228 n->set(j,i, 3*i+j+1 ); 229 } 225 230 // transpose 226 CPPUNIT_ASSERT_EQUAL( true, m->Transpose() ); 227 for (int i=0;i<4;i++) 228 for (int j=0;j<3;j++) 229 CPPUNIT_ASSERT_EQUAL( (double)(3*i+j+1), m->Get(j,i) ); 231 MatrixContent res = ((const MatrixContent)(*m)).transpose(); 232 CPPUNIT_ASSERT( *n == res ); 230 233 // second transpose 231 CPPUNIT_ASSERT_EQUAL( true, m->Transpose() ); 232 for (int i=0;i<4;i++) 233 for (int j=0;j<3;j++) 234 CPPUNIT_ASSERT_EQUAL( (double)(3*i+j+1), m->Get(i,j) ); 234 MatrixContent res2 = ((const MatrixContent)res).transpose(); 235 CPPUNIT_ASSERT( *m == res2 ); 235 236 }; 236 237 … … 238 239 * 239 240 */ 240 void GSLMatrixTest::PropertiesTest()241 void MatrixContentTest::PropertiesTest() 241 242 { 242 243 // is zero 243 m-> SetZero();244 m->setZero(); 244 245 CPPUNIT_ASSERT_EQUAL( true, m->IsNull() ); 245 246 CPPUNIT_ASSERT_EQUAL( false, m->IsPositive() ); … … 248 249 249 250 // is positive 250 m-> SetAll(0.5);251 m->setValue(0.5); 251 252 CPPUNIT_ASSERT_EQUAL( false, m->IsNull() ); 252 253 CPPUNIT_ASSERT_EQUAL( true, m->IsPositive() ); … … 255 256 256 257 // is negative 257 m-> SetAll(-0.1);258 m->setValue(-0.1); 258 259 CPPUNIT_ASSERT_EQUAL( false, m->IsNull() ); 259 260 CPPUNIT_ASSERT_EQUAL( false, m->IsPositive() ); -
src/unittests/MatrixContentUnittest.hpp
rcca9ef r0d4424 1 1 /* 2 * gslmatrixunittest.hpp2 * MatrixContentUnittest.hpp 3 3 * 4 4 * Created on: Jan 8, 2010 … … 6 6 */ 7 7 8 #ifndef GSLMATRIXUNITTEST_HPP_9 #define GSLMATRIXUNITTEST_HPP_8 #ifndef MATRIXCONTENTUNITTEST_HPP_ 9 #define MATRIXCONTENTUNITTEST_HPP_ 10 10 11 11 #include <cppunit/extensions/HelperMacros.h> 12 12 13 #include "LinearAlgebra/gslmatrix.hpp" 13 class MatrixContent; 14 14 15 15 /********************************************** Test classes **************************************/ 16 16 17 class GSLMatrixTest : public CppUnit::TestFixture17 class MatrixContentTest : public CppUnit::TestFixture 18 18 { 19 CPPUNIT_TEST_SUITE( GSLMatrixTest) ;19 CPPUNIT_TEST_SUITE( MatrixContentTest) ; 20 20 CPPUNIT_TEST (AccessTest ); 21 21 CPPUNIT_TEST (InitializationTest ); … … 36 36 37 37 private: 38 GSLMatrix*m;38 MatrixContent *m; 39 39 }; 40 40 41 41 42 #endif /* GSLMATRIXUNITTEST_HPP_ */42 #endif /* MATRIXCONTENTUNITTEST_HPP_ */
Note:
See TracChangeset
for help on using the changeset viewer.