Changeset d96277


Ignore:
Timestamp:
Oct 29, 2009, 10:09:05 AM (15 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:
8c5327
Parents:
c0f6c6
Message:

Refactored StackClass with respect to tickets #38, #4.

  • #38 make const what is const
  • #4 shorten constructors
  • StackClass::TestImplementation() has been shifted into a unit test stackclassunittest.[ch]pp

Signed-off-by: Frederik Heber <heber@…>

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/stackclass.hpp

    rc0f6c6 rd96277  
    3333  bool RemoveItem(T ptr);
    3434  void ClearStack();
    35   bool IsEmpty();
    36   bool IsFull();
    37   int ItemCount();
    38   void Output(ofstream *out) const;
    39   void TestImplementation(ofstream *out, T test);
     35  bool IsEmpty() const;
     36  bool IsFull() const;
     37  int ItemCount() const;
     38  void Output(ofstream * const out) const;
    4039
    4140  private:
     
    4948/** Constructor of class StackClass.
    5049 */
    51 template <typename T> StackClass<T>::StackClass(int dimension)
    52 {
    53   CurrentLastEntry = 0;
    54   CurrentFirstEntry = 0;
    55   NextFreeField = 0;
    56   EntryCount = dimension;
     50template <typename T> StackClass<T>::StackClass(int dimension) : EntryCount(dimension), CurrentLastEntry(0), CurrentFirstEntry(0), NextFreeField(0)
     51{
    5752  StackList = Malloc<T>(EntryCount, "StackClass::StackClass: **StackList");
    5853};
     
    165160};
    166161
    167 /** Test the functionality of the stack.
    168  * \param *out ofstream for debugging
    169  * \param *test one item to put on stack
    170  * \return true - all tests worked correctly
    171  */
    172 template <typename T> void StackClass<T>::TestImplementation(ofstream *out, T test)
    173 {
    174   T Walker = test;
    175   *out << Verbose(1) << "Testing the snake stack..." << endl;
    176   for (int i=0;i<EntryCount;i++) {
    177     *out << Verbose(2) << "Filling " << i << "th element of stack." << endl;
    178     Push(Walker);
    179     Walker=Walker->next;
    180   }
    181   *out << endl;
    182   Output(out);
    183   if (IsFull())
    184     *out << "Stack is full as supposed to be!" << endl;
    185   else
    186     *out << "ERROR: Stack is not as full as supposed to be!" << endl;
    187   //if (StackList[(EntryCount+1)/2] != NULL) {
    188     *out << "Removing element in the middle ..." << endl;
    189     RemoveItem(StackList[(EntryCount+1)/2]);
    190     Output(out);
    191   //}
    192   //if (StackList[CurrentFirstEntry] != NULL) {
    193     *out << "Removing first element  ..." << endl;
    194     RemoveItem(StackList[CurrentFirstEntry]);
    195     Output(out);
    196   //}
    197   //if (StackList[CurrentLastEntry] != NULL) {
    198     *out << "Removing last element ..." << endl;
    199     RemoveItem(StackList[CurrentLastEntry]);
    200     Output(out);
    201   //}
    202   *out << "Clearing stack ... " << endl;
    203   ClearStack();
    204   Output(out);
    205   if (IsEmpty())
    206     *out << "Stack is empty as supposed to be!" << endl;
    207   else
    208     *out << "ERROR: Stack is not as empty as supposed to be!" << endl;
    209   *out << "done." << endl;
    210 };
    211162
    212163/** Puts contents of stack into ofstream \a *out.
    213164 * \param *out ofstream for output
    214165 */
    215 template <typename T> void StackClass<T>::Output(ofstream *out) const
     166template <typename T> void StackClass<T>::Output(ofstream * const out) const
    216167{
    217168  *out << "Contents of Stack: ";
     
    234185 * \return true - empty, false - not
    235186 */
    236 template <typename T> bool StackClass<T>::IsEmpty()
     187template <typename T> bool StackClass<T>::IsEmpty() const
    237188{
    238189  return((NextFreeField == CurrentFirstEntry) && (CurrentLastEntry == CurrentFirstEntry));
     
    244195 * \return true - full, false - not
    245196 */
    246 template <typename T> bool StackClass<T>::IsFull()
     197template <typename T> bool StackClass<T>::IsFull() const
    247198{
    248199  return((NextFreeField == CurrentFirstEntry) && (CurrentLastEntry != CurrentFirstEntry));
     
    254205 * \warning will never return correct item count if stack is full, i.e. count would be StackClass::EntryCount.
    255206 */
    256 template <typename T> int StackClass<T>::ItemCount()
     207template <typename T> int StackClass<T>::ItemCount() const
    257208{
    258209  //cout << "Stack: CurrentLastEntry " << CurrentLastEntry<< "\tCurrentFirstEntry " << CurrentFirstEntry << "\tEntryCount " << EntryCount << "." << endl;
  • src/unittests/Makefile.am

    rc0f6c6 rd96277  
    44AM_CXXFLAGS = $(CPPUNIT_CFLAGS)
    55
    6 TESTS = ActOnAllUnitTest AnalysisCorrelationToPointUnitTest AnalysisCorrelationToSurfaceUnitTest AnalysisPairCorrelationUnitTest ListOfBondsUnitTest MemoryUsageObserverUnitTest MemoryAllocatorUnitTest VectorUnitTest
     6TESTS = ActOnAllUnitTest AnalysisCorrelationToPointUnitTest AnalysisCorrelationToSurfaceUnitTest AnalysisPairCorrelationUnitTest ListOfBondsUnitTest MemoryUsageObserverUnitTest MemoryAllocatorUnitTest StackClassUnitTest VectorUnitTest
    77check_PROGRAMS = $(TESTS)
    88noinst_PROGRAMS = $(TESTS)
     
    2323ListOfBondsUnitTest_LDADD = ../libmolecuilder.a
    2424
    25 VectorUnitTest_SOURCES = defs.hpp helpers.hpp leastsquaremin.hpp memoryallocator.hpp memoryusageobserver.hpp vectorunittest.cpp vectorunittest.hpp vector.hpp verbose.hpp
    26 VectorUnitTest_LDADD = ../libmolecuilder.a
    27 
    2825MemoryAllocatorUnitTest_SOURCES = defs.hpp helpers.hpp memoryallocatorunittest.cpp memoryallocatorunittest.hpp memoryallocator.hpp memoryusageobserver.hpp verbose.hpp
    2926MemoryAllocatorUnitTest_LDADD = ../libmolecuilder.a
     
    3229MemoryUsageObserverUnitTest_LDADD = ../libmolecuilder.a
    3330
     31StackClassUnitTest_SOURCES = stackclass.hpp stackclassunittest.cpp stackclassunittest.hpp
     32StackClassUnitTest_LDADD = ../libmolecuilder.a
     33
     34VectorUnitTest_SOURCES = defs.hpp helpers.hpp leastsquaremin.hpp memoryallocator.hpp memoryusageobserver.hpp vectorunittest.cpp vectorunittest.hpp vector.hpp verbose.hpp
     35VectorUnitTest_LDADD = ../libmolecuilder.a
     36
     37
    3438#AUTOMAKE_OPTIONS = parallel-tests
Note: See TracChangeset for help on using the changeset viewer.