Changeset 3aa8a5 for src/Graph/unittests


Ignore:
Timestamp:
Dec 3, 2012, 9:50:01 AM (12 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:
4694df
Parents:
5197e5
git-author:
Frederik Heber <heber@…> (09/21/12 16:22:50)
git-committer:
Frederik Heber <heber@…> (12/03/12 09:50:01)
Message:

REFACTOR: AdjacencyList now just contains a single internal map.

Location:
src/Graph/unittests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Graph/unittests/AdjacencyListUnitTest.cpp

    r5197e5 r3aa8a5  
    6565CPPUNIT_TEST_SUITE_REGISTRATION( AdjacencyListTest );
    6666
    67 static std::string adjacencyfile ="\
     67const std::string adjacencyfile ="\
    68681 2\n\
    69692 1 3\n\
     
    777710 9\n";
    7878
    79 static std::string wrongadjacencyfile1 ="\
     79const std::string wrongadjacencyfile1 ="\
    80801 2\n\
    81812 1\n\
     
    888810 9\n";
    8989
    90 static std::string wrongadjacencyfile2 ="\
     90const std::string wrongadjacencyfile2 ="\
    91911 2\n\
    92922 1 3\n\
     
    99999 8 10\n\
    10010010 9 11\n\
    101 11 10";
    102 
    103 static std::string wrongadjacencyfile3 ="\
     10111 10\n";
     102
     103const std::string wrongadjacencyfile3 ="\
    1041041 2\n\
    1051052 1 3\n\
     
    1111118 7 9\n\
    1121129 8 10\n\
    113 10 9 11\n\
    114 11 10";
     11310 9\n";
    115114
    116115// set up and tear down
     
    167166{
    168167  std::stringstream input;
    169   AdjacencyList fileChecker(input);
    170   fileChecker.CreateMap(atomIds, fileChecker.ExternalAtomBondMap);
     168  AdjacencyList FileAdjacency(input);
     169  AdjacencyList WorldAdjacency(atomIds);
    171170
    172171  // check size (it's 8*2 + 2*1 = 18 keys)
    173   CPPUNIT_ASSERT_EQUAL( (size_t)18, fileChecker.ExternalAtomBondMap.size() );
    174   CPPUNIT_ASSERT_EQUAL( (size_t)0, fileChecker.InternalAtomBondMap.size() );
     172  CPPUNIT_ASSERT_EQUAL( (size_t)18, WorldAdjacency.atombondmap.size() );
     173  CPPUNIT_ASSERT_EQUAL( (size_t)0, FileAdjacency.atombondmap.size() );
    175174
    176175  // check equality
    177   CPPUNIT_ASSERT( comparisonMap.size() == fileChecker.ExternalAtomBondMap.size() );
     176  CPPUNIT_ASSERT( comparisonMap.size() == WorldAdjacency.atombondmap.size() );
    178177//  std::cout << "comparisonMap: " << comparisonMap << std::endl;
    179 //  std::cout << "fileChecker.InternalAtomBondMap: " << fileChecker.InternalAtomBondMap << std::endl;
    180   CPPUNIT_ASSERT( comparisonMap == fileChecker.ExternalAtomBondMap );
     178//  std::cout << "WorldAdjacency.atombondmap: " << WorldAdjacency.atombondmap << std::endl;
     179  CPPUNIT_ASSERT( comparisonMap == WorldAdjacency.atombondmap );
    181180
    182181  // check non-equality: more
    183182  comparisonMap.insert( std::make_pair( (atomId_t)10, (atomId_t)8) );
    184   CPPUNIT_ASSERT( comparisonMap != fileChecker.ExternalAtomBondMap );
     183  CPPUNIT_ASSERT( comparisonMap != WorldAdjacency.atombondmap );
    185184  comparisonMap.erase((atomId_t)10);
    186185
    187186  // check non-equality: less
    188187  comparisonMap.erase((atomId_t)9);
    189   CPPUNIT_ASSERT( comparisonMap != fileChecker.ExternalAtomBondMap );
     188  CPPUNIT_ASSERT( comparisonMap != WorldAdjacency.atombondmap );
    190189}
    191190
     
    196195{
    197196  std::stringstream input(adjacencyfile);
    198   AdjacencyList fileChecker(input);
    199   std::vector<atomId_t> noids;
    200   fileChecker.CreateMap(noids, fileChecker.ExternalAtomBondMap);
     197  AdjacencyList FileAdjacency(input);
     198  AdjacencyList WorldAdjacency;
    201199
    202200  // check size (it's 8*2 + 2*1 = 18 keys)
    203   CPPUNIT_ASSERT_EQUAL( (size_t)0, fileChecker.ExternalAtomBondMap.size() );
    204   CPPUNIT_ASSERT_EQUAL( (size_t)18, fileChecker.InternalAtomBondMap.size() );
     201  CPPUNIT_ASSERT_EQUAL( (size_t)0, WorldAdjacency.atombondmap.size() );
     202  CPPUNIT_ASSERT_EQUAL( (size_t)18, FileAdjacency.atombondmap.size() );
    205203
    206204  // check equality
    207   CPPUNIT_ASSERT( comparisonMap.size() == fileChecker.InternalAtomBondMap.size() );
    208   CPPUNIT_ASSERT( comparisonMap == fileChecker.InternalAtomBondMap );
     205  CPPUNIT_ASSERT( comparisonMap.size() == FileAdjacency.atombondmap.size() );
     206  CPPUNIT_ASSERT( comparisonMap == FileAdjacency.atombondmap );
    209207
    210208  // check non-equality: more
    211209  comparisonMap.insert( std::make_pair( (atomId_t)10, (atomId_t)8) );
    212   CPPUNIT_ASSERT( comparisonMap != fileChecker.InternalAtomBondMap );
     210  CPPUNIT_ASSERT( comparisonMap != FileAdjacency.atombondmap );
    213211  comparisonMap.erase((atomId_t)10);
    214212
    215213  // check non-equality: less
    216214  comparisonMap.erase((atomId_t)9);
    217   CPPUNIT_ASSERT( comparisonMap != fileChecker.InternalAtomBondMap );
    218 }
    219 
    220 /** Unit tests for AdjacencyList::CompareInternalExternalMap().
    221  *
    222  */
    223 void AdjacencyListTest::CompareInternalExternalMapTest()
     215  CPPUNIT_ASSERT( comparisonMap != FileAdjacency.atombondmap );
     216}
     217
     218/** Unit tests for AdjacencyList::StoreToFile().
     219 *
     220 */
     221void AdjacencyListTest::StoreToFileTest()
    224222{
    225223  std::stringstream input(adjacencyfile);
    226   AdjacencyList fileChecker(input);
     224  AdjacencyList FileAdjacency(input);
     225
     226  // check size (it's 8*2 + 2*1 = 18 keys)
     227  CPPUNIT_ASSERT_EQUAL( (size_t)18, FileAdjacency.atombondmap.size() );
     228
     229  // store to file
     230  std::stringstream output;
     231  FileAdjacency.StoreToFile(output);
     232  CPPUNIT_ASSERT_EQUAL( input.str(), output.str() );
     233}
     234
     235/** Unit tests for AdjacencyList::operator<().
     236 *
     237 */
     238void AdjacencyListTest::operatorGreaterLessTest()
     239{
     240  std::stringstream input(adjacencyfile);
     241  AdjacencyList FileAdjacency(input);
     242  AdjacencyList WorldAdjacency;
     243
     244  // assert empty set is subset of some filled set (empty sets should always return true)
     245  CPPUNIT_ASSERT( FileAdjacency.atombondmap.size() != WorldAdjacency.atombondmap.size() );
     246  CPPUNIT_ASSERT( FileAdjacency.atombondmap != WorldAdjacency.atombondmap );
     247  CPPUNIT_ASSERT( WorldAdjacency < FileAdjacency );
     248  CPPUNIT_ASSERT( !(WorldAdjacency > FileAdjacency) );
     249
     250  // parse in external map
     251  WorldAdjacency.CreateMap(atomIds);
     252
     253  // assert equality after parsing
     254  CPPUNIT_ASSERT_EQUAL( FileAdjacency.atombondmap.size(), WorldAdjacency.atombondmap.size() );
     255  CPPUNIT_ASSERT_EQUAL( FileAdjacency.atombondmap, WorldAdjacency.atombondmap );
     256  CPPUNIT_ASSERT( WorldAdjacency < FileAdjacency );
     257  CPPUNIT_ASSERT( WorldAdjacency > FileAdjacency );
     258
     259  // remove one entry from the world
     260  WorldAdjacency.atombondmap.erase((atomId_t)9);
     261  CPPUNIT_ASSERT( WorldAdjacency < FileAdjacency );
     262  CPPUNIT_ASSERT( !(WorldAdjacency > FileAdjacency) );
     263}
     264
     265/** Unit tests for AdjacencyList::operator==().
     266 *
     267 */
     268void AdjacencyListTest::operatorEqualTest()
     269{
     270  std::stringstream input(adjacencyfile);
     271  AdjacencyList FileAdjacency(input);
     272  AdjacencyList WorldAdjacency;
    227273
    228274  // assert equality before parsing (empty sets should always return true)
    229   CPPUNIT_ASSERT( fileChecker.ExternalAtomBondMap.size() != fileChecker.InternalAtomBondMap.size() );
    230   CPPUNIT_ASSERT( fileChecker.ExternalAtomBondMap != fileChecker.InternalAtomBondMap );
    231   CPPUNIT_ASSERT( fileChecker.CompareInternalExternalMap() );
     275  CPPUNIT_ASSERT( FileAdjacency.atombondmap.size() != WorldAdjacency.atombondmap.size() );
     276  CPPUNIT_ASSERT( FileAdjacency.atombondmap != WorldAdjacency.atombondmap );
     277  CPPUNIT_ASSERT( WorldAdjacency != FileAdjacency );
    232278
    233279  // parse in external map
    234   fileChecker.CreateMap(atomIds, fileChecker.ExternalAtomBondMap);
     280  WorldAdjacency.CreateMap(atomIds);
    235281
    236282  // assert equality after parsing
    237   CPPUNIT_ASSERT_EQUAL( fileChecker.ExternalAtomBondMap.size(), fileChecker.InternalAtomBondMap.size() );
    238   CPPUNIT_ASSERT_EQUAL( fileChecker.ExternalAtomBondMap, fileChecker.InternalAtomBondMap );
    239   CPPUNIT_ASSERT( fileChecker.CompareInternalExternalMap() );
     283  CPPUNIT_ASSERT_EQUAL( FileAdjacency.atombondmap.size(), WorldAdjacency.atombondmap.size() );
     284  CPPUNIT_ASSERT_EQUAL( FileAdjacency.atombondmap, WorldAdjacency.atombondmap );
     285  CPPUNIT_ASSERT( WorldAdjacency == FileAdjacency );
    240286}
    241287
     
    245291void AdjacencyListTest::CheckAgainstSubsetTest()
    246292{
     293  AdjacencyList WorldAdjacency(atomIds);
    247294  {
    248295    // parse right
    249296    std::stringstream input(adjacencyfile);
    250     AdjacencyList fileChecker(input);
    251     CPPUNIT_ASSERT( fileChecker.CheckAgainstSubset(atomIds) );
     297    AdjacencyList FileAdjacency(input);
     298    CPPUNIT_ASSERT( (WorldAdjacency > FileAdjacency) && (WorldAdjacency < FileAdjacency) );
    252299  }
    253300  {
    254301    // parse wrong1 (more atoms in the world than in file, hence wrong)
    255302    std::stringstream input(wrongadjacencyfile1);
    256     AdjacencyList fileChecker(input);
    257     CPPUNIT_ASSERT( !fileChecker.CheckAgainstSubset(atomIds) );
     303    AdjacencyList FileAdjacency(input);
     304    CPPUNIT_ASSERT( !(WorldAdjacency < FileAdjacency) && (WorldAdjacency > FileAdjacency) );
    258305  }
    259306  {
     
    262309    std::remove_copy_if(atomIds.begin(), atomIds.end(), std::back_inserter(validids), boost::lambda::_1 == (atomId_t)2);
    263310    CPPUNIT_ASSERT_EQUAL( (size_t)ATOM_COUNT-1, validids.size() );
     311    AdjacencyList RestrictedWorldAdjacency(validids);
    264312    // parse wrong1 (more atoms in the world than in file, hence wrong)
    265313    std::stringstream input(wrongadjacencyfile1);
    266     AdjacencyList fileChecker(input);
    267     CPPUNIT_ASSERT( fileChecker.CheckAgainstSubset(validids) );
     314    AdjacencyList FileAdjacency(input);
     315    CPPUNIT_ASSERT( RestrictedWorldAdjacency == FileAdjacency );
    268316  }
    269317  {
    270318    // parse wrong2 (there is no atom 10, but present in file. hence true)
    271319    std::stringstream input(wrongadjacencyfile2);
    272     AdjacencyList fileChecker(input);
    273     CPPUNIT_ASSERT( !fileChecker.CheckAgainstSubset(atomIds) );
    274   }
    275   {
    276     // parse wrong3 (6 is not connected)
     320    AdjacencyList FileAdjacency(input);
     321    CPPUNIT_ASSERT( !(WorldAdjacency > FileAdjacency) && (WorldAdjacency < FileAdjacency) );
     322  }
     323  {
     324    // parse wrong3 (6 is skipped in connection, hence neither is subset)
    277325    std::stringstream input(wrongadjacencyfile3);
    278     AdjacencyList fileChecker(input);
    279     CPPUNIT_ASSERT( !fileChecker.CheckAgainstSubset(atomIds) );
    280   }
    281 }
     326    AdjacencyList FileAdjacency(input);
     327//    WorldAdjacency.StoreToFile((std::ostream &)std::cout);
     328//    FileAdjacency.StoreToFile((std::ostream &)std::cout);
     329    CPPUNIT_ASSERT( WorldAdjacency != FileAdjacency );
     330  }
     331}
  • src/Graph/unittests/AdjacencyListUnitTest.hpp

    r5197e5 r3aa8a5  
    3232  CPPUNIT_TEST ( CreateMapTest );
    3333  CPPUNIT_TEST ( ParseIntoMapTest );
    34   CPPUNIT_TEST ( CompareInternalExternalMapTest );
     34  CPPUNIT_TEST ( StoreToFileTest );
     35  CPPUNIT_TEST ( operatorGreaterLessTest );
     36  CPPUNIT_TEST ( operatorEqualTest );
    3537  CPPUNIT_TEST ( CheckAgainstSubsetTest );
    3638  CPPUNIT_TEST_SUITE_END();
     
    4244  void CreateMapTest();
    4345  void ParseIntoMapTest();
    44   void CompareInternalExternalMapTest();
     46  void StoreToFileTest();
     47  void operatorGreaterLessTest();
     48  void operatorEqualTest();
    4549  void CheckAgainstSubsetTest();
    4650
Note: See TracChangeset for help on using the changeset viewer.