|
Sierra Toolkit Version of the Day
|
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 <stk_util/unit_test_support/stk_utest_macros.hpp> 00012 00013 #include <stk_mesh/base/Selector.hpp> 00014 #include <stk_mesh/base/Bucket.hpp> 00015 #include <stk_mesh/base/Part.hpp> 00016 #include <stk_mesh/base/Types.hpp> 00017 #include <stk_mesh/base/GetBuckets.hpp> 00018 #include <stk_util/environment/WallTime.hpp> 00019 00020 #include <stk_util/parallel/Parallel.hpp> 00021 00022 #include <stk_mesh/fixtures/SelectorFixture.hpp> 00023 00024 // Unit test the Selector in isolation 00025 00026 namespace { 00027 00028 using stk::mesh::fixtures::SelectorFixture ; 00029 00065 STKUNIT_UNIT_TEST( UnitTestSelector, one_SelectorFixture ) 00066 { 00067 SelectorFixture fix ; 00068 STKUNIT_EXPECT_TRUE(true); 00069 } 00070 00071 00075 STKUNIT_UNIT_TEST( UnitTestSelector, two_SelectorFixture ) 00076 { 00077 { 00078 SelectorFixture fix ; 00079 } 00080 { 00081 SelectorFixture fix ; 00082 } 00083 STKUNIT_EXPECT_TRUE(true); 00084 } 00085 00086 00087 00093 STKUNIT_UNIT_TEST( UnitTestSelector, A_12345 ) 00094 { 00095 SelectorFixture fix ; 00096 stk::mesh::Selector selector( fix.m_partA ); 00097 //std::cout << "Selector = " << selector << std::endl; 00098 00099 { 00100 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket() ; 00101 bool result = selector(bucket); 00102 STKUNIT_EXPECT_TRUE(result); 00103 } 00104 { 00105 const stk::mesh::Bucket & bucket = fix.m_entity2->bucket(); 00106 bool result = selector(bucket); 00107 STKUNIT_EXPECT_TRUE(result); 00108 } 00109 { 00110 const stk::mesh::Bucket & bucket = fix.m_entity3->bucket(); 00111 bool result = selector(bucket); 00112 STKUNIT_EXPECT_FALSE(result); 00113 } 00114 { 00115 const stk::mesh::Bucket & bucket = fix.m_entity4->bucket(); 00116 bool result = selector(bucket); 00117 STKUNIT_EXPECT_FALSE(result); 00118 } 00119 { 00120 const stk::mesh::Bucket & bucket = fix.m_entity5->bucket(); 00121 bool result = selector(bucket); 00122 STKUNIT_EXPECT_FALSE(result); 00123 } 00124 } 00125 00131 STKUNIT_UNIT_TEST( UnitTestSelector, Ac_12345 ) 00132 { 00133 SelectorFixture fix ; 00134 stk::mesh::Selector selector = ! fix.m_partA ; 00135 //std::cout << "Selector = " << selector << std::endl; 00136 00137 { 00138 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00139 bool result = selector(bucket); 00140 STKUNIT_EXPECT_FALSE(result); 00141 } 00142 { 00143 const stk::mesh::Bucket & bucket = fix.m_entity2->bucket(); 00144 bool result = selector(bucket); 00145 STKUNIT_EXPECT_FALSE(result); 00146 } 00147 { 00148 const stk::mesh::Bucket & bucket = fix.m_entity3->bucket(); 00149 bool result = selector(bucket); 00150 STKUNIT_EXPECT_TRUE(result); 00151 } 00152 { 00153 const stk::mesh::Bucket & bucket = fix.m_entity4->bucket(); 00154 bool result = selector(bucket); 00155 STKUNIT_EXPECT_TRUE(result); 00156 } 00157 { 00158 const stk::mesh::Bucket & bucket = fix.m_entity5->bucket(); 00159 bool result = selector(bucket); 00160 STKUNIT_EXPECT_TRUE(result); 00161 } 00162 00163 } 00164 00168 STKUNIT_UNIT_TEST( UnitTestSelector, D_5 ) 00169 { 00170 SelectorFixture fix ; 00171 stk::mesh::Selector selector( fix.m_partD ); 00172 00173 const stk::mesh::Bucket & bucket = fix.m_entity5->bucket(); 00174 00175 bool result = selector(bucket); 00176 STKUNIT_EXPECT_FALSE(result); 00177 } 00178 00182 STKUNIT_UNIT_TEST( UnitTestSelector, Ac_15 ) 00183 { 00184 SelectorFixture fix ; 00185 stk::mesh::Part & partA = fix.m_partA ; 00186 00187 stk::mesh::Selector selector(partA); 00188 selector.complement(); 00189 //std::cout << "Selector = " << selector << std::endl; 00190 00191 { 00192 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00193 bool result = selector(bucket); 00194 STKUNIT_EXPECT_FALSE(result); 00195 } 00196 { 00197 const stk::mesh::Bucket & bucket = fix.m_entity5->bucket(); 00198 bool result = selector(bucket); 00199 STKUNIT_EXPECT_TRUE(result); 00200 } 00201 } 00202 00207 STKUNIT_UNIT_TEST( UnitTestSelector, AiB_12 ) 00208 { 00209 SelectorFixture fix ; 00210 stk::mesh::Part & partA = fix.m_partA ; 00211 stk::mesh::Part & partB = fix.m_partB ; 00212 00213 stk::mesh::Selector selector = partA & partB; 00214 //std::cout << "Selector = " << selector << std::endl; 00215 00216 { 00217 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00218 bool result = selector(bucket); 00219 STKUNIT_EXPECT_FALSE(result); 00220 } 00221 { 00222 const stk::mesh::Bucket & bucket = fix.m_entity2->bucket(); 00223 bool result = selector(bucket); 00224 STKUNIT_EXPECT_TRUE(result); 00225 } 00226 } 00227 00228 00232 STKUNIT_UNIT_TEST( UnitTestSelector, AuB_14 ) 00233 { 00234 SelectorFixture fix ; 00235 stk::mesh::Part & partA = fix.m_partA ; 00236 stk::mesh::Part & partB = fix.m_partB ; 00237 00238 stk::mesh::Selector selector = partA | partB; 00239 //std::cout << "Selector = " << selector << std::endl; 00240 00241 { 00242 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00243 bool result = selector(bucket); 00244 STKUNIT_EXPECT_TRUE(result); 00245 } 00246 { 00247 const stk::mesh::Bucket & bucket = fix.m_entity4->bucket(); 00248 bool result = selector(bucket); 00249 STKUNIT_EXPECT_FALSE(result); 00250 } 00251 } 00252 00253 00257 STKUNIT_UNIT_TEST( UnitTestSelector, AiBc_12 ) 00258 { 00259 SelectorFixture fix ; 00260 stk::mesh::Part & partA = fix.m_partA ; 00261 stk::mesh::Part & partB = fix.m_partB ; 00262 00263 stk::mesh::Selector selector = partA & !partB; 00264 //std::cout << "Selector = " << selector << std::endl; 00265 00266 { 00267 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00268 bool result = selector(bucket); 00269 STKUNIT_EXPECT_TRUE(result); 00270 } 00271 { 00272 const stk::mesh::Bucket & bucket = fix.m_entity2->bucket(); 00273 bool result = selector(bucket); 00274 STKUNIT_EXPECT_FALSE(result); 00275 } 00276 } 00277 00278 00282 STKUNIT_UNIT_TEST( UnitTestSelector, AuBc_13 ) 00283 { 00284 SelectorFixture fix ; 00285 stk::mesh::Part & partA = fix.m_partA ; 00286 stk::mesh::Part & partB = fix.m_partB ; 00287 00288 stk::mesh::Selector selector = partA | !partB; 00289 //std::cout << "Selector = " << selector << std::endl; 00290 00291 { 00292 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00293 bool result = selector(bucket); 00294 STKUNIT_EXPECT_TRUE(result); 00295 } 00296 { 00297 const stk::mesh::Bucket & bucket = fix.m_entity3->bucket(); 00298 bool result = selector(bucket); 00299 STKUNIT_EXPECT_FALSE(result); 00300 } 00301 } 00302 00303 00304 // plus copy constructor 00309 STKUNIT_UNIT_TEST( UnitTestSelector, Ai_BuC_c_12 ) 00310 { 00311 SelectorFixture fix ; 00312 stk::mesh::Part & partA = fix.m_partA ; 00313 stk::mesh::Part & partB = fix.m_partB ; 00314 stk::mesh::Part & partC = fix.m_partC ; 00315 00316 stk::mesh::Selector selector = partA & !(partB | partC); 00317 //std::cout << "Selector = " << selector << std::endl; 00318 00319 { 00320 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00321 bool result = selector(bucket); 00322 STKUNIT_EXPECT_TRUE(result); 00323 } 00324 { 00325 const stk::mesh::Bucket & bucket = fix.m_entity2->bucket(); 00326 bool result = selector(bucket); 00327 STKUNIT_EXPECT_FALSE(result); 00328 } 00329 00330 stk::mesh::Selector newSelector(selector); 00331 // Should be the same: 00332 { 00333 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00334 bool result = newSelector(bucket); 00335 STKUNIT_EXPECT_TRUE(result); 00336 } 00337 { 00338 const stk::mesh::Bucket & bucket = fix.m_entity2->bucket(); 00339 bool result = newSelector(bucket); 00340 STKUNIT_EXPECT_FALSE(result); 00341 } 00342 00343 } 00344 00345 00349 STKUNIT_UNIT_TEST( UnitTestSelector, entityTest ) 00350 { 00351 { 00352 SelectorFixture fix ; 00353 stk::mesh::Part & partA = fix.m_partA ; 00354 stk::mesh::Part & partB = fix.m_partB ; 00355 stk::mesh::Selector selector = partA & !partB; 00356 00357 const stk::mesh::Entity & pEntity = *fix.m_entity5; 00358 bool result = selector(pEntity); 00359 STKUNIT_EXPECT_FALSE(result); 00360 } 00361 00362 } 00363 00367 STKUNIT_UNIT_TEST( UnitTestSelector, defaultConstructor ) 00368 { 00369 SelectorFixture fix ; 00370 stk::mesh::Selector selector; 00371 //std::cout << "Selector = " << selector << std::endl; 00372 00373 { 00374 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00375 bool result = selector(bucket); 00376 STKUNIT_EXPECT_FALSE(result); 00377 } 00378 } 00379 00380 00388 STKUNIT_UNIT_TEST( UnitTestSelector, flipComplement_AuB_c ) 00389 { 00390 SelectorFixture fix ; 00391 stk::mesh::Part & partA = fix.m_partA ; 00392 stk::mesh::Part & partB = fix.m_partB ; 00393 stk::mesh::Selector notOrSelector = partA | partB; 00394 //std::cout << "Or Selector = " << notOrSelector << std::endl; 00395 notOrSelector.complement(); 00396 //std::cout << "Not Or Selector = " << notOrSelector << std::endl; 00397 00398 { 00399 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00400 bool result = notOrSelector(bucket); 00401 STKUNIT_EXPECT_FALSE(result); 00402 } 00403 { 00404 const stk::mesh::Bucket & bucket = fix.m_entity2->bucket(); 00405 bool result = notOrSelector(bucket); 00406 STKUNIT_EXPECT_FALSE(result); 00407 } 00408 { 00409 const stk::mesh::Bucket & bucket = fix.m_entity3->bucket(); 00410 bool result = notOrSelector(bucket); 00411 STKUNIT_EXPECT_FALSE(result); 00412 } 00413 { 00414 const stk::mesh::Bucket & bucket = fix.m_entity4->bucket(); 00415 bool result = notOrSelector(bucket); 00416 STKUNIT_EXPECT_TRUE(result); 00417 } 00418 00419 stk::mesh::Selector notNotOrSelector = !notOrSelector; 00420 //std::cout << "Not Not Or Selector = " << notNotOrSelector << std::endl; 00421 { 00422 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00423 bool result = notNotOrSelector(bucket); 00424 STKUNIT_EXPECT_TRUE(result); 00425 } 00426 { 00427 const stk::mesh::Bucket & bucket = fix.m_entity2->bucket(); 00428 bool result = notNotOrSelector(bucket); 00429 STKUNIT_EXPECT_TRUE(result); 00430 } 00431 { 00432 const stk::mesh::Bucket & bucket = fix.m_entity3->bucket(); 00433 bool result = notNotOrSelector(bucket); 00434 STKUNIT_EXPECT_TRUE(result); 00435 } 00436 { 00437 const stk::mesh::Bucket & bucket = fix.m_entity4->bucket(); 00438 bool result = notNotOrSelector(bucket); 00439 STKUNIT_EXPECT_FALSE(result); 00440 } 00441 } 00442 00450 STKUNIT_UNIT_TEST( UnitTestSelector, flipComplement_AiB_c ) 00451 { 00452 SelectorFixture fix ; 00453 stk::mesh::Part & partA = fix.m_partA ; 00454 stk::mesh::Part & partB = fix.m_partB ; 00455 stk::mesh::Selector notAndSelector = partA & partB; 00456 //std::cout << "And Selector = " << notAndSelector << std::endl; 00457 notAndSelector.complement(); 00458 //std::cout << "Not And Selector = " << notAndSelector << std::endl; 00459 00460 { 00461 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00462 bool result = notAndSelector(bucket); 00463 STKUNIT_EXPECT_TRUE(result); 00464 } 00465 { 00466 const stk::mesh::Bucket & bucket = fix.m_entity2->bucket(); 00467 bool result = notAndSelector(bucket); 00468 STKUNIT_EXPECT_FALSE(result); 00469 } 00470 { 00471 const stk::mesh::Bucket & bucket = fix.m_entity3->bucket(); 00472 bool result = notAndSelector(bucket); 00473 STKUNIT_EXPECT_TRUE(result); 00474 } 00475 { 00476 const stk::mesh::Bucket & bucket = fix.m_entity4->bucket(); 00477 bool result = notAndSelector(bucket); 00478 STKUNIT_EXPECT_TRUE(result); 00479 } 00480 00481 stk::mesh::Selector notNotAndSelector = !notAndSelector; 00482 //std::cout << "Not Not And Selector = " << notNotAndSelector << std::endl; 00483 { 00484 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00485 bool result = notNotAndSelector(bucket); 00486 STKUNIT_EXPECT_FALSE(result); 00487 } 00488 { 00489 const stk::mesh::Bucket & bucket = fix.m_entity2->bucket(); 00490 bool result = notNotAndSelector(bucket); 00491 STKUNIT_EXPECT_TRUE(result); 00492 } 00493 { 00494 const stk::mesh::Bucket & bucket = fix.m_entity3->bucket(); 00495 bool result = notNotAndSelector(bucket); 00496 STKUNIT_EXPECT_FALSE(result); 00497 } 00498 { 00499 const stk::mesh::Bucket & bucket = fix.m_entity4->bucket(); 00500 bool result = notNotAndSelector(bucket); 00501 STKUNIT_EXPECT_FALSE(result); 00502 } 00503 } 00504 00511 STKUNIT_UNIT_TEST( UnitTestSelector, complementEmpty ) { 00512 SelectorFixture fix ; 00513 stk::mesh::Selector selector; 00514 { 00515 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00516 bool result = selector(bucket); 00517 STKUNIT_EXPECT_FALSE(result); 00518 } 00519 selector.complement(); 00520 { 00521 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00522 bool result = selector(bucket); 00523 STKUNIT_EXPECT_TRUE(result); 00524 } 00525 } 00526 00527 00532 STKUNIT_UNIT_TEST( UnitTestSelector, AuBuCuD ) 00533 { 00534 SelectorFixture fix ; 00535 stk::mesh::Part & partA = fix.m_partA ; 00536 stk::mesh::Part & partB = fix.m_partB ; 00537 stk::mesh::Part & partC = fix.m_partC ; 00538 stk::mesh::Part & partD = fix.m_partD ; 00539 stk::mesh::Selector selector = partA | partB | partC | partD; 00540 std::cout << "A|B|C|D = " << selector << std::endl; 00541 std::ostringstream msg; 00542 msg << selector; 00543 STKUNIT_EXPECT_EQUAL( "!(!PartA AND !PartB AND !PartC AND !PartD)" , msg.str() ); 00544 } 00545 00546 00550 STKUNIT_UNIT_TEST( UnitTestSelector, AiBiC ) 00551 { 00552 SelectorFixture fix ; 00553 stk::mesh::Part & partA = fix.m_partA ; 00554 stk::mesh::Part & partB = fix.m_partB ; 00555 stk::mesh::Part & partC = fix.m_partC ; 00556 stk::mesh::Selector selector = partA & partB & partC; 00557 std::cout << "A&B&C = " << selector << std::endl; 00558 std::ostringstream msg; 00559 msg << selector; 00560 STKUNIT_EXPECT_TRUE( msg.str() == "PartA AND PartB AND PartC" ); 00561 } 00562 00563 00567 STKUNIT_UNIT_TEST( UnitTestSelector, complicated ) 00568 { 00569 SelectorFixture fix ; 00570 stk::mesh::Part & partA = fix.m_partA ; 00571 stk::mesh::Part & partB = fix.m_partB ; 00572 stk::mesh::Part & partC = fix.m_partC ; 00573 stk::mesh::Part & partD = fix.m_partD ; 00574 stk::mesh::Selector selector = partA | ( !((partA & partB) | partC) & (!partD | partB)); 00575 std::cout << "complicated selector = " << selector << std::endl; 00576 std::ostringstream msg; 00577 msg << selector; 00578 STKUNIT_EXPECT_EQUAL( "!(!PartA AND !((!(PartA AND PartB) AND !PartC) AND !(PartD AND !PartB)))" , msg.str() ); 00579 } 00580 00581 00586 STKUNIT_UNIT_TEST( UnitTestSelector, selectIntersection ) 00587 { 00588 SelectorFixture fix ; 00589 stk::mesh::PartVector parts ; 00590 parts.push_back( & fix.m_partA ); 00591 parts.push_back( & fix.m_partB ); 00592 stk::mesh::Selector selector = selectIntersection(parts); 00593 00594 { 00595 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00596 bool result = selector(bucket); 00597 STKUNIT_ASSERT_FALSE(result); 00598 } 00599 { 00600 const stk::mesh::Bucket & bucket = fix.m_entity2->bucket(); 00601 bool result = selector(bucket); 00602 STKUNIT_ASSERT_TRUE(result); 00603 } 00604 { 00605 const stk::mesh::Bucket & bucket = fix.m_entity3->bucket(); 00606 bool result = selector(bucket); 00607 STKUNIT_ASSERT_FALSE(result); 00608 } 00609 { 00610 const stk::mesh::Bucket & bucket = fix.m_entity4->bucket(); 00611 bool result = selector(bucket); 00612 STKUNIT_ASSERT_FALSE(result); 00613 } 00614 { 00615 const stk::mesh::Bucket & bucket = fix.m_entity5->bucket(); 00616 bool result = selector(bucket); 00617 STKUNIT_ASSERT_FALSE(result); 00618 } 00619 00620 std::ostringstream msg; 00621 msg << selector; 00622 STKUNIT_EXPECT_TRUE( msg.str() == "PartA AND PartB"); 00623 } 00624 00625 00630 STKUNIT_UNIT_TEST( UnitTestSelector, selectUnion ) 00631 { 00632 SelectorFixture fix ; 00633 stk::mesh::PartVector parts ; 00634 parts.push_back( & fix.m_partA ); 00635 parts.push_back( & fix.m_partB ); 00636 parts.push_back( & fix.m_partC ); 00637 stk::mesh::Selector selector = selectUnion(parts); 00638 00639 { 00640 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00641 bool result = selector(bucket); 00642 STKUNIT_ASSERT_TRUE(result); 00643 } 00644 { 00645 const stk::mesh::Bucket & bucket = fix.m_entity2->bucket(); 00646 bool result = selector(bucket); 00647 STKUNIT_ASSERT_TRUE(result); 00648 } 00649 { 00650 const stk::mesh::Bucket & bucket = fix.m_entity3->bucket(); 00651 bool result = selector(bucket); 00652 STKUNIT_ASSERT_TRUE(result); 00653 } 00654 { 00655 const stk::mesh::Bucket & bucket = fix.m_entity4->bucket(); 00656 bool result = selector(bucket); 00657 STKUNIT_ASSERT_TRUE(result); 00658 } 00659 { 00660 const stk::mesh::Bucket & bucket = fix.m_entity5->bucket(); 00661 bool result = selector(bucket); 00662 STKUNIT_ASSERT_FALSE(result); 00663 } 00664 00665 std::ostringstream msg; 00666 msg << selector; 00667 std::cout << "msg.str() = " << msg.str() << std::endl; 00668 STKUNIT_EXPECT_EQUAL( "!(!PartA AND !PartB AND !PartC)", msg.str() ); 00669 } 00670 00671 // Intersection first then union 00672 // & before | 00678 //STKUNIT_UNIT_TEST( UnitTestSelector, orderOfOperations ) 00679 //{ 00680 // SelectorFixture fix ; 00681 // stk::mesh::Part & partA = fix.m_partA ; 00682 // stk::mesh::Part & partB = fix.m_partB ; 00683 // stk::mesh::Part & partC = fix.m_partC ; 00684 // { 00685 // stk::mesh::Selector selector = partA | partB & partC; 00686 // //std::cout << "A|B&C selector = " << selector << std::endl; 00687 // std::ostringstream msg; 00688 // msg << selector; 00689 // STKUNIT_EXPECT_EQUAL( "!(!PartA AND !(PartB AND PartC))", msg.str() ); 00690 // { 00691 // const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00692 // bool result = selector(bucket); 00693 // STKUNIT_EXPECT_TRUE(result); 00694 // } 00695 // { 00696 // const stk::mesh::Bucket & bucket = fix.m_entity2->bucket(); 00697 // bool result = selector(bucket); 00698 // STKUNIT_EXPECT_TRUE(result); 00699 // } 00700 // { 00701 // const stk::mesh::Bucket & bucket = fix.m_entity3->bucket(); 00702 // bool result = selector(bucket); 00703 // STKUNIT_EXPECT_TRUE(result); 00704 // } 00705 // { 00706 // const stk::mesh::Bucket & bucket = fix.m_entity4->bucket(); 00707 // bool result = selector(bucket); 00708 // STKUNIT_EXPECT_FALSE(result); 00709 // } 00710 // } 00711 // { 00712 // stk::mesh::Selector selector = partB & partC | partA; 00713 // //std::cout << "B&C|A selector = " << selector << std::endl; 00714 // std::ostringstream msg; 00715 // msg << selector; 00716 // STKUNIT_EXPECT_EQUAL( "!(!(PartB AND PartC) AND !PartA)", msg.str() ); 00717 // { 00718 // const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00719 // bool result = selector(bucket); 00720 // STKUNIT_EXPECT_TRUE(result); 00721 // } 00722 // { 00723 // const stk::mesh::Bucket & bucket = fix.m_entity2->bucket(); 00724 // bool result = selector(bucket); 00725 // STKUNIT_EXPECT_TRUE(result); 00726 // } 00727 // { 00728 // const stk::mesh::Bucket & bucket = fix.m_entity3->bucket(); 00729 // bool result = selector(bucket); 00730 // STKUNIT_EXPECT_TRUE(result); 00731 // } 00732 // { 00733 // const stk::mesh::Bucket & bucket = fix.m_entity4->bucket(); 00734 // bool result = selector(bucket); 00735 // STKUNIT_EXPECT_FALSE(result); 00736 // } 00737 // } 00738 //} 00739 00740 00745 STKUNIT_UNIT_TEST( UnitTestSelector, ZeroiuZero ) { 00746 SelectorFixture fix ; 00747 stk::mesh::Selector selectNone; 00748 stk::mesh::Selector selectAll; 00749 selectAll.complement(); 00750 { 00751 stk::mesh::Selector selector = selectNone & selectAll; 00752 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00753 bool result = selector(bucket); 00754 STKUNIT_EXPECT_FALSE(result); 00755 } 00756 { 00757 stk::mesh::Selector selector = selectNone | selectAll; 00758 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00759 bool result = selector(bucket); 00760 STKUNIT_EXPECT_TRUE(result); 00761 } 00762 00763 } 00764 00765 00771 STKUNIT_UNIT_TEST( UnitTestSelector, AibA ) 00772 { 00773 SelectorFixture fix ; 00774 SelectorFixture fixHat ; 00775 stk::mesh::Part & partA = fix.m_partA ; 00776 stk::mesh::Part & partAhat = fixHat.m_partA ; 00777 stk::mesh::Selector selector(partA); 00778 STKUNIT_ASSERT_THROW( 00779 selector &= partAhat, 00780 std::runtime_error 00781 ); 00782 00783 } 00784 00790 STKUNIT_UNIT_TEST( UnitTestSelector, AubA ) 00791 { 00792 SelectorFixture fix ; 00793 SelectorFixture fixHat ; 00794 stk::mesh::Part & partA = fix.m_partA ; 00795 stk::mesh::Part & partAhat = fixHat.m_partA ; 00796 stk::mesh::Selector selector(partA); 00797 STKUNIT_ASSERT_THROW( 00798 selector |= partAhat, 00799 std::runtime_error 00800 ); 00801 00802 } 00803 00804 // (A)b1 throws 00811 STKUNIT_UNIT_TEST( UnitTestSelector, Ab1 ) 00812 { 00813 SelectorFixture fix ; 00814 stk::mesh::Part & partA = fix.m_partA ; 00815 stk::mesh::Selector selector = partA; 00816 SelectorFixture fixHat ; 00817 const stk::mesh::Bucket & bucketHat = fixHat.m_entity1->bucket(); 00818 bool result; 00819 STKUNIT_ASSERT_THROW( 00820 result = selector(bucketHat), 00821 std::runtime_error 00822 ); 00823 } 00824 00825 00835 STKUNIT_UNIT_TEST( UnitTestSelector, ZeroiuA ) 00836 { 00837 SelectorFixture fix ; 00838 stk::mesh::Part & partA = fix.m_partA ; 00839 stk::mesh::Selector selectNone; 00840 stk::mesh::Selector selectAll; 00841 selectAll.complement(); 00842 stk::mesh::Selector selectA = partA; 00843 stk::mesh::Selector selectNoneOrA = selectNone | selectA; 00844 stk::mesh::Selector selectAllAndA = selectAll & selectA; 00845 { 00846 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00847 bool result = selectNoneOrA(bucket); 00848 STKUNIT_EXPECT_TRUE(result); 00849 } 00850 { 00851 const stk::mesh::Bucket & bucket = fix.m_entity1->bucket(); 00852 bool result = selectAllAndA(bucket); 00853 STKUNIT_EXPECT_TRUE(result); 00854 } 00855 } 00856 00857 00861 STKUNIT_UNIT_TEST( UnitTestSelector, copyConstructor ) 00862 { 00863 SelectorFixture fix ; 00864 stk::mesh::Part & partA = fix.m_partA ; 00865 stk::mesh::Part & partB = fix.m_partB ; 00866 stk::mesh::Part & partC = fix.m_partC ; 00867 stk::mesh::Selector selectA = (partA & partB) | partC; 00868 stk::mesh::Selector anotherSelectA(selectA); 00869 std::ostringstream descriptionA; 00870 descriptionA << selectA; 00871 std::ostringstream descriptionAnotherA; 00872 descriptionAnotherA << anotherSelectA; 00873 STKUNIT_EXPECT_EQUAL( descriptionA.str() == descriptionAnotherA.str(), true ); 00874 } 00875 00876 00883 STKUNIT_UNIT_TEST( UnitTestSelector, AlliuAll ) 00884 { 00885 stk::mesh::Selector selectAll; 00886 selectAll.complement(); 00887 00888 stk::mesh::Selector anotherSelectAll; 00889 anotherSelectAll.complement(); 00890 00891 { 00892 stk::mesh::Selector selectAllANDAll = selectAll & anotherSelectAll; 00893 std::ostringstream description; 00894 description << selectAllANDAll; 00895 STKUNIT_EXPECT_EQUAL( "!() AND !()", description.str() ); 00896 } 00897 { 00898 stk::mesh::Selector selectAllORAll = selectAll | anotherSelectAll; 00899 std::ostringstream description; 00900 description << selectAllORAll; 00901 STKUNIT_EXPECT_EQUAL( "!(())", description.str() ); 00902 } 00903 } 00907 } // namespace