MOAB: Mesh Oriented datABase  (version 5.4.1)
InstructionQueueTest.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2004 Sandia Corporation and Argonne National
00005     Laboratory.  Under the terms of Contract DE-AC04-94AL85000
00006     with Sandia Corporation, the U.S. Government retains certain
00007     rights in this software.
00008 
00009     This library is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU Lesser General Public
00011     License as published by the Free Software Foundation; either
00012     version 2.1 of the License, or (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     (lgpl.txt) along with this library; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023     [email protected], [email protected], [email protected],
00024     [email protected], [email protected], [email protected]
00025 
00026   ***************************************************************** */
00027 // -*- Mode : c++; tab-width: 3; c-tab-always-indent: t; indent-tabs-mode: nil; c-basic-offset: 3
00028 // -*-
00029 //
00030 //   SUMMARY:
00031 //     USAGE:
00032 //
00033 //    AUTHOR: Thomas Leurent <[email protected]>
00034 //       ORG: Argonne National Laboratory
00035 //    E-MAIL: [email protected]
00036 //
00037 // ORIG-DATE: 13-Nov-02 at 18:05:56
00038 //  LAST-MOD: 23-Jul-03 at 17:33:18 by Thomas Leurent
00039 //
00040 // DESCRIPTION:
00041 // ============
00042 /*! \file InstructionQueueTest.cpp
00043 
00044 Unit testing of various functions in the InstructionQueue class.
00045 
00046  */
00047 // DESCRIP-END.
00048 //
00049 
00050 #include "Mesquite.hpp"
00051 #include "InstructionQueue.hpp"
00052 #include "QualityAssessor.hpp"
00053 #include "QualityImprover.hpp"
00054 #include "IdealWeightInverseMeanRatio.hpp"
00055 #include "LPtoPTemplate.hpp"
00056 #include "SteepestDescent.hpp"
00057 #include "Vector3D.hpp"
00058 #include "PatchData.hpp"
00059 #include "VertexSlaver.hpp"
00060 
00061 #include "UnitUtil.hpp"
00062 
00063 #include <iostream>
00064 using std::cout;
00065 using std::endl;
00066 
00067 using namespace MBMesquite;
00068 
00069 class InstructionQueueTest : public CppUnit::TestFixture
00070 {
00071   private:
00072     CPPUNIT_TEST_SUITE( InstructionQueueTest );
00073     CPPUNIT_TEST( test_add_preconditioner );
00074     CPPUNIT_TEST( test_remove_preconditioner );
00075     CPPUNIT_TEST( test_insert_preconditioner );
00076     CPPUNIT_TEST( test_add_quality_assessor );
00077     CPPUNIT_TEST( test_remove_quality_assessor );
00078     CPPUNIT_TEST( test_insert_quality_assessor );
00079     CPPUNIT_TEST( test_add_remove_vertex_slaver );
00080     CPPUNIT_TEST_SUITE_END();
00081 
00082   private:
00083     QualityAssessor* mQA;
00084     QualityImprover* mQI;
00085     QualityMetric* mQM;
00086     ObjectiveFunction* mOF;
00087     InstructionQueue mQueue;
00088 
00089   public:
00090     void setUp()
00091     {
00092         MsqPrintError err( cout );
00093         // creates a quality assessor and a qualilty improver
00094         mQM = new IdealWeightInverseMeanRatio( err );
00095         CPPUNIT_ASSERT( !err );
00096         mOF = new LPtoPTemplate( mQM, 2, err );
00097         CPPUNIT_ASSERT( !err );
00098         mQI = new SteepestDescent( mOF );
00099         mQA = new QualityAssessor();
00100         mQA->set_stopping_assessment( mQM );
00101         CPPUNIT_ASSERT( !err );
00102     }
00103 
00104     void tearDown()
00105     {
00106         delete mQA;
00107         delete mQI;
00108         delete mQM;
00109         delete mOF;
00110     }
00111 
00112   public:
00113     InstructionQueueTest() {}
00114 
00115     void test_add_preconditioner()
00116     {
00117         MsqPrintError err( cout );
00118         mQueue.clear();
00119         mQueue.add_preconditioner( mQI, err );
00120         CPPUNIT_ASSERT( !err );
00121         err.clear();
00122         mQueue.set_master_quality_improver( mQI, err );
00123         CPPUNIT_ASSERT( !err );
00124         err.clear();
00125         mQueue.add_preconditioner( mQI, err );
00126         CPPUNIT_ASSERT_MESSAGE( "preconditioner cannot be added after master QI", err );
00127         err.clear();
00128     }
00129 
00130     void test_remove_preconditioner()
00131     {
00132         MsqPrintError err( cout );
00133         mQueue.clear();
00134         mQueue.add_preconditioner( mQI, err );    // 0
00135         mQueue.add_quality_assessor( mQA, err );  // 1
00136         mQueue.add_preconditioner( mQI, err );    // 2
00137         mQueue.set_master_quality_improver( mQI, err );
00138         CPPUNIT_ASSERT( !err );
00139         err.clear();
00140         mQueue.remove_preconditioner( 2, err );
00141         CPPUNIT_ASSERT_MESSAGE( "should remove QualityImprover", !err );
00142         err.clear();
00143         mQueue.remove_preconditioner( 3, err );
00144         CPPUNIT_ASSERT_MESSAGE( "should not remove master QualityImprover", err );
00145         err.clear();
00146         mQueue.remove_preconditioner( 1, err );
00147         CPPUNIT_ASSERT_MESSAGE( "should not remove QualityAssessor", err );
00148         err.clear();
00149         mQueue.remove_preconditioner( 0, err );
00150         CPPUNIT_ASSERT_MESSAGE( "should  remove QualityImprover", !err );
00151         err.clear();
00152         mQueue.remove_preconditioner( 0, err );
00153         CPPUNIT_ASSERT_MESSAGE( "should not remove QualityAssessor", err );
00154         err.clear();
00155     }
00156 
00157     void test_insert_preconditioner()
00158     {
00159         MsqPrintError err( cout );
00160         mQueue.clear();
00161         mQueue.add_preconditioner( mQI, err );    // 0
00162         mQueue.add_quality_assessor( mQA, err );  // 1
00163         mQueue.add_preconditioner( mQI, err );    // 2
00164         mQueue.set_master_quality_improver( mQI, err );
00165         CPPUNIT_ASSERT( !err );
00166         err.clear();
00167         mQueue.insert_preconditioner( mQI, 2, err );
00168         CPPUNIT_ASSERT( !err );
00169         err.clear();
00170         mQueue.insert_preconditioner( mQI, 5, err );
00171         CPPUNIT_ASSERT_MESSAGE( "should not insert after master QualityImprover", err );
00172         err.clear();
00173     }
00174 
00175     void test_add_quality_assessor()
00176     {
00177         MsqPrintError err( cout );
00178         mQueue.clear();
00179         mQueue.add_quality_assessor( mQA, err );
00180         CPPUNIT_ASSERT( !err );
00181         err.clear();
00182         mQueue.set_master_quality_improver( mQI, err );
00183         CPPUNIT_ASSERT( !err );
00184         err.clear();
00185         mQueue.add_quality_assessor( mQA, err );
00186         CPPUNIT_ASSERT( !err );
00187     }
00188 
00189     void test_remove_quality_assessor()
00190     {
00191         MsqPrintError err( cout );
00192         mQueue.clear();
00193         mQueue.add_preconditioner( mQI, err );    // 0
00194         mQueue.add_quality_assessor( mQA, err );  // 1
00195         mQueue.add_preconditioner( mQI, err );    // 2
00196         mQueue.set_master_quality_improver( mQI, err );
00197         CPPUNIT_ASSERT( !err );
00198         err.clear();
00199         mQueue.remove_quality_assessor( 2, err );
00200         CPPUNIT_ASSERT_MESSAGE( "should not remove QualityImprover", err );
00201         err.clear();
00202         mQueue.remove_quality_assessor( 3, err );
00203         CPPUNIT_ASSERT_MESSAGE( "should not remove master QualityImprover", err );
00204         err.clear();
00205         mQueue.remove_quality_assessor( 1, err );
00206         CPPUNIT_ASSERT_MESSAGE( "should remove QualityAssessor", !err );
00207         err.clear();
00208         mQueue.remove_quality_assessor( 1, err );
00209         CPPUNIT_ASSERT_MESSAGE( "should not remove QualityImprover", err );
00210         err.clear();
00211     }
00212 
00213     void test_insert_quality_assessor()
00214     {
00215         MsqPrintError err( cout );
00216         mQueue.clear();
00217         mQueue.add_preconditioner( mQI, err );    // 0
00218         mQueue.add_quality_assessor( mQA, err );  // 1
00219         mQueue.add_preconditioner( mQI, err );    // 2
00220         mQueue.set_master_quality_improver( mQI, err );
00221         CPPUNIT_ASSERT( !err );
00222         err.clear();
00223         mQueue.insert_quality_assessor( mQA, 2, err );
00224         CPPUNIT_ASSERT( !err );
00225         err.clear();
00226         mQueue.insert_quality_assessor( mQA, 5, err );
00227         CPPUNIT_ASSERT( !err );
00228         err.clear();
00229     }
00230 
00231     void test_add_remove_vertex_slaver();
00232 };
00233 
00234 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( InstructionQueueTest, "InstructionQueueTest" );
00235 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( InstructionQueueTest, "Unit" );
00236 
00237 class DummyVertexSlaver : public VertexSlaver
00238 {
00239   public:
00240     virtual double loop_over_mesh( MeshDomainAssoc*, const Settings*, MsqError& )
00241     {
00242         CPPUNIT_ASSERT( false );
00243         return 0.0;
00244     }
00245     virtual std::string get_name() const
00246     {
00247         return "Dummy";
00248     }
00249     virtual void initialize_queue( MeshDomainAssoc*, const Settings*, MsqError& ) {}
00250 };
00251 
00252 void InstructionQueueTest::test_add_remove_vertex_slaver()
00253 {
00254     InstructionQueue q;
00255     DummyVertexSlaver s1, s2;
00256     MsqPrintError err( std::cerr );
00257 
00258     CPPUNIT_ASSERT( q.get_slaved_ho_node_mode() != Settings::SLAVE_CALCULATED );
00259     q.add_vertex_slaver( &s1, err );
00260     ASSERT_NO_ERROR( err );
00261     CPPUNIT_ASSERT_EQUAL( Settings::SLAVE_CALCULATED, q.get_slaved_ho_node_mode() );
00262     q.add_vertex_slaver( &s2, err );
00263     ASSERT_NO_ERROR( err );
00264     CPPUNIT_ASSERT_EQUAL( Settings::SLAVE_CALCULATED, q.get_slaved_ho_node_mode() );
00265     q.remove_vertex_slaver( &s2, err );
00266     ASSERT_NO_ERROR( err );
00267     CPPUNIT_ASSERT_EQUAL( Settings::SLAVE_CALCULATED, q.get_slaved_ho_node_mode() );
00268     q.remove_vertex_slaver( &s2, err );
00269     CPPUNIT_ASSERT( err );
00270     err.clear();
00271     CPPUNIT_ASSERT_EQUAL( Settings::SLAVE_CALCULATED, q.get_slaved_ho_node_mode() );
00272     q.remove_vertex_slaver( &s1, err );
00273     ASSERT_NO_ERROR( err );
00274     CPPUNIT_ASSERT_EQUAL( Settings::SLAVE_ALL, q.get_slaved_ho_node_mode() );
00275 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines