MOAB: Mesh Oriented datABase  (version 5.2.1)
CylinderDomainTest.cpp
Go to the documentation of this file.
00001 #include "CylinderDomain.hpp"
00002 #include "MsqError.hpp"
00003 #include <cppunit/extensions/HelperMacros.h>
00004 
00005 const double EPSILON = 1e-6;
00006 #define ASSERT_VECTORS_EQUAL( A, B ) CPPUNIT_ASSERT( ( ( A ) - ( B ) ).length() < EPSILON )
00007 
00008 using namespace MBMesquite;
00009 
00010 class CylinderDomainTest : public CppUnit::TestFixture
00011 {
00012   private:
00013     CPPUNIT_TEST_SUITE( CylinderDomainTest );
00014     CPPUNIT_TEST( test_z_basic );
00015     CPPUNIT_TEST( test_z_snap_to );
00016     CPPUNIT_TEST( test_z_normal_at );
00017     CPPUNIT_TEST( test_z_closest_point );
00018     CPPUNIT_TEST( test_x_basic );
00019     CPPUNIT_TEST( test_x_snap_to );
00020     CPPUNIT_TEST( test_x_normal_at );
00021     CPPUNIT_TEST( test_x_closest_point );
00022     CPPUNIT_TEST( test_domain_DoF );
00023     CPPUNIT_TEST_SUITE_END();
00024 
00025     CylinderDomain z, x;
00026 
00027   public:
00028     CylinderDomainTest() : z( 1 ), x( 2, Vector3D( 1, 0, 0 ) ) {}
00029 
00030     void setUp() {}
00031     void tearDown() {}
00032 
00033     void test_z_basic();
00034     void test_z_snap_to();
00035     void test_z_normal_at();
00036     void test_z_closest_point();
00037 
00038     void test_x_basic();
00039     void test_x_snap_to();
00040     void test_x_normal_at();
00041     void test_x_closest_point();
00042 
00043     void test_domain_DoF();
00044 };
00045 
00046 void CylinderDomainTest::test_z_basic()
00047 {
00048     CPPUNIT_ASSERT_EQUAL( Vector3D( 0, 0, 1 ), z.axis() );
00049     CPPUNIT_ASSERT_EQUAL( 1.0, z.radius() );
00050     CPPUNIT_ASSERT_EQUAL( Vector3D( 0, 0, 0 ), z.center() );
00051 }
00052 
00053 void CylinderDomainTest::test_x_basic()
00054 {
00055     CPPUNIT_ASSERT_EQUAL( Vector3D( 1, 0, 0 ), x.axis() );
00056     CPPUNIT_ASSERT_EQUAL( 2.0, x.radius() );
00057     CPPUNIT_ASSERT_EQUAL( Vector3D( 0, 0, 0 ), x.center() );
00058 }
00059 
00060 void CylinderDomainTest::test_z_snap_to()
00061 {
00062     Vector3D vect;
00063 
00064     vect.set( 0.5, 0, 1 );
00065     z.snap_to( 0, vect );
00066     ASSERT_VECTORS_EQUAL( Vector3D( z.radius(), 0, 1 ), vect );
00067 
00068     vect.set( 0, 100, -5 );
00069     z.snap_to( 0, vect );
00070     ASSERT_VECTORS_EQUAL( Vector3D( 0, z.radius(), -5 ), vect );
00071 
00072     vect = z.center();
00073     z.snap_to( 0, vect );
00074     CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, vect.z(), EPSILON );
00075     CPPUNIT_ASSERT_DOUBLES_EQUAL( z.radius(), ( vect - z.center() ).length(), EPSILON );
00076 }
00077 
00078 void CylinderDomainTest::test_x_snap_to()
00079 {
00080     Vector3D vect;
00081 
00082     vect.set( 1, 0, 0.5 );
00083     x.snap_to( 0, vect );
00084     ASSERT_VECTORS_EQUAL( Vector3D( 1, 0, x.radius() ), vect );
00085 
00086     vect.set( -5, 100, 0 );
00087     x.snap_to( 0, vect );
00088     ASSERT_VECTORS_EQUAL( Vector3D( -5, x.radius(), 0 ), vect );
00089 
00090     vect = x.center();
00091     x.snap_to( 0, vect );
00092     CPPUNIT_ASSERT_DOUBLES_EQUAL( 0, vect.x(), EPSILON );
00093     CPPUNIT_ASSERT_DOUBLES_EQUAL( x.radius(), ( vect - x.center() ).length(), EPSILON );
00094 }
00095 
00096 void CylinderDomainTest::test_z_normal_at()
00097 {
00098     Vector3D vect;
00099 
00100     vect.set( 0.5, 0, 1 );
00101     z.vertex_normal_at( 0, vect );
00102     ASSERT_VECTORS_EQUAL( Vector3D( 1, 0, 0 ), vect );
00103 
00104     vect.set( 0, 100, -5 );
00105     z.vertex_normal_at( 0, vect );
00106     ASSERT_VECTORS_EQUAL( Vector3D( 0, 1, 0 ), vect );
00107 
00108     vect = z.center();
00109     z.vertex_normal_at( 0, vect );
00110     CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, vect.z(), EPSILON );
00111     CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, vect.length(), EPSILON );
00112 
00113     vect.set( 0.5, 0, 1 );
00114     z.element_normal_at( 0, vect );
00115     ASSERT_VECTORS_EQUAL( Vector3D( 1, 0, 0 ), vect );
00116 
00117     vect.set( 0, 100, -5 );
00118     z.element_normal_at( 0, vect );
00119     ASSERT_VECTORS_EQUAL( Vector3D( 0, 1, 0 ), vect );
00120 
00121     vect = z.center();
00122     z.element_normal_at( 0, vect );
00123     CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, vect.z(), EPSILON );
00124     CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, vect.length(), EPSILON );
00125 }
00126 
00127 void CylinderDomainTest::test_x_normal_at()
00128 {
00129     Vector3D vect;
00130 
00131     vect.set( 1, 0, 0.5 );
00132     x.vertex_normal_at( 0, vect );
00133     ASSERT_VECTORS_EQUAL( Vector3D( 0, 0, 1 ), vect );
00134 
00135     vect.set( -5, 100, 0 );
00136     x.vertex_normal_at( 0, vect );
00137     ASSERT_VECTORS_EQUAL( Vector3D( 0, 1, 0 ), vect );
00138 
00139     vect = x.center();
00140     x.vertex_normal_at( 0, vect );
00141     CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, vect.x(), EPSILON );
00142     CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, vect.length(), EPSILON );
00143 
00144     vect.set( 1, 0, 0.5 );
00145     x.element_normal_at( 0, vect );
00146     ASSERT_VECTORS_EQUAL( Vector3D( 0, 0, 1 ), vect );
00147 
00148     vect.set( -5, 100, 0 );
00149     x.element_normal_at( 0, vect );
00150     ASSERT_VECTORS_EQUAL( Vector3D( 0, 1, 0 ), vect );
00151 
00152     vect = x.center();
00153     x.element_normal_at( 0, vect );
00154     CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, vect.x(), EPSILON );
00155     CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, vect.length(), EPSILON );
00156 }
00157 
00158 void CylinderDomainTest::test_z_closest_point()
00159 {
00160     MsqError err;
00161     Vector3D point( z.radius(), 0, 20 );
00162     Vector3D close, normal;
00163     z.closest_point( 0, point, close, normal, err );
00164     CPPUNIT_ASSERT( !err );
00165     ASSERT_VECTORS_EQUAL( point, close );
00166     ASSERT_VECTORS_EQUAL( Vector3D( 1, 0, 0 ), normal );
00167 }
00168 
00169 void CylinderDomainTest::test_x_closest_point()
00170 {
00171     MsqError err;
00172     Vector3D point( 20, 0, x.radius() );
00173     Vector3D close, normal;
00174     x.closest_point( 0, point, close, normal, err );
00175     CPPUNIT_ASSERT( !err );
00176     ASSERT_VECTORS_EQUAL( point, close );
00177     ASSERT_VECTORS_EQUAL( Vector3D( 0, 0, 1 ), normal );
00178 }
00179 
00180 void CylinderDomainTest::test_domain_DoF()
00181 {
00182     const size_t count = 3;
00183     unsigned short dof_vals[count];
00184     MsqError err;
00185     z.domain_DoF( 0, dof_vals, count, err );
00186     CPPUNIT_ASSERT( !err );
00187     for( size_t i = 0; i < count; ++i )
00188         CPPUNIT_ASSERT_EQUAL( (unsigned short)2, dof_vals[i] );
00189 }
00190 
00191 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CylinderDomainTest, "CylinderDomainTest" );
00192 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CylinderDomainTest, "Unit" );
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines