Ignore:
Timestamp:
Oct 8, 2016, 7:25:46 PM (9 years ago)
Author:
Frederik Heber <heber@…>
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)
Message:

Extracted IndexedValue from IndexedVectors.

  • we may now sum up indexed values of arbitrary type, i.e. an arbitrary class that fulfills a certain interface, and each instance connected to a specific index (within index sets).
  • added detail::force where std::vector<double> is specialized for three components.
  • IndexedVectors is now a specialization of IndexedValue for detail::force.
  • adapated usage signatures in AnalyseFragmentationResultsAction, InterfaceVMGJob, and MPQCCommandJob.
  • slight changes in IndexedVectorsUnitTest because boost::assign is no longer used for detail::force.
Location:
src/Fragmentation/Summation/SetValues/unittests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Summation/SetValues/unittests/IndexedVectorsUnitTest.cpp

    re08108 rbd8b57  
    4747#include <boost/assign.hpp>
    4848
    49 
    5049#include "CodePatterns/Assert.hpp"
    5150
     
    6867
    6968  // 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 vectors
    78 
    79   IndexedVectors::vectors_t vectors;
    80   vectors.push_back(ones);
    81   vectors.push_back(twos);
    82   IndexedVectors::vectors_t othervectors;
    83   othervectors.push_back(threes);
    84   othervectors.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);
    8584
    8685  // create two indices
     
    9089  otherindices += 1,3;
    9190
    92   // create indexed vectors
    93   ivectors = new IndexedVectors(indices, vectors);
    94   otherivectors = new IndexedVectors(otherindices, othervectors);
     91  // create indexed values
     92  ivectors = new IndexedVectors(indices, values);
     93  otherivectors = new IndexedVectors(otherindices, othervalues);
    9594}
    9695
     
    102101}
    103102
     103static 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}
    104114
    105115/** UnitTest for cstor's
     
    110120  IndexedVectors::indices_t indices;
    111121  indices += 1,-1,3;
    112   IndexedVectors::vectors_t vectors;
    113   vectors.push_back(ones);
    114   vectors.push_back(twos);
    115   vectors.push_back(threes);
    116   IndexedVectors testivectors(indices, vectors);
    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() );
    122132}
    123133
     
    127137{
    128138  // 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() );
    131141
    132142  // perform operation
     
    134144
    135145  // 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() );
    138148
    139149  // then check result
    140   IndexedVectors::vector_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)
    143153    result[i] = ones[i] + threes[i];
    144   for (IndexedVectors::indexedvectors_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() );
    147157  }
    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);
    151161}
    152162
     
    156166{
    157167  // 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() );
    160170
    161171  // perform operation
     
    163173
    164174  // 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() );
    167177
    168178  // then check result
    169   IndexedVectors::vector_t result( IndexedVectors::nullvector );
    170   IndexedVectors::vector_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) {
    173183    result[i] = ones[i] - threes[i];
    174184    thirdresult[i] = -threes[i];
    175185  }
    176   for (IndexedVectors::indexedvectors_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() );
    179189  }
    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);
    183193}
    184194
  • src/Fragmentation/Summation/SetValues/unittests/IndexedVectorsUnitTest.hpp

    re08108 rbd8b57  
    4141      IndexedVectors *ivectors;
    4242      IndexedVectors *otherivectors;
    43       IndexedVectors::vector_t ones;
    44       IndexedVectors::vector_t twos;
    45       IndexedVectors::vector_t threes;
     43      IndexedVectors::value_t ones;
     44      IndexedVectors::value_t twos;
     45      IndexedVectors::value_t threes;
    4646
    4747};
Note: See TracChangeset for help on using the changeset viewer.