| 1 | #include "brains/DataStorageTestCase.hpp" | 
| 2 | // Registers the fixture into the 'registry' | 
| 3 | CPPUNIT_TEST_SUITE_REGISTRATION( DataStorageTestCase ); | 
| 4 |  | 
| 5 | void DataStorageTestCase::testDataStorage() { | 
| 6 | //test constructor | 
| 7 | DataStorage ds1(10020); | 
| 8 | CPPUNIT_ASSERT_EQUAL(ds1.getStorageLayout(), 0x11111111); | 
| 9 | CPPUNIT_ASSERT_EQUAL(ds1.getSize(), 10020); | 
| 10 |  | 
| 11 | //test resize | 
| 12 | ds1.resize(56); | 
| 13 | CPPUNIT_ASSERT_EQUAL(ds1.getSize(), 56); | 
| 14 |  | 
| 15 | //test reserve | 
| 16 |  | 
| 17 | DataStorage ds2(10000, DataStorage::dslForce |DataStorage::dslAmat |DataStorage::dslZAngle); | 
| 18 |  | 
| 19 | CPPUNIT_ASSERT(!(ds2.getStorageLayout() & DataStorage::dslPosition)); | 
| 20 | CPPUNIT_ASSERT(!(ds2.getStorageLayout() & DataStorage::dslVelocity)); | 
| 21 | CPPUNIT_ASSERT(ds2.getStorageLayout() & DataStorage::dslAmat); | 
| 22 | CPPUNIT_ASSERT(!(ds2.getStorageLayout() & DataStorage::dslAngularMomentum)); | 
| 23 | CPPUNIT_ASSERT(!(ds2.getStorageLayout() & DataStorage::dslUnitVector)); | 
| 24 | CPPUNIT_ASSERT(ds2.getStorageLayout() & DataStorage::dslZAngle); | 
| 25 | CPPUNIT_ASSERT(ds2.getStorageLayout() & DataStorage::dslForce); | 
| 26 | CPPUNIT_ASSERT(!(ds2.getStorageLayout() & DataStorage::dslTorque)); | 
| 27 |  | 
| 28 |  | 
| 29 | CPPUNIT_ASSERT(ds2.position.size() == 0); | 
| 30 | CPPUNIT_ASSERT(ds2.velocity.size() == 0); | 
| 31 | CPPUNIT_ASSERT(ds2.aMat.size() == 10000); | 
| 32 | CPPUNIT_ASSERT(ds2.angularMomentum.size() == 0); | 
| 33 | CPPUNIT_ASSERT(ds2.unitVector.size() == 0); | 
| 34 | CPPUNIT_ASSERT(ds2.zAngle.size() == 10000); | 
| 35 | CPPUNIT_ASSERT(ds2.force.size() == 10000); | 
| 36 | CPPUNIT_ASSERT(ds2.torque.size() == 0); | 
| 37 |  | 
| 38 | //test getArrayPointer | 
| 39 |  | 
| 40 | double* pamat = ds2.getArrayPointer(DataStorage::dslAmat); | 
| 41 | double* pzangle = ds2.getArrayPointer(DataStorage::dslZAngle); | 
| 42 | double* pforce = ds2.getArrayPointer(DataStorage::dslForce); | 
| 43 |  | 
| 44 | pamat[9] = 2.0993; | 
| 45 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[1](0,0), 2.0993, OpenMD::NumericConstant::epsilon); | 
| 46 |  | 
| 47 | pzangle[9743] = 8464353.129574; | 
| 48 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.zAngle[9743], 8464353.129574, OpenMD::NumericConstant::epsilon); | 
| 49 |  | 
| 50 | pforce[12] = 345546.3413263; | 
| 51 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.force[4][0], 345546.3413263, OpenMD::NumericConstant::epsilon); | 
| 52 |  | 
| 53 | //test copy | 
| 54 | ds2.zAngle[0] = 7.0; | 
| 55 | ds2.zAngle[1] = 3.5; | 
| 56 |  | 
| 57 | ds2.force[0][0]= 6; | 
| 58 | ds2.force[0][1]= 7.0; | 
| 59 | ds2.force[0][2]= 8.0; | 
| 60 |  | 
| 61 | ds2.force[1][0]= 9.0; | 
| 62 | ds2.force[1][1]= 10.0; | 
| 63 | ds2.force[1][2]= 11.0; | 
| 64 |  | 
| 65 | ds2.aMat[0](0,0) = 1.0; | 
| 66 | ds2.aMat[0](0,1) = 2.0; | 
| 67 | ds2.aMat[0](0,2) = 3.0; | 
| 68 | ds2.aMat[0](1,0) = 4.0; | 
| 69 | ds2.aMat[0](1,1) = 5.0; | 
| 70 | ds2.aMat[0](1,2) = 6.0; | 
| 71 | ds2.aMat[0](2,0) = 7.0; | 
| 72 | ds2.aMat[0](2,1) = 8.0; | 
| 73 | ds2.aMat[0](2,2) = 9.0; | 
| 74 |  | 
| 75 | ds2.aMat[1](0,0) = 11.0; | 
| 76 | ds2.aMat[1](0,1) = 12.0; | 
| 77 | ds2.aMat[1](0,2) = 13.0; | 
| 78 | ds2.aMat[1](1,0) = 14.0; | 
| 79 | ds2.aMat[1](1,1) = 15.0; | 
| 80 | ds2.aMat[1](1,2) = 16.0; | 
| 81 | ds2.aMat[1](2,0) = 17.0; | 
| 82 | ds2.aMat[1](2,1) = 18.0; | 
| 83 | ds2.aMat[1](2,2) = 19.0; | 
| 84 |  | 
| 85 | ds2.copy(0, 2, 10); | 
| 86 |  | 
| 87 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.zAngle[10], 7.0, OpenMD::NumericConstant::epsilon); | 
| 88 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.zAngle[11], 3.5, OpenMD::NumericConstant::epsilon); | 
| 89 |  | 
| 90 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.force[10][0], 6.0, OpenMD::NumericConstant::epsilon); | 
| 91 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.force[10][1], 7.0, OpenMD::NumericConstant::epsilon); | 
| 92 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.force[10][2], 8.0, OpenMD::NumericConstant::epsilon); | 
| 93 |  | 
| 94 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.force[11][0], 9.0, OpenMD::NumericConstant::epsilon); | 
| 95 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.force[11][1], 10.0, OpenMD::NumericConstant::epsilon); | 
| 96 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.force[11][2], 11.0, OpenMD::NumericConstant::epsilon); | 
| 97 |  | 
| 98 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[10](0, 0), 1.0, OpenMD::NumericConstant::epsilon); | 
| 99 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[10](0, 1), 2.0, OpenMD::NumericConstant::epsilon); | 
| 100 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[10](0, 2), 3.0, OpenMD::NumericConstant::epsilon); | 
| 101 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[10](1, 0), 4.0, OpenMD::NumericConstant::epsilon); | 
| 102 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[10](1, 1) , 5.0, OpenMD::NumericConstant::epsilon); | 
| 103 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[10](1, 2), 6.0, OpenMD::NumericConstant::epsilon); | 
| 104 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[10](2, 0), 7.0, OpenMD::NumericConstant::epsilon); | 
| 105 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[10](2, 1), 8.0, OpenMD::NumericConstant::epsilon); | 
| 106 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[10](2, 2), 9.0, OpenMD::NumericConstant::epsilon); | 
| 107 |  | 
| 108 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[11](0, 0), 11.0, OpenMD::NumericConstant::epsilon); | 
| 109 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[11](0, 1), 12.0, OpenMD::NumericConstant::epsilon); | 
| 110 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[11](0, 2), 13.0, OpenMD::NumericConstant::epsilon); | 
| 111 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[11](1, 0), 14.0, OpenMD::NumericConstant::epsilon); | 
| 112 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[11](1, 1) , 15.0, OpenMD::NumericConstant::epsilon); | 
| 113 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[11](1, 2), 16.0, OpenMD::NumericConstant::epsilon); | 
| 114 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[11](2, 0), 17.0, OpenMD::NumericConstant::epsilon); | 
| 115 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[11](2, 1), 18.0, OpenMD::NumericConstant::epsilon); | 
| 116 | CPPUNIT_ASSERT_DOUBLES_EQUAL(ds2.aMat[11](2, 2), 19.0, OpenMD::NumericConstant::epsilon); | 
| 117 |  | 
| 118 |  | 
| 119 | } | 
| 120 |  |