Ignore:
Timestamp:
Oct 17, 2013, 7:14:21 AM (11 years ago)
Author:
Frederik Heber <heber@…>
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:
58952a
Parents:
e0ae58d
git-author:
Frederik Heber <heber@…> (09/27/13 11:25:35)
git-committer:
Frederik Heber <heber@…> (10/17/13 07:14:21)
Message:

Added (in)equality operators to all SetValues.

Location:
src/Fragmentation/Summation/SetValues
Files:
2 added
21 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Summation/SetValues/Eigenvalues.cpp

    re0ae58d r955051  
    9898}
    9999
     100bool Eigenvalues::operator==(const Eigenvalues& other) const
     101{
     102  bool status = true;
     103  status &= addedsamples == other.addedsamples;
     104  status &= subtractedsamples == other.subtractedsamples;
     105  return status;
     106}
     107
    100108template<> Eigenvalues ZeroInstance<Eigenvalues>()
    101109{
  • src/Fragmentation/Summation/SetValues/Eigenvalues.hpp

    re0ae58d r955051  
    2020class Eigenvalues
    2121{
     22  //!> grant unit test access to private parts
     23  friend class EigenvaluesTest;
     24  //!> grant output operator access
     25  friend std::ostream & operator<<(std::ostream &ost, const Eigenvalues &eigenvalues);
    2226public:
    2327  //!> named type for a vector of sample values
    2428  typedef std::vector<double> samples_t;
    25   //!> grant output operator access
    26   friend std::ostream & operator<<(std::ostream &ost, const Eigenvalues &eigenvalues);
    2729public:
    2830  /** Default constructor for class Eigenvalues.
     
    7173//  }
    7274
     75  /** Equality operator.
     76   *
     77   * @param other other instance to check against
     78   * @return true - both are equal, false - some eigenvalues differ
     79   */
     80  bool operator==(const Eigenvalues& other) const;
     81
     82  bool operator!=(const Eigenvalues& other) const
     83  {
     84    return (!(*this == other));
     85  }
     86
    7387private:
    7488  //!> typedef for the internal container format
  • src/Fragmentation/Summation/SetValues/Histogram.cpp

    re0ae58d r955051  
    107107    const_cast<BinLowerEnd &>(offset) = *samples.begin();
    108108    // set binwidth to statistical sensible value
    109     MinMax_t MinMax = getMinMaxFromSamples(samples);
     109//    MinMax_t MinMax = getMinMaxFromSamples(samples);
    110110//    const_cast<double &>(binwidth) = (*(MinMax.second) - *(MinMax.first))/pow(samples.size(), 1./3.);
    111111    // and add all samples to these histogram bins
    112     addSamples(samples);
    113   }
     112  }
     113  addSamples(samples);
    114114}
    115115
     
    185185    }
    186186    LOG(3, "DEBUG: Bins after adding empties before start are " << printBins() << ".");
    187     loweriter = getLowerEndBin(LowerEnd);
    188     ASSERT( loweriter != bins.end(),
    189         "Histogram::extendMissingBins() - still no lower bound after adding empties.");
    190187  }
    191188  if (upperiter == bins.end()) {
     
    198195    }
    199196    LOG(3, "DEBUG: Bins after adding empties after end are " << printBins() << ".");
    200     upperiter = getHigherEndBin(NextLowerEnd);
    201     ASSERT( upperiter != bins.end(),
    202         "Histogram::extendMissingBins() - still no upper bound after adding empties.");
    203   }
     197  }
     198  loweriter = getLowerEndBin(LowerEnd);
     199  ASSERT( loweriter != bins.end(),
     200      "Histogram::extendMissingBins() - still no lower bound after adding empties.");
     201  upperiter = getHigherEndBin(NextLowerEnd);
     202  ASSERT( upperiter != bins.end(),
     203      "Histogram::extendMissingBins() - still no upper bound after adding empties.");
    204204}
    205205
     
    347347}
    348348
     349bool Histogram::operator==(const Histogram& other) const
     350{
     351  bool status = true;
     352  status &= binwidth == other.binwidth;
     353  status &= offset == other.offset;
     354  status &= bins == other.bins;
     355  return status;
     356}
     357
    349358template<> Histogram ZeroInstance<Histogram>()
    350359{
  • src/Fragmentation/Summation/SetValues/Histogram.hpp

    re0ae58d r955051  
    126126  void addSamples(const samples_t &samples);
    127127
     128  /** Equality operator.
     129   *
     130   * @param other other instance to check against
     131   * @return true - both are equal, false - some bins differ
     132   */
     133  bool operator==(const Histogram& other) const;
     134
     135  bool operator!=(const Histogram& other) const
     136  {
     137    return (!(*this == other));
     138  }
     139
    128140private:
    129141  /** Returns the iterator to the bin representing the lower end into which the \a value fits.
  • src/Fragmentation/Summation/SetValues/IndexedVectors.cpp

    re0ae58d r955051  
    103103}
    104104
     105bool IndexedVectors::operator==(const IndexedVectors& other) const
     106{
     107  bool status = vectors == other.vectors;
     108  return status;
     109}
     110
    105111std::ostream & operator<<(std::ostream &ost, const IndexedVectors &other)
    106112{
  • src/Fragmentation/Summation/SetValues/IndexedVectors.hpp

    re0ae58d r955051  
    102102  { return vectors; }
    103103
     104  /** Equality operator.
     105   *
     106   * @param other other instance to check against
     107   * @return true - both are equal, false - some IndexedVectors differ
     108   */
     109  bool operator==(const IndexedVectors& other) const;
     110
     111  bool operator!=(const IndexedVectors& other) const
     112  {
     113    return (!(*this == other));
     114  }
     115
    104116private:
    105117  /** Helper function that contains all the logic of how to superpose two
  • src/Fragmentation/Summation/SetValues/SamplingGrid.cpp

    re0ae58d r955051  
    266266    const double value, const size_t axis) const
    267267{
    268   const double length = end[axis] - begin[axis];
     268  const double length = getTotalLengthPerAxis(axis);
    269269  if ((fabs(length) < std::numeric_limits<double>::epsilon()) || (getGridPointsPerAxis() == 0))
    270270    return begin[axis];
    271   if (value > end[axis])
     271  if ((value - end[axis]) > -std::numeric_limits<double>::epsilon()*1.e4)
    272272    return end[axis];
    273273  const double offset = value - begin[axis];
    274   if (offset < 0)
     274  if (offset < std::numeric_limits<double>::epsilon()*1.e4)
    275275    return begin[axis];
    276276  // modify value a little if value actually has been on a grid point but
     
    279279      floor((double)getGridPointsPerAxis()*(offset/length)
    280280          +std::numeric_limits<double>::epsilon()*1.e4);
    281   return factor*(length/(double)getGridPointsPerAxis());
     281  return begin[axis]+factor*getDeltaPerAxis(axis);
    282282}
    283283
     
    285285    const double value, const size_t axis) const
    286286{
    287   const double length = end[axis] - begin[axis];
     287  const double length = getTotalLengthPerAxis(axis);
    288288  if ((fabs(length) < std::numeric_limits<double>::epsilon()) || (getGridPointsPerAxis() == 0))
    289289    return end[axis];
    290   if (value > end[axis])
     290  if ((value - end[axis]) > -std::numeric_limits<double>::epsilon()*1.e4)
    291291    return end[axis];
    292292  const double offset = value - begin[axis];
    293   if (offset < 0)
     293  if (offset < std::numeric_limits<double>::epsilon()*1.e4)
    294294    return begin[axis];
    295295  // modify value a little if value actually has been on a grid point but
     
    298298      ceil((double)getGridPointsPerAxis()*(offset/length)
    299299          -std::numeric_limits<double>::epsilon()*1.e4);
    300   return factor*(length/(double)getGridPointsPerAxis());
     300  return begin[axis]+factor*getDeltaPerAxis(axis);
    301301}
    302302
     
    605605}
    606606
     607
     608bool SamplingGrid::operator==(const SamplingGrid &other) const
     609{
     610  bool status =
     611      static_cast<const SamplingGridProperties &>(*this)
     612      == static_cast<const SamplingGridProperties &>(other);
     613  // compare general properties
     614  if (status) {
     615    // compare windows
     616    for (size_t i=0; i<3; ++i) {
     617      status &= begin_window[i] == other.begin_window[i];
     618      status &= end_window[i] == other.end_window[i];
     619    }
     620    // compare grids
     621    if (status)
     622      status &= sampled_grid == other.sampled_grid;
     623  }
     624  return status;
     625}
     626
    607627std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other)
    608628{
  • src/Fragmentation/Summation/SetValues/SamplingGrid.hpp

    re0ae58d r955051  
    2222
    2323#include "Fragmentation/Summation/SetValues/SamplingGridProperties.hpp"
     24#include "Fragmentation/Summation/ZeroInstance.hpp"
    2425
    2526class MPQCData;
     
    221222      size_t *total) const;
    222223
     224  /** Equality operator.
     225   *
     226   * @param other other instance to check against
     227   * @return true - both are equal, false - grids differ
     228   */
     229  bool operator==(const SamplingGrid& other) const;
     230
     231  bool operator!=(const SamplingGrid& other) const
     232  {
     233    return (!(*this == other));
     234  }
     235
    223236private:
    224237  /** Sets the size of the domain.
     
    394407std::ostream & operator<<(std::ostream &ost, const SamplingGrid& other);
    395408
    396 template<typename T> T ZeroInstance();
    397409template<> SamplingGrid ZeroInstance<SamplingGrid>();
    398410
  • src/Fragmentation/Summation/SetValues/SamplingGridProperties.cpp

    re0ae58d r955051  
    100100}
    101101
     102
     103template<> SamplingGridProperties ZeroInstance<SamplingGridProperties>()
     104{
     105  SamplingGridProperties returnvalue;
     106  return returnvalue;
     107}
     108
    102109// we need to explicitly instantiate the serialization functions as
    103110// its is only serialized through its base class FragmentJob
  • src/Fragmentation/Summation/SetValues/SamplingGridProperties.hpp

    re0ae58d r955051  
    1616#include "boost/serialization/export.hpp"
    1717#include "boost/serialization/array.hpp"
     18
     19#include "Fragmentation/Summation/ZeroInstance.hpp"
    1820
    1921/** This class stores a sample function on a three-dimensional grid.
     
    136138};
    137139
     140template<> SamplingGridProperties ZeroInstance<SamplingGridProperties>();
     141
    138142// we need to give this class a unique key for serialization
    139143// its is only serialized through its base class FragmentJob
  • src/Fragmentation/Summation/SetValues/SamplingGridProperties_inline.hpp

    re0ae58d r955051  
    6161}
    6262
    63 
    6463#endif /* SAMPLINGGRIDPROPERTIES_INLINE_HPP_ */
  • src/Fragmentation/Summation/SetValues/unittests/FragmentUnitTest.cpp

    re0ae58d r955051  
    235235  CPPUNIT_ASSERT( otherfragment == otherfragment );
    236236  CPPUNIT_ASSERT( emptyfragment == emptyfragment );
     237
     238  // check against ZeroInstance
     239  CPPUNIT_ASSERT( *fragment != ZeroInstance<Fragment>() );
     240  CPPUNIT_ASSERT( otherfragment != ZeroInstance<Fragment>() );
    237241}
    238242
  • src/Fragmentation/Summation/SetValues/unittests/HistogramUnitTest.cpp

    re0ae58d r955051  
    318318}
    319319
     320/** UnitTest for operator==()
     321 */
     322void HistogramTest::equality_Test()
     323{
     324  Histogram::samples_t sampled_values;
     325  sampled_values += 1.,2.,3.,4.;
     326  histogram = new Histogram(sampled_values, 1., 1.);
     327
     328  // create different histogram
     329  Histogram::samples_t more_values;
     330  more_values += 0.5, 1.25, 2.5,3., 4.2;
     331  Histogram otherhistogram(more_values, 0.5, .625);
     332
     333  CPPUNIT_ASSERT( !(*histogram == otherhistogram) );
     334  CPPUNIT_ASSERT( *histogram != otherhistogram );
     335
     336  // test against empty histogram
     337  Histogram emptyhistogram;
     338  CPPUNIT_ASSERT( !(*histogram == emptyhistogram) );
     339  CPPUNIT_ASSERT( *histogram != emptyhistogram );
     340
     341  // tests against themselves
     342  CPPUNIT_ASSERT( *histogram == *histogram );
     343  CPPUNIT_ASSERT( otherhistogram == otherhistogram );
     344  CPPUNIT_ASSERT( emptyhistogram == emptyhistogram );
     345
     346  // check against ZeroInstance
     347  CPPUNIT_ASSERT( *histogram != ZeroInstance<Histogram>() );
     348  CPPUNIT_ASSERT( otherhistogram != ZeroInstance<Histogram>() );
     349}
  • src/Fragmentation/Summation/SetValues/unittests/HistogramUnitTest.hpp

    re0ae58d r955051  
    3333    CPPUNIT_TEST ( operatorPlusEqual_Test );
    3434    CPPUNIT_TEST ( operatorMinusEqual_Test );
     35    CPPUNIT_TEST ( equality_Test );
    3536    CPPUNIT_TEST_SUITE_END();
    3637
     
    4748      void operatorPlusEqual_Test();
    4849      void operatorMinusEqual_Test();
     50      void equality_Test();
    4951
    5052private:
  • src/Fragmentation/Summation/SetValues/unittests/IndexedVectorsUnitTest.cpp

    re0ae58d r955051  
    183183}
    184184
     185
     186/** UnitTest for operator==()
     187 */
     188void IndexedVectorsTest::equality_Test()
     189{
     190  CPPUNIT_ASSERT( !(*ivectors == *otherivectors) );
     191  CPPUNIT_ASSERT( *ivectors != *otherivectors );
     192
     193  // test against empty ivectors
     194  IndexedVectors emptyivectors;
     195  CPPUNIT_ASSERT( !(*ivectors == emptyivectors) );
     196  CPPUNIT_ASSERT( *ivectors != emptyivectors );
     197
     198  // tests against themselves
     199  CPPUNIT_ASSERT( *ivectors == *ivectors );
     200  CPPUNIT_ASSERT( *otherivectors == *otherivectors );
     201  CPPUNIT_ASSERT( emptyivectors == emptyivectors );
     202
     203  // check against ZeroInstance
     204  CPPUNIT_ASSERT( *ivectors != ZeroInstance<IndexedVectors>() );
     205  CPPUNIT_ASSERT( *otherivectors != ZeroInstance<IndexedVectors>() );
     206}
  • src/Fragmentation/Summation/SetValues/unittests/IndexedVectorsUnitTest.hpp

    re0ae58d r955051  
    2727    CPPUNIT_TEST ( operatorPlusEqual_Test );
    2828    CPPUNIT_TEST ( operatorMinusEqual_Test );
     29    CPPUNIT_TEST ( equality_Test );
    2930    CPPUNIT_TEST_SUITE_END();
    3031
     
    3536      void operatorPlusEqual_Test();
    3637      void operatorMinusEqual_Test();
     38      void equality_Test();
    3739
    3840private:
  • src/Fragmentation/Summation/SetValues/unittests/Makefile.am

    re0ae58d r955051  
    33
    44FRAGMENTATIONSETVALUESTESTSSOURCES = \
     5        ../Fragmentation/Summation/SetValues/unittests/EigenvaluesUnitTest.cpp \
    56        ../Fragmentation/Summation/SetValues/unittests/FragmentUnitTest.cpp \
    67        ../Fragmentation/Summation/SetValues/unittests/HistogramUnitTest.cpp \
     
    1011
    1112FRAGMENTATIONSETVALUESTESTSHEADERS = \
     13        ../Fragmentation/Summation/SetValues/unittests/EigenvaluesUnitTest.hpp \
    1214        ../Fragmentation/Summation/SetValues/unittests/FragmentUnitTest.hpp \
    1315        ../Fragmentation/Summation/SetValues/unittests/HistogramUnitTest.hpp \
     
    1719
    1820FRAGMENTATIONSETVALUESTESTS = \
     21        EigenvaluesUnitTest \
    1922        FragmentUnitTest \
    2023        HistogramUnitTest \
     
    3134        ${CodePatterns_LIBS} \
    3235        $(BOOST_LIB)
     36
     37EigenvaluesUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
     38        ../Fragmentation/Summation/SetValues/unittests/EigenvaluesUnitTest.cpp \
     39        ../Fragmentation/Summation/SetValues/unittests/EigenvaluesUnitTest.hpp
     40EigenvaluesUnitTest_LDADD = \
     41        ${FRAGMENTATIONSETVALUESLIBS} \
     42        $(BOOST_SERIALIZATION_LDFLAGS) $(BOOST_SERIALIZATION_LIBS)
    3343
    3444FragmentUnitTest_SOURCES = $(top_srcdir)/src/unittests/UnitTestMain.cpp \
  • src/Fragmentation/Summation/SetValues/unittests/SamplingGridPropertiesUnitTest.cpp

    re0ae58d r955051  
    3939#include <cppunit/extensions/TestFactoryRegistry.h>
    4040#include <cppunit/ui/text/TestRunner.h>
     41
     42// include headers that implement a archive in simple text format
     43#include <boost/archive/text_oarchive.hpp>
     44#include <boost/archive/text_iarchive.hpp>
    4145
    4246#include "SamplingGridPropertiesUnitTest.hpp"
     
    123127  CPPUNIT_ASSERT( *props != moreotherprops );
    124128  CPPUNIT_ASSERT( moreotherprops != *props );
     129
     130  // check against ZeroInstance
     131  CPPUNIT_ASSERT( *props != ZeroInstance<SamplingGridProperties>() );
     132  CPPUNIT_ASSERT( sameprops != ZeroInstance<SamplingGridProperties>() );
     133  CPPUNIT_ASSERT( otherprops != ZeroInstance<SamplingGridProperties>() );
     134  CPPUNIT_ASSERT( anotherprops != ZeroInstance<SamplingGridProperties>() );
     135  CPPUNIT_ASSERT( moreotherprops != ZeroInstance<SamplingGridProperties>() );
    125136}
    126137
     138
     139/** UnitTest for serialization
     140 */
     141void SamplingGridPropertiesTest::serializeTest()
     142{
     143  // serialize
     144  std::stringstream outputstream;
     145  boost::archive::text_oarchive oa(outputstream);
     146  oa << props;
     147
     148  // deserialize
     149  SamplingGridProperties *sameprops = NULL;
     150  std::stringstream returnstream(outputstream.str());
     151  boost::archive::text_iarchive ia(returnstream);
     152  ia >> sameprops;
     153
     154  CPPUNIT_ASSERT( sameprops != NULL );
     155  CPPUNIT_ASSERT( *props == *sameprops );
     156
     157  delete sameprops;
     158}
  • src/Fragmentation/Summation/SetValues/unittests/SamplingGridPropertiesUnitTest.hpp

    re0ae58d r955051  
    2626    CPPUNIT_TEST ( isCompatible_Test );
    2727    CPPUNIT_TEST ( equality_Test );
     28    CPPUNIT_TEST ( serializeTest );
    2829    CPPUNIT_TEST_SUITE_END();
    2930
     
    3334      void isCompatible_Test();
    3435      void equality_Test();
     36      void serializeTest();
    3537
    3638private:
  • src/Fragmentation/Summation/SetValues/unittests/SamplingGridUnitTest.cpp

    re0ae58d r955051  
    3939#include <cppunit/extensions/TestFactoryRegistry.h>
    4040#include <cppunit/ui/text/TestRunner.h>
     41
     42// include headers that implement a archive in simple text format
     43#include <boost/archive/text_oarchive.hpp>
     44#include <boost/archive/text_iarchive.hpp>
    4145
    4246#include "SamplingGridUnitTest.hpp"
     
    131135
    132136  // differing windows
    133   const double begin_window[3] = { 0.5, 0.5, 0.5 };
    134   const double end_window[3] = { 1., 1., 1. };
     137//  const double begin_window[3] = { 0.5, 0.5, 0.5 };
     138//  const double end_window[3] = { 1., 1., 1. };
    135139  const double otherbegin_window[3] = { 0.45, 0.45, 0.45 };
    136140  const double otherend_window[3] = { 1.05, 1.05, 1.05 };
     
    422426}
    423427
     428
     429/** UnitTest for operator==()
     430 */
     431void SamplingGridTest::equality_Test()
     432{
     433  const double begin[3] = { 0., 0., 0. };
     434  const double otherbegin[3] = { .5, 0.1, -0.5 };
     435  const double end[3] = { 1., 1., 1. };
     436  const double otherend[3] = { 2., 2., 2. };
     437  const double begin_window[3] = { 0., 0., 0. };
     438  const double otherbegin_window[3] = { .75, 0.1, 0. };
     439  const double end_window[3] = { 1., 1., 1. };
     440  const double otherend_window[3] = { .9, .9, .9 };
     441
     442  // create other grid
     443  SamplingGrid samegrid(begin, end, 2, values);
     444  SamplingGrid differentbegin(otherbegin, end, 2, values);
     445  SamplingGrid differentend(begin, otherend, 2, values);
     446  SamplingGrid::sampledvalues_t morevalues;
     447  {
     448    const double othergrid_value = 1.5;
     449    for (size_t i=0; i< NUMBEROFSAMPLES(4); ++i)
     450      morevalues += othergrid_value;
     451  }
     452  SamplingGrid differentlevel(begin, end, 4, morevalues);
     453  SamplingGrid::sampledvalues_t othervalues;
     454  {
     455    const double othergrid_value = 1.5;
     456    for (size_t i=0; i< NUMBEROFSAMPLES(2); ++i)
     457      othervalues += othergrid_value;
     458  }
     459  SamplingGrid differentvalues(begin, end, 2, othervalues);
     460
     461  // check for same level, begin, and end
     462  CPPUNIT_ASSERT( *grid == *grid );
     463  CPPUNIT_ASSERT( *grid == samegrid );
     464  CPPUNIT_ASSERT( samegrid == *grid);
     465  CPPUNIT_ASSERT( *grid != differentbegin);
     466  CPPUNIT_ASSERT( differentbegin != *grid);
     467  CPPUNIT_ASSERT( *grid != differentend );
     468  CPPUNIT_ASSERT( differentend != *grid );
     469  CPPUNIT_ASSERT( *grid != differentlevel );
     470  CPPUNIT_ASSERT( differentlevel != *grid );
     471
     472  // check for all but differing values
     473  CPPUNIT_ASSERT( *grid != differentvalues );
     474  CPPUNIT_ASSERT( differentvalues != *grid );
     475
     476  // check for different windows
     477  SamplingGrid differentwindowbegin(begin, end, 2);
     478  differentwindowbegin.setWindow(otherbegin_window, end_window);
     479  SamplingGrid differentwindowend(begin, end, 2);
     480  differentwindowend.setWindow(begin_window, otherend_window);
     481  CPPUNIT_ASSERT( *grid != differentwindowbegin );
     482  CPPUNIT_ASSERT( differentwindowbegin != *grid );
     483  CPPUNIT_ASSERT( *grid != differentwindowend );
     484  CPPUNIT_ASSERT( differentwindowend != *grid );
     485
     486  // check against ZeroInstance
     487  CPPUNIT_ASSERT( *grid != ZeroInstance<SamplingGrid>() );
     488  CPPUNIT_ASSERT( samegrid != ZeroInstance<SamplingGrid>() );
     489  CPPUNIT_ASSERT( differentbegin != ZeroInstance<SamplingGrid>() );
     490  CPPUNIT_ASSERT( differentend != ZeroInstance<SamplingGrid>() );
     491  CPPUNIT_ASSERT( differentlevel != ZeroInstance<SamplingGrid>() );
     492  CPPUNIT_ASSERT( differentvalues != ZeroInstance<SamplingGrid>() );
     493  CPPUNIT_ASSERT( differentwindowbegin != ZeroInstance<SamplingGrid>() );
     494  CPPUNIT_ASSERT( differentwindowend != ZeroInstance<SamplingGrid>() );
     495}
     496
     497/** UnitTest for serialization
     498 */
     499void SamplingGridTest::serializeTest()
     500{
     501  // serialize
     502  std::stringstream outputstream;
     503  boost::archive::text_oarchive oa(outputstream);
     504  oa << grid;
     505
     506  // deserialize
     507  SamplingGrid *samegrid = NULL;
     508  std::stringstream returnstream(outputstream.str());
     509  boost::archive::text_iarchive ia(returnstream);
     510  ia >> samegrid;
     511
     512  CPPUNIT_ASSERT( samegrid != NULL );
     513  CPPUNIT_ASSERT( *grid == *samegrid );
     514
     515  delete samegrid;
     516}
  • src/Fragmentation/Summation/SetValues/unittests/SamplingGridUnitTest.hpp

    re0ae58d r955051  
    3535    CPPUNIT_TEST ( addOntoWindow_Test );
    3636    CPPUNIT_TEST ( addOntoWindow_asymmetric_Test );
     37    CPPUNIT_TEST ( equality_Test );
     38    CPPUNIT_TEST ( serializeTest );
    3739    CPPUNIT_TEST_SUITE_END();
    3840
     
    5153      void operatorPlusEqual_Test();
    5254      void operatorMinusEqual_Test();
     55      void equality_Test();
     56      void serializeTest();
    5357
    5458private:
Note: See TracChangeset for help on using the changeset viewer.