Changeset bd8b57 for src/Fragmentation/Summation/SetValues/unittests
- Timestamp:
- Oct 8, 2016, 7:25:46 PM (9 years ago)
- Branches:
- Add_FitFragmentPartialChargesAction, Fix_ChargeSampling_PBC, Fix_FitPartialCharges
- Children:
- f5d635
- Parents:
- e08108
- git-author:
- Frederik Heber <heber@…> (06/12/16 14:28:29)
- git-committer:
- Frederik Heber <heber@…> (10/08/16 19:25:46)
- Location:
- src/Fragmentation/Summation/SetValues/unittests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Fragmentation/Summation/SetValues/unittests/IndexedVectorsUnitTest.cpp
re08108 rbd8b57 47 47 #include <boost/assign.hpp> 48 48 49 50 49 #include "CodePatterns/Assert.hpp" 51 50 … … 68 67 69 68 // create two vector_t 70 ones += 1.,1.,1.;71 twos += 2.,2.,2.;72 threes += 3.,3.,3.;73 CPPUNIT_ASSERT_EQUAL( IndexedVectors:: FixedSize, ones.size() );74 CPPUNIT_ASSERT_EQUAL( IndexedVectors:: FixedSize, twos.size() );75 CPPUNIT_ASSERT_EQUAL( IndexedVectors:: FixedSize, threes.size() );76 77 // create v ectors78 79 IndexedVectors::v ectors_t vectors;80 v ectors.push_back(ones);81 v ectors.push_back(twos);82 IndexedVectors::v ectors_t othervectors;83 otherv ectors.push_back(threes);84 otherv ectors.push_back(threes);69 ones(1.,1.,1.); 70 twos(2.,2.,2.); 71 threes(3.,3.,3.); 72 CPPUNIT_ASSERT_EQUAL( IndexedVectors::value_t::FixedSize, ones.size() ); 73 CPPUNIT_ASSERT_EQUAL( IndexedVectors::value_t::FixedSize, twos.size() ); 74 CPPUNIT_ASSERT_EQUAL( IndexedVectors::value_t::FixedSize, threes.size() ); 75 76 // create values 77 78 IndexedVectors::values_t values; 79 values.push_back(ones); 80 values.push_back(twos); 81 IndexedVectors::values_t othervalues; 82 othervalues.push_back(threes); 83 othervalues.push_back(threes); 85 84 86 85 // create two indices … … 90 89 otherindices += 1,3; 91 90 92 // create indexed v ectors93 ivectors = new IndexedVectors(indices, v ectors);94 otherivectors = new IndexedVectors(otherindices, otherv ectors);91 // create indexed values 92 ivectors = new IndexedVectors(indices, values); 93 otherivectors = new IndexedVectors(otherindices, othervalues); 95 94 } 96 95 … … 102 101 } 103 102 103 static void checkValueInIndexedVectors( 104 const IndexedVectors &_vectors, 105 const IndexedVectors::index_t &_index, 106 const IndexedVectors::value_t &_compareto 107 ) 108 { 109 const IndexedVectors::indexedvalues_t &indexedvalues = _vectors.getValues(); 110 IndexedVectors::indexedvalues_t::const_iterator iter = indexedvalues.find(_index); 111 CPPUNIT_ASSERT( iter != indexedvalues.end() ); 112 CPPUNIT_ASSERT( _compareto == iter->second ); 113 } 104 114 105 115 /** UnitTest for cstor's … … 110 120 IndexedVectors::indices_t indices; 111 121 indices += 1,-1,3; 112 IndexedVectors::v ectors_t vectors;113 v ectors.push_back(ones);114 v ectors.push_back(twos);115 v ectors.push_back(threes);116 IndexedVectors testivectors(indices, v ectors);117 118 CPPUNIT_ASSERT_EQUAL( (size_t)2, testivectors. vectors.size() );119 CPPUNIT_ASSERT( ones == testivectors.vectors[1]);120 CPPUNIT_ASSERT( threes == testivectors.vectors[3]);121 CPPUNIT_ASSERT( testivectors. vectors.find(-1) == testivectors.vectors.end() );122 IndexedVectors::values_t values; 123 values.push_back(ones); 124 values.push_back(twos); 125 values.push_back(threes); 126 IndexedVectors testivectors(indices, values); 127 128 CPPUNIT_ASSERT_EQUAL( (size_t)2, testivectors.getValues().size() ); 129 checkValueInIndexedVectors(testivectors, 1, ones); 130 checkValueInIndexedVectors(testivectors, 3, threes); 131 CPPUNIT_ASSERT( testivectors.getValues().find(-1) == testivectors.getValues().end() ); 122 132 } 123 133 … … 127 137 { 128 138 // safeguard initial sizes 129 CPPUNIT_ASSERT_EQUAL( (size_t)2, ivectors-> vectors.size() );130 CPPUNIT_ASSERT_EQUAL( (size_t)2, otherivectors-> vectors.size() );139 CPPUNIT_ASSERT_EQUAL( (size_t)2, ivectors->getValues().size() ); 140 CPPUNIT_ASSERT_EQUAL( (size_t)2, otherivectors->getValues().size() ); 131 141 132 142 // perform operation … … 134 144 135 145 // check new and ole sizes 136 CPPUNIT_ASSERT_EQUAL( (size_t)3, ivectors-> vectors.size() );137 CPPUNIT_ASSERT_EQUAL( (size_t)2, otherivectors-> vectors.size() );146 CPPUNIT_ASSERT_EQUAL( (size_t)3, ivectors->getValues().size() ); 147 CPPUNIT_ASSERT_EQUAL( (size_t)2, otherivectors->getValues().size() ); 138 148 139 149 // then check result 140 IndexedVectors::v ector_t result( IndexedVectors::nullvector );141 CPPUNIT_ASSERT_EQUAL( IndexedVectors:: FixedSize, result.size() );142 for (size_t i=0; i<IndexedVectors:: FixedSize; ++i)150 IndexedVectors::value_t result; 151 CPPUNIT_ASSERT_EQUAL( IndexedVectors::value_t::FixedSize, result.size() ); 152 for (size_t i=0; i<IndexedVectors::value_t::FixedSize; ++i) 143 153 result[i] = ones[i] + threes[i]; 144 for (IndexedVectors::indexedv ectors_t::const_iterator iter = ivectors->vectors.begin();145 iter != ivectors-> vectors.end(); ++iter) {146 CPPUNIT_ASSERT_EQUAL( IndexedVectors:: FixedSize, iter->second.size() );154 for (IndexedVectors::indexedvalues_t::const_iterator iter = ivectors->getValues().begin(); 155 iter != ivectors->getValues().end(); ++iter) { 156 CPPUNIT_ASSERT_EQUAL( IndexedVectors::value_t::FixedSize, iter->second.size() ); 147 157 } 148 CPPUNIT_ASSERT( result == ivectors->vectors[1]);149 CPPUNIT_ASSERT( twos == ivectors->vectors[2]);150 CPPUNIT_ASSERT( threes == ivectors->vectors[3]);158 checkValueInIndexedVectors(*ivectors, 1, result); 159 checkValueInIndexedVectors(*ivectors, 2, twos); 160 checkValueInIndexedVectors(*ivectors, 3, threes); 151 161 } 152 162 … … 156 166 { 157 167 // safeguard initial sizes 158 CPPUNIT_ASSERT_EQUAL( (size_t)2, ivectors-> vectors.size() );159 CPPUNIT_ASSERT_EQUAL( (size_t)2, otherivectors-> vectors.size() );168 CPPUNIT_ASSERT_EQUAL( (size_t)2, ivectors->getValues().size() ); 169 CPPUNIT_ASSERT_EQUAL( (size_t)2, otherivectors->getValues().size() ); 160 170 161 171 // perform operation … … 163 173 164 174 // check new and ole sizes 165 CPPUNIT_ASSERT_EQUAL( (size_t)3, ivectors-> vectors.size() );166 CPPUNIT_ASSERT_EQUAL( (size_t)2, otherivectors-> vectors.size() );175 CPPUNIT_ASSERT_EQUAL( (size_t)3, ivectors->getValues().size() ); 176 CPPUNIT_ASSERT_EQUAL( (size_t)2, otherivectors->getValues().size() ); 167 177 168 178 // then check result 169 IndexedVectors::v ector_t result( IndexedVectors::nullvector );170 IndexedVectors::v ector_t thirdresult( IndexedVectors::nullvector );171 CPPUNIT_ASSERT_EQUAL( IndexedVectors:: FixedSize, result.size() );172 for (size_t i=0; i<IndexedVectors:: FixedSize; ++i) {179 IndexedVectors::value_t result; 180 IndexedVectors::value_t thirdresult; 181 CPPUNIT_ASSERT_EQUAL( IndexedVectors::value_t::FixedSize, result.size() ); 182 for (size_t i=0; i<IndexedVectors::value_t::FixedSize; ++i) { 173 183 result[i] = ones[i] - threes[i]; 174 184 thirdresult[i] = -threes[i]; 175 185 } 176 for (IndexedVectors::indexedv ectors_t::const_iterator iter = ivectors->vectors.begin();177 iter != ivectors-> vectors.end(); ++iter) {178 CPPUNIT_ASSERT_EQUAL( IndexedVectors:: FixedSize, iter->second.size() );186 for (IndexedVectors::indexedvalues_t::const_iterator iter = ivectors->getValues().begin(); 187 iter != ivectors->getValues().end(); ++iter) { 188 CPPUNIT_ASSERT_EQUAL( IndexedVectors::value_t::FixedSize, iter->second.size() ); 179 189 } 180 CPPUNIT_ASSERT( result == ivectors->vectors[1]);181 CPPUNIT_ASSERT( twos == ivectors->vectors[2]);182 CPPUNIT_ASSERT( thirdresult == ivectors->vectors[3]);190 checkValueInIndexedVectors(*ivectors, 1, result); 191 checkValueInIndexedVectors(*ivectors, 2, twos); 192 checkValueInIndexedVectors(*ivectors, 3, thirdresult); 183 193 } 184 194 -
src/Fragmentation/Summation/SetValues/unittests/IndexedVectorsUnitTest.hpp
re08108 rbd8b57 41 41 IndexedVectors *ivectors; 42 42 IndexedVectors *otherivectors; 43 IndexedVectors::v ector_t ones;44 IndexedVectors::v ector_t twos;45 IndexedVectors::v ector_t threes;43 IndexedVectors::value_t ones; 44 IndexedVectors::value_t twos; 45 IndexedVectors::value_t threes; 46 46 47 47 };
Note:
See TracChangeset
for help on using the changeset viewer.