1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
/* *****************************************************************
    MESQUITE -- The Mesh Quality Improvement Toolkit

    Copyright 2004 Sandia Corporation and Argonne National
    Laboratory.  Under the terms of Contract DE-AC04-94AL85000
    with Sandia Corporation, the U.S. Government retains certain
    rights in this software.

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    (lgpl.txt) along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    [email protected], [email protected], [email protected],
    [email protected], [email protected], [email protected]

  ***************************************************************** */
// -*- Mode : c++; tab-width: 3; c-tab-always-indent: t; indent-tabs-mode: nil; c-basic-offset: 3
// -*-
//
//   SUMMARY:
//     USAGE:
//
//    AUTHOR: Thomas Leurent <[email protected]>
//       ORG: Argonne National Laboratory
//    E-MAIL: [email protected]
//
// ORIG-DATE: 13-Nov-02 at 18:05:56
//  LAST-MOD: 23-Jul-03 at 17:33:18 by Thomas Leurent
//
// DESCRIPTION:
// ============
/*! \file InstructionQueueTest.cpp

Unit testing of various functions in the InstructionQueue class.

 */
// DESCRIP-END.
//

#include "Mesquite.hpp"
#include "InstructionQueue.hpp"
#include "QualityAssessor.hpp"
#include "QualityImprover.hpp"
#include "IdealWeightInverseMeanRatio.hpp"
#include "LPtoPTemplate.hpp"
#include "SteepestDescent.hpp"
#include "Vector3D.hpp"
#include "PatchData.hpp"
#include "VertexSlaver.hpp"

#include "UnitUtil.hpp"

#include <iostream>
using std::cout;
using std::endl;

using namespace MBMesquite;

class InstructionQueueTest : public CppUnit::TestFixture
{
  private:
    CPPUNIT_TEST_SUITE( InstructionQueueTest );
    CPPUNIT_TEST( test_add_preconditioner );
    CPPUNIT_TEST( test_remove_preconditioner );
    CPPUNIT_TEST( test_insert_preconditioner );
    CPPUNIT_TEST( test_add_quality_assessor );
    CPPUNIT_TEST( test_remove_quality_assessor );
    CPPUNIT_TEST( test_insert_quality_assessor );
    CPPUNIT_TEST( test_add_remove_vertex_slaver );
    CPPUNIT_TEST_SUITE_END();

  private:
    QualityAssessor* mQA;
    QualityImprover* mQI;
    QualityMetric* mQM;
    ObjectiveFunction* mOF;
    InstructionQueue mQueue;

  public:
    void setUp()
    {
        MsqPrintError err( cout );
        // creates a quality assessor and a qualilty improver
        mQM = new IdealWeightInverseMeanRatio( err );
        CPPUNIT_ASSERT( !err );
        mOF = new LPtoPTemplate( mQM, 2, err );
        CPPUNIT_ASSERT( !err );
        mQI = new SteepestDescent( mOF );
        mQA = new QualityAssessor();
        mQA->set_stopping_assessment( mQM );
        CPPUNIT_ASSERT( !err );
    }

    void tearDown()
    {
        delete mQA;
        delete mQI;
        delete mQM;
        delete mOF;
    }

  public:
    InstructionQueueTest() {}<--- Member variable 'InstructionQueueTest::mQA' is not initialized in the constructor.<--- Member variable 'InstructionQueueTest::mQI' is not initialized in the constructor.<--- Member variable 'InstructionQueueTest::mQM' is not initialized in the constructor.<--- Member variable 'InstructionQueueTest::mOF' is not initialized in the constructor.

    void test_add_preconditioner()
    {
        MsqPrintError err( cout );
        mQueue.clear();
        mQueue.add_preconditioner( mQI, err );
        CPPUNIT_ASSERT( !err );
        err.clear();
        mQueue.set_master_quality_improver( mQI, err );
        CPPUNIT_ASSERT( !err );
        err.clear();
        mQueue.add_preconditioner( mQI, err );
        CPPUNIT_ASSERT_MESSAGE( "preconditioner cannot be added after master QI", err );
        err.clear();
    }

    void test_remove_preconditioner()
    {
        MsqPrintError err( cout );
        mQueue.clear();
        mQueue.add_preconditioner( mQI, err );    // 0
        mQueue.add_quality_assessor( mQA, err );  // 1
        mQueue.add_preconditioner( mQI, err );    // 2
        mQueue.set_master_quality_improver( mQI, err );
        CPPUNIT_ASSERT( !err );
        err.clear();
        mQueue.remove_preconditioner( 2, err );
        CPPUNIT_ASSERT_MESSAGE( "should remove QualityImprover", !err );
        err.clear();
        mQueue.remove_preconditioner( 3, err );
        CPPUNIT_ASSERT_MESSAGE( "should not remove master QualityImprover", err );
        err.clear();
        mQueue.remove_preconditioner( 1, err );
        CPPUNIT_ASSERT_MESSAGE( "should not remove QualityAssessor", err );
        err.clear();
        mQueue.remove_preconditioner( 0, err );
        CPPUNIT_ASSERT_MESSAGE( "should  remove QualityImprover", !err );
        err.clear();
        mQueue.remove_preconditioner( 0, err );
        CPPUNIT_ASSERT_MESSAGE( "should not remove QualityAssessor", err );
        err.clear();
    }

    void test_insert_preconditioner()
    {
        MsqPrintError err( cout );
        mQueue.clear();
        mQueue.add_preconditioner( mQI, err );    // 0
        mQueue.add_quality_assessor( mQA, err );  // 1
        mQueue.add_preconditioner( mQI, err );    // 2
        mQueue.set_master_quality_improver( mQI, err );
        CPPUNIT_ASSERT( !err );
        err.clear();
        mQueue.insert_preconditioner( mQI, 2, err );
        CPPUNIT_ASSERT( !err );
        err.clear();
        mQueue.insert_preconditioner( mQI, 5, err );
        CPPUNIT_ASSERT_MESSAGE( "should not insert after master QualityImprover", err );
        err.clear();
    }

    void test_add_quality_assessor()
    {
        MsqPrintError err( cout );
        mQueue.clear();
        mQueue.add_quality_assessor( mQA, err );
        CPPUNIT_ASSERT( !err );
        err.clear();
        mQueue.set_master_quality_improver( mQI, err );
        CPPUNIT_ASSERT( !err );
        err.clear();
        mQueue.add_quality_assessor( mQA, err );
        CPPUNIT_ASSERT( !err );
    }

    void test_remove_quality_assessor()
    {
        MsqPrintError err( cout );
        mQueue.clear();
        mQueue.add_preconditioner( mQI, err );    // 0
        mQueue.add_quality_assessor( mQA, err );  // 1
        mQueue.add_preconditioner( mQI, err );    // 2
        mQueue.set_master_quality_improver( mQI, err );
        CPPUNIT_ASSERT( !err );
        err.clear();
        mQueue.remove_quality_assessor( 2, err );
        CPPUNIT_ASSERT_MESSAGE( "should not remove QualityImprover", err );
        err.clear();
        mQueue.remove_quality_assessor( 3, err );
        CPPUNIT_ASSERT_MESSAGE( "should not remove master QualityImprover", err );
        err.clear();
        mQueue.remove_quality_assessor( 1, err );
        CPPUNIT_ASSERT_MESSAGE( "should remove QualityAssessor", !err );
        err.clear();
        mQueue.remove_quality_assessor( 1, err );
        CPPUNIT_ASSERT_MESSAGE( "should not remove QualityImprover", err );
        err.clear();
    }

    void test_insert_quality_assessor()
    {
        MsqPrintError err( cout );
        mQueue.clear();
        mQueue.add_preconditioner( mQI, err );    // 0
        mQueue.add_quality_assessor( mQA, err );  // 1
        mQueue.add_preconditioner( mQI, err );    // 2
        mQueue.set_master_quality_improver( mQI, err );
        CPPUNIT_ASSERT( !err );
        err.clear();
        mQueue.insert_quality_assessor( mQA, 2, err );
        CPPUNIT_ASSERT( !err );
        err.clear();
        mQueue.insert_quality_assessor( mQA, 5, err );
        CPPUNIT_ASSERT( !err );
        err.clear();
    }

    void test_add_remove_vertex_slaver();
};

CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( InstructionQueueTest, "InstructionQueueTest" );
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( InstructionQueueTest, "Unit" );

class DummyVertexSlaver : public VertexSlaver
{
  public:
    virtual double loop_over_mesh( MeshDomainAssoc*, const Settings*, MsqError& )
    {
        CPPUNIT_ASSERT( false );
        return 0.0;
    }
    virtual std::string get_name() const
    {
        return "Dummy";
    }
    virtual void initialize_queue( MeshDomainAssoc*, const Settings*, MsqError& ) {}
};

void InstructionQueueTest::test_add_remove_vertex_slaver()
{
    InstructionQueue q;
    DummyVertexSlaver s1, s2;
    MsqPrintError err( std::cerr );

    CPPUNIT_ASSERT( q.get_slaved_ho_node_mode() != Settings::SLAVE_CALCULATED );
    q.add_vertex_slaver( &s1, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( Settings::SLAVE_CALCULATED, q.get_slaved_ho_node_mode() );
    q.add_vertex_slaver( &s2, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( Settings::SLAVE_CALCULATED, q.get_slaved_ho_node_mode() );
    q.remove_vertex_slaver( &s2, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( Settings::SLAVE_CALCULATED, q.get_slaved_ho_node_mode() );
    q.remove_vertex_slaver( &s2, err );
    CPPUNIT_ASSERT( err );
    err.clear();
    CPPUNIT_ASSERT_EQUAL( Settings::SLAVE_CALCULATED, q.get_slaved_ho_node_mode() );
    q.remove_vertex_slaver( &s1, err );
    ASSERT_NO_ERROR( err );
    CPPUNIT_ASSERT_EQUAL( Settings::SLAVE_ALL, q.get_slaved_ho_node_mode() );
}