Sierra Toolkit Version of the Day
UnitTestFieldRestriction.cpp
00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00009 
00010 #include <stdexcept>
00011 #include <sstream>
00012 
00013 #include <stk_util/unit_test_support/stk_utest_macros.hpp>
00014 
00015 #include <stk_mesh/base/FieldRestriction.hpp>
00016 #include <stk_mesh/base/Types.hpp>
00017 
00018 namespace {
00019 
00020 
00021 STKUNIT_UNIT_TEST( UnitTestFieldRestriction, defaultConstruct )
00022 {
00023   stk::mesh::FieldRestriction fr;
00024   //STKUNIT_EXPECT_EQ( fr.entity_rank(), stk::mesh::InvalidEntityRank );
00025   STKUNIT_EXPECT_EQ( fr.part_ordinal(), stk::mesh::InvalidPartOrdinal );
00026   for (stk::mesh::Ordinal i = 0 ; i < stk::mesh::MaximumFieldDimension ; ++i) {
00027     STKUNIT_EXPECT_EQ( fr.stride(i), 0 );
00028   }
00029   STKUNIT_EXPECT_EQ( fr.dimension(), 0 );
00030 }
00031 
00032 
00033 STKUNIT_UNIT_TEST( UnitTestFieldRestriction, construct )
00034 {
00035   stk::mesh::FieldRestriction fr(1,2);
00036   for (stk::mesh::Ordinal i = 0 ; i < stk::mesh::MaximumFieldDimension ; ++i) {
00037     fr.stride(i) = i+1;
00038   }
00039 
00040   STKUNIT_EXPECT_EQ( fr.entity_rank(), 1u );
00041   STKUNIT_EXPECT_EQ( fr.part_ordinal(), 2u );
00042   const int max_field_dimension = stk::mesh::MaximumFieldDimension;
00043   for (int i = 0 ; i < max_field_dimension ; ++i) {
00044     STKUNIT_EXPECT_EQ( fr.stride(i), i+1 );
00045   }
00046   STKUNIT_EXPECT_EQ( fr.dimension(), 1 );
00047 }
00048 
00049 
00050 STKUNIT_UNIT_TEST( UnitTestFieldRestriction, copyConstruct )
00051 {
00052   stk::mesh::FieldRestriction fr(1,2);
00053   for (stk::mesh::Ordinal i = 0 ; i < stk::mesh::MaximumFieldDimension ; ++i) {
00054     fr.stride(i) = i+1;
00055   }
00056 
00057   stk::mesh::FieldRestriction tmpfr(fr);
00058   STKUNIT_EXPECT_EQ( tmpfr.entity_rank(), 1u );
00059   STKUNIT_EXPECT_EQ( tmpfr.part_ordinal(), 2u );
00060   const int max_field_dimension = stk::mesh::MaximumFieldDimension;
00061   for (int i = 0 ; i < max_field_dimension ; ++i) {
00062     STKUNIT_EXPECT_EQ( tmpfr.stride(i), i+1 );
00063   }
00064   STKUNIT_EXPECT_EQ( tmpfr.dimension(), 1 );
00065 }
00066 
00067 
00068 STKUNIT_UNIT_TEST( UnitTestFieldRestriction, operatorEqual )
00069 {
00070   stk::mesh::FieldRestriction fr(1,2);
00071   for (stk::mesh::Ordinal i = 0 ; i < stk::mesh::MaximumFieldDimension ; ++i) {
00072     fr.stride(i) = i+1;
00073   }
00074   stk::mesh::FieldRestriction tmpfr(3,4);
00075   for (stk::mesh::Ordinal i = 0 ; i < stk::mesh::MaximumFieldDimension ; ++i) {
00076     tmpfr.stride(i) = i+10;
00077   }
00078 
00079   tmpfr = fr;
00080   STKUNIT_EXPECT_EQ( tmpfr.entity_rank(), 1u );
00081   STKUNIT_EXPECT_EQ( tmpfr.part_ordinal(), 2u );
00082   const int max_field_dimension = stk::mesh::MaximumFieldDimension;
00083   for (int i = 0 ; i < max_field_dimension ; ++i) {
00084     STKUNIT_EXPECT_EQ( tmpfr.stride(i), i+1 );
00085   }
00086   STKUNIT_EXPECT_EQ( tmpfr.dimension(), 1 );
00087 }
00088 
00089 
00090 STKUNIT_UNIT_TEST( UnitTestFieldRestriction, operatorLess )
00091 {
00092   {
00093     stk::mesh::FieldRestriction frA(1,1);
00094     stk::mesh::FieldRestriction frB(1,2);
00095     STKUNIT_EXPECT_EQ( frA < frB, true );
00096     STKUNIT_EXPECT_EQ( frB < frA, false );
00097   }
00098   {
00099     stk::mesh::FieldRestriction frA(1,1);
00100     stk::mesh::FieldRestriction frB(2,1);
00101     STKUNIT_EXPECT_EQ( frA < frB, true );
00102     STKUNIT_EXPECT_EQ( frB < frA, false );
00103   }
00104   {
00105     stk::mesh::FieldRestriction frA(0,1);
00106     stk::mesh::FieldRestriction frB(1,2);
00107     STKUNIT_EXPECT_EQ( frA < frB, true );
00108     STKUNIT_EXPECT_EQ( frB < frA, false );
00109   }
00110 }
00111 
00112 
00113 STKUNIT_UNIT_TEST( UnitTestFieldRestriction, operatorLessInvalid )
00114 {
00115   stk::mesh::FieldRestriction frA(1,2);
00116   stk::mesh::FieldRestriction frB;
00117   STKUNIT_EXPECT_EQ( frA < frB, true );
00118   STKUNIT_EXPECT_EQ( frB < frA, false );
00119 }
00120 
00121 
00122 STKUNIT_UNIT_TEST( UnitTestFieldRestriction, operatorEqualEqual_and_NotEqual )
00123 {
00124   {
00125     stk::mesh::FieldRestriction frA(1,2);
00126     frA.stride(0) = 25;
00127     stk::mesh::FieldRestriction frB(1,2);
00128     frB.stride(0) = 10;
00129     STKUNIT_EXPECT_EQ( frA == frB, true );
00130     STKUNIT_EXPECT_EQ( frA != frB, false );
00131   }
00132   {
00133     stk::mesh::FieldRestriction frA(1,1);
00134     frA.stride(0) = 3;
00135     stk::mesh::FieldRestriction frB(1,2);
00136     frB.stride(0) = 3;
00137     STKUNIT_EXPECT_EQ( frA == frB, false );
00138     STKUNIT_EXPECT_EQ( frA != frB, true );
00139   }
00140   {
00141     stk::mesh::FieldRestriction frA(1,2);
00142     stk::mesh::FieldRestriction frB(2,2);
00143     STKUNIT_EXPECT_EQ( frA == frB, false );
00144     STKUNIT_EXPECT_EQ( frA != frB, true );
00145   }
00146   {
00147     stk::mesh::FieldRestriction frA;
00148     stk::mesh::FieldRestriction frB;
00149     STKUNIT_EXPECT_EQ( frA == frB, true );
00150     STKUNIT_EXPECT_EQ( frA != frB, false );
00151   }
00152 }
00153 
00154 
00155 STKUNIT_UNIT_TEST( UnitTestFieldRestriction, not_equal_stride )
00156 {
00157   {
00158     stk::mesh::FieldRestriction frA(1,2);
00159     frA.stride(0) = 25;
00160     stk::mesh::FieldRestriction frB(1,2);
00161     frB.stride(0) = 10;
00162     STKUNIT_EXPECT_EQ( frA.not_equal_stride(frB), true );
00163     STKUNIT_EXPECT_EQ( frB.not_equal_stride(frA), true );
00164   }
00165   {
00166     stk::mesh::FieldRestriction frA(1,2);
00167     for (stk::mesh::Ordinal i=0 ; i < stk::mesh::MaximumFieldDimension ; ++i ) {
00168       frA.stride(0) = i+1;
00169     }
00170     stk::mesh::FieldRestriction frB(1,2);
00171     for (stk::mesh::Ordinal i=0 ; i < stk::mesh::MaximumFieldDimension ; ++i ) {
00172       frB.stride(0) = i+1;
00173     }
00174     STKUNIT_EXPECT_EQ( frA.not_equal_stride(frB), false );
00175     STKUNIT_EXPECT_EQ( frB.not_equal_stride(frA), false );
00176     frB.stride(stk::mesh::MaximumFieldDimension-1) = 1;
00177     STKUNIT_EXPECT_EQ( frA.not_equal_stride(frB), true );
00178     STKUNIT_EXPECT_EQ( frB.not_equal_stride(frA), true );
00179   }
00180 }
00181 
00182 
00183 } //namespace <anonymous>
00184 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends