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.part_ordinal(), stk::mesh::InvalidPartOrdinal );
00025   for (stk::mesh::Ordinal i = 0 ; i < stk::mesh::MaximumFieldDimension ; ++i) {
00026     STKUNIT_EXPECT_EQ( fr.stride(i), 0 );
00027   }
00028   STKUNIT_EXPECT_EQ( fr.dimension(), 0 );
00029 }
00030 
00031 
00032 STKUNIT_UNIT_TEST( UnitTestFieldRestriction, construct )
00033 {
00034   stk::mesh::FieldRestriction fr(1,2);
00035   for (stk::mesh::Ordinal i = 0 ; i < stk::mesh::MaximumFieldDimension ; ++i) {
00036     fr.stride(i) = i+1;
00037   }
00038 
00039   STKUNIT_EXPECT_EQ( fr.entity_rank(), 1u );
00040   STKUNIT_EXPECT_EQ( fr.part_ordinal(), 2u );
00041   const int max_field_dimension = stk::mesh::MaximumFieldDimension;
00042   for (int i = 0 ; i < max_field_dimension ; ++i) {
00043     STKUNIT_EXPECT_EQ( fr.stride(i), i+1 );
00044   }
00045   STKUNIT_EXPECT_EQ( fr.dimension(), 1 );
00046 }
00047 
00048 
00049 STKUNIT_UNIT_TEST( UnitTestFieldRestriction, copyConstruct )
00050 {
00051   stk::mesh::FieldRestriction fr(1,2);
00052   for (stk::mesh::Ordinal i = 0 ; i < stk::mesh::MaximumFieldDimension ; ++i) {
00053     fr.stride(i) = i+1;
00054   }
00055 
00056   stk::mesh::FieldRestriction tmpfr(fr);
00057   STKUNIT_EXPECT_EQ( tmpfr.entity_rank(), 1u );
00058   STKUNIT_EXPECT_EQ( tmpfr.part_ordinal(), 2u );
00059   const int max_field_dimension = stk::mesh::MaximumFieldDimension;
00060   for (int i = 0 ; i < max_field_dimension ; ++i) {
00061     STKUNIT_EXPECT_EQ( tmpfr.stride(i), i+1 );
00062   }
00063   STKUNIT_EXPECT_EQ( tmpfr.dimension(), 1 );
00064 }
00065 
00066 
00067 STKUNIT_UNIT_TEST( UnitTestFieldRestriction, operatorEqual )
00068 {
00069   stk::mesh::FieldRestriction fr(1,2);
00070   for (stk::mesh::Ordinal i = 0 ; i < stk::mesh::MaximumFieldDimension ; ++i) {
00071     fr.stride(i) = i+1;
00072   }
00073   stk::mesh::FieldRestriction tmpfr(3,4);
00074   for (stk::mesh::Ordinal i = 0 ; i < stk::mesh::MaximumFieldDimension ; ++i) {
00075     tmpfr.stride(i) = i+10;
00076   }
00077 
00078   tmpfr = fr;
00079   STKUNIT_EXPECT_EQ( tmpfr.entity_rank(), 1u );
00080   STKUNIT_EXPECT_EQ( tmpfr.part_ordinal(), 2u );
00081   const int max_field_dimension = stk::mesh::MaximumFieldDimension;
00082   for (int i = 0 ; i < max_field_dimension ; ++i) {
00083     STKUNIT_EXPECT_EQ( tmpfr.stride(i), i+1 );
00084   }
00085   STKUNIT_EXPECT_EQ( tmpfr.dimension(), 1 );
00086 }
00087 
00088 
00089 STKUNIT_UNIT_TEST( UnitTestFieldRestriction, operatorLess )
00090 {
00091   {
00092     stk::mesh::FieldRestriction frA(1,1);
00093     stk::mesh::FieldRestriction frB(1,2);
00094     STKUNIT_EXPECT_EQ( frA < frB, true );
00095     STKUNIT_EXPECT_EQ( frB < frA, false );
00096   }
00097   {
00098     stk::mesh::FieldRestriction frA(1,1);
00099     stk::mesh::FieldRestriction frB(2,1);
00100     STKUNIT_EXPECT_EQ( frA < frB, true );
00101     STKUNIT_EXPECT_EQ( frB < frA, false );
00102   }
00103   {
00104     stk::mesh::FieldRestriction frA(0,1);
00105     stk::mesh::FieldRestriction frB(1,2);
00106     STKUNIT_EXPECT_EQ( frA < frB, true );
00107     STKUNIT_EXPECT_EQ( frB < frA, false );
00108   }
00109 }
00110 
00111 
00112 STKUNIT_UNIT_TEST( UnitTestFieldRestriction, operatorLessInvalid )
00113 {
00114   stk::mesh::FieldRestriction frA(1,2);
00115   stk::mesh::FieldRestriction frB;
00116   STKUNIT_EXPECT_EQ( frA < frB, true );
00117   STKUNIT_EXPECT_EQ( frB < frA, false );
00118 }
00119 
00120 
00121 STKUNIT_UNIT_TEST( UnitTestFieldRestriction, operatorEqualEqual_and_NotEqual )
00122 {
00123   {
00124     stk::mesh::FieldRestriction frA(1,2);
00125     frA.stride(0) = 25;
00126     stk::mesh::FieldRestriction frB(1,2);
00127     frB.stride(0) = 10;
00128     STKUNIT_EXPECT_EQ( frA == frB, true );
00129     STKUNIT_EXPECT_EQ( frA != frB, false );
00130   }
00131   {
00132     stk::mesh::FieldRestriction frA(1,1);
00133     frA.stride(0) = 3;
00134     stk::mesh::FieldRestriction frB(1,2);
00135     frB.stride(0) = 3;
00136     STKUNIT_EXPECT_EQ( frA == frB, false );
00137     STKUNIT_EXPECT_EQ( frA != frB, true );
00138   }
00139   {
00140     stk::mesh::FieldRestriction frA(1,2);
00141     stk::mesh::FieldRestriction frB(2,2);
00142     STKUNIT_EXPECT_EQ( frA == frB, false );
00143     STKUNIT_EXPECT_EQ( frA != frB, true );
00144   }
00145   {
00146     stk::mesh::FieldRestriction frA;
00147     stk::mesh::FieldRestriction frB;
00148     STKUNIT_EXPECT_EQ( frA == frB, true );
00149     STKUNIT_EXPECT_EQ( frA != frB, false );
00150   }
00151 }
00152 
00153 
00154 STKUNIT_UNIT_TEST( UnitTestFieldRestriction, not_equal_stride )
00155 {
00156   {
00157     stk::mesh::FieldRestriction frA(1,2);
00158     frA.stride(0) = 25;
00159     stk::mesh::FieldRestriction frB(1,2);
00160     frB.stride(0) = 10;
00161     STKUNIT_EXPECT_EQ( frA.not_equal_stride(frB), true );
00162     STKUNIT_EXPECT_EQ( frB.not_equal_stride(frA), true );
00163   }
00164   {
00165     stk::mesh::FieldRestriction frA(1,2);
00166     for (stk::mesh::Ordinal i=0 ; i < stk::mesh::MaximumFieldDimension ; ++i ) {
00167       frA.stride(0) = i+1;
00168     }
00169     stk::mesh::FieldRestriction frB(1,2);
00170     for (stk::mesh::Ordinal i=0 ; i < stk::mesh::MaximumFieldDimension ; ++i ) {
00171       frB.stride(0) = i+1;
00172     }
00173     STKUNIT_EXPECT_EQ( frA.not_equal_stride(frB), false );
00174     STKUNIT_EXPECT_EQ( frB.not_equal_stride(frA), false );
00175     frB.stride(stk::mesh::MaximumFieldDimension-1) = 1;
00176     STKUNIT_EXPECT_EQ( frA.not_equal_stride(frB), true );
00177     STKUNIT_EXPECT_EQ( frB.not_equal_stride(frA), true );
00178   }
00179 }
00180 
00181 
00182 } //namespace <anonymous>
00183 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends