|
Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Teuchos: Common Tools Package 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #include "Teuchos_VerboseObject.hpp" 00043 #include "Teuchos_ParameterList.hpp" 00044 #include "Teuchos_StandardDependencies.hpp" 00045 #include "Teuchos_DependencySheet.hpp" 00046 #include "Teuchos_StandardConditions.hpp" 00047 #include "Teuchos_UnitTestHarness.hpp" 00048 00049 00050 namespace Teuchos{ 00051 00055 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testValiDeps){ 00056 RCP<ParameterList> My_deplist = rcp(new ParameterList); 00057 RCP<DependencySheet> depSheet1 = rcp(new DependencySheet); 00058 00059 /* 00060 * Testing StringValidatorDependency 00061 */ 00062 RCP<StringToIntegralParameterEntryValidator<int> > 00063 stringFoodTypeValidator = rcp( 00064 new StringToIntegralParameterEntryValidator<int>( 00065 tuple<std::string>( "Cheese", "Soda", "Chips" ) 00066 ,"Food Type" 00067 ) 00068 ); 00069 00070 RCP<StringToIntegralParameterEntryValidator<int> > 00071 cheeseValidator = rcp( 00072 new StringToIntegralParameterEntryValidator<int>( 00073 tuple<std::string>( "Swiss", "American", "Super Awesome Cheese" ) 00074 ,"Food Selector" 00075 ) 00076 ); 00077 00078 RCP<StringToIntegralParameterEntryValidator<int> > 00079 sodaValidator = rcp( 00080 new StringToIntegralParameterEntryValidator<int>( 00081 tuple<std::string>( "Pepsi", "Coke", "Kurtis Cola", "Bad Cola" ) 00082 ,"Food Selector" 00083 ) 00084 ); 00085 00086 RCP<StringToIntegralParameterEntryValidator<int> > 00087 chipsValidator = rcp( 00088 new StringToIntegralParameterEntryValidator<int>( 00089 tuple<std::string>( "Lays", "Doritos", "Kurtis Super Awesome Brand" ) 00090 ,"Food Selector" 00091 ) 00092 ); 00093 00094 StringValidatorDependency::ValueToValidatorMap testValidatorMap1; 00095 testValidatorMap1["Cheese"] = cheeseValidator; 00096 testValidatorMap1["Soda"] = sodaValidator; 00097 testValidatorMap1["Chips"] = chipsValidator; 00098 00099 ParameterList stringValiDepList = My_deplist->sublist( 00100 "String Validator Dependency", false, 00101 "String Validator Dependency testing list."); 00102 stringValiDepList.set( 00103 "Food Selector", "Swiss", "select the food you want", cheeseValidator); 00104 stringValiDepList.set( 00105 "Food Type", 00106 "Cheese", 00107 "String Validator Dependency Tester", 00108 stringFoodTypeValidator); 00109 00110 RCP<StringValidatorDependency> 00111 stringValiDep = rcp( 00112 new StringValidatorDependency( 00113 stringValiDepList.getEntryRCP("Food Type"), 00114 stringValiDepList.getEntryRCP("Food Selector"), 00115 testValidatorMap1, 00116 cheeseValidator 00117 ) 00118 ); 00119 00120 depSheet1->addDependency(stringValiDep); 00121 00122 TEST_NOTHROW(stringValiDepList.validateParameters(stringValiDepList)); 00123 TEST_ASSERT(depSheet1->hasDependents( 00124 stringValiDepList.getEntryRCP("Food Type"))); 00125 RCP<const DependencySheet::DepSet> stringValiDepSet = 00126 depSheet1->getDependenciesForParameter( 00127 stringValiDepList.getEntryRCP("Food Type")); 00128 TEST_ASSERT(stringValiDepSet->size() == 1); 00129 stringValiDepList.set("Food Type","Soda"); 00130 stringValiDep->evaluate(); 00131 TEST_ASSERT(stringValiDepList.getEntry("Food Selector").validator() 00132 == 00133 sodaValidator); 00134 TEST_THROW(stringValiDepList.validateParameters(stringValiDepList), 00135 Exceptions::InvalidParameterValue); 00136 stringValiDepList.set("Food Selector", "Pepsi"); 00137 TEST_NOTHROW(stringValiDepList.validateParameters(stringValiDepList)); 00138 00139 00140 /* 00141 * Tesing some different aspects of the StringValidatorDependency 00142 */ 00143 ParameterList 00144 stringValiDepList2 = My_deplist->sublist( 00145 "String Validator Dependency (other validators)", 00146 false, 00147 "String validator testing" 00148 ); 00149 00150 RCP<StringToIntegralParameterEntryValidator<int> > 00151 stringRangeValidator = rcp( 00152 new StringToIntegralParameterEntryValidator<int>( 00153 tuple<std::string>( "1-10", "10-33", "50-60" ), 00154 "Range selector" 00155 ) 00156 ); 00157 00158 RCP<EnhancedNumberValidator<int> > range110Vali = 00159 rcp(new EnhancedNumberValidator<int>(1,10)); 00160 RCP<EnhancedNumberValidator<int> > range1033Vali = 00161 rcp(new EnhancedNumberValidator<int>(10,33)); 00162 RCP<EnhancedNumberValidator<int> > range5060Vali = 00163 rcp(new EnhancedNumberValidator<int>(50,60)); 00164 00165 stringValiDepList2.set("Range selector", "1-10", 00166 "selects the range to validate", stringRangeValidator); 00167 00168 StringValidatorDependency::ValueToValidatorMap rangeValidatorMap1; 00169 rangeValidatorMap1["1-10"] = range110Vali; 00170 rangeValidatorMap1["10-33"] = range1033Vali; 00171 rangeValidatorMap1["50-60"] = range5060Vali; 00172 stringValiDepList2.set( 00173 "RangeValue", 3, "the value of the range", range110Vali); 00174 00175 RCP<StringValidatorDependency> 00176 stringValiDep2 = RCP<StringValidatorDependency>( 00177 new StringValidatorDependency( 00178 stringValiDepList2.getEntryRCP("Range selector"), 00179 stringValiDepList2.getEntryRCP("RangeValue"), 00180 rangeValidatorMap1, 00181 range110Vali 00182 ) 00183 ); 00184 00185 depSheet1->addDependency(stringValiDep2); 00186 00187 TEST_NOTHROW(stringValiDepList2.validateParameters(stringValiDepList2)); 00188 TEST_ASSERT(depSheet1->hasDependents( 00189 stringValiDepList2.getEntryRCP("Range selector"))); 00190 RCP<const DependencySheet::DepSet> stringValiDepSet2 = 00191 depSheet1->getDependenciesForParameter( 00192 stringValiDepList2.getEntryRCP("Range selector")); 00193 TEST_ASSERT(stringValiDepSet2->size() == 1); 00194 stringValiDepList2.set("Range selector","50-60"); 00195 stringValiDep2->evaluate(); 00196 TEST_ASSERT(stringValiDepList2.getEntry("RangeValue").validator() 00197 == 00198 range5060Vali); 00199 TEST_THROW(stringValiDepList2.validateParameters(stringValiDepList2), 00200 Exceptions::InvalidParameterValue); 00201 stringValiDepList2.set("RangeValue", 55); 00202 TEST_NOTHROW(stringValiDepList2.validateParameters(stringValiDepList2)); 00203 00204 /* 00205 * Testing the BoolValidatorDependency. 00206 */ 00207 ParameterList 00208 boolValidatorDepList = My_deplist->sublist( 00209 "Bool Validator Dependency List", 00210 false, 00211 "Bool Validator Dependency testing list." 00212 ); 00213 00214 boolValidatorDepList.set("Use Validator?", 00215 true, "truns the validator on and off"); 00216 RCP<EnhancedNumberValidator<int> > basicVali = 00217 rcp(new EnhancedNumberValidator<int>(1,10)); 00218 RCP<EnhancedNumberValidator<int> > basicVali2 = 00219 rcp(new EnhancedNumberValidator<int>()); 00220 boolValidatorDepList.set("do I have a validator?", 00221 4, "does it have a validator?", basicVali); 00222 00223 RCP<BoolValidatorDependency> 00224 boolValiDep = RCP<BoolValidatorDependency>( 00225 new BoolValidatorDependency( 00226 boolValidatorDepList.getEntryRCP("Use Validator?"), 00227 boolValidatorDepList.getEntryRCP("do I have a validator?"), 00228 basicVali, 00229 basicVali2 00230 ) 00231 ); 00232 00233 depSheet1->addDependency(boolValiDep); 00234 00235 TEST_ASSERT(depSheet1->hasDependents( 00236 boolValidatorDepList.getEntryRCP("Use Validator?"))); 00237 TEST_ASSERT( 00238 boolValidatorDepList.getEntry("do I have a validator?").validator() 00239 == 00240 basicVali); 00241 TEST_NOTHROW( 00242 boolValidatorDepList.validateParameters(boolValidatorDepList)); 00243 RCP<const DependencySheet::DepSet> boolValiDepSet = 00244 depSheet1->getDependenciesForParameter(boolValidatorDepList.getEntryRCP( 00245 "Use Validator?")); 00246 TEST_ASSERT(boolValiDepSet->size() == 1); 00247 boolValidatorDepList.set("Use Validator?",false); 00248 boolValiDep->evaluate(); 00249 TEST_ASSERT( 00250 boolValidatorDepList.getEntry("do I have a validator?").validator() 00251 == 00252 basicVali2); 00253 00254 00255 /* 00256 * Testing the RangeValidatorDependency 00257 */ 00258 RCP<StringToIntegralParameterEntryValidator<int> > 00259 lowTempCheeseValidator = rcp( 00260 new StringToIntegralParameterEntryValidator<int>( 00261 tuple<std::string>( "PepperJack", "Swiss", "American" ), 00262 "Cheese to Fondue" 00263 ) 00264 ); 00265 00266 RCP<StringToIntegralParameterEntryValidator<int> > 00267 highTempCheeseValidator = rcp( 00268 new StringToIntegralParameterEntryValidator<int>( 00269 tuple<std::string>( 00270 "Munster", "Provalone", "Kurtis Super Awesome Cheese"), 00271 "Cheese to Fondue" 00272 ) 00273 ); 00274 00275 RCP<StringToIntegralParameterEntryValidator<int> > 00276 defaultCheeseValidator = rcp( 00277 new StringToIntegralParameterEntryValidator<int>( 00278 tuple<std::string>( 00279 "Other cheese", "other cheese 1", "other cheese 3"), 00280 "Cheese to Fondue" 00281 ) 00282 ); 00283 00284 ParameterList& 00285 rangeValidatorDepList = My_deplist->sublist( 00286 "Range Validator Dependency List", 00287 false, 00288 "Range Validator Dependency testing list.\nWorking June 27th 2009" 00289 ); 00290 rangeValidatorDepList.set( 00291 "Temperature",101.0, "The temperature of the fondue"); 00292 rangeValidatorDepList.set( 00293 "Cheese to Fondue", "Swiss", 00294 "The cheese we'll be using in our fondue pot.", lowTempCheeseValidator); 00295 RangeValidatorDependency<double>::RangeToValidatorMap tempranges; 00296 tempranges[std::pair<double,double>(100,200)] = lowTempCheeseValidator; 00297 tempranges[std::pair<double,double>(200,300)] = highTempCheeseValidator; 00298 RCP<RangeValidatorDependency<double> > 00299 cheeseTempDep = RCP<RangeValidatorDependency<double> >( 00300 new RangeValidatorDependency<double>( 00301 rangeValidatorDepList.getEntryRCP("Temperature"), 00302 rangeValidatorDepList.getEntryRCP("Cheese to Fondue"), 00303 tempranges, 00304 defaultCheeseValidator 00305 ) 00306 ); 00307 depSheet1->addDependency(cheeseTempDep); 00308 00309 TEST_ASSERT(depSheet1->hasDependents( 00310 rangeValidatorDepList.getEntryRCP("Temperature"))); 00311 RCP<const DependencySheet::DepSet> rangeValiDepSet = 00312 depSheet1->getDependenciesForParameter( 00313 rangeValidatorDepList.getEntryRCP("Temperature")); 00314 TEST_ASSERT(rangeValiDepSet->size() == 1); 00315 rangeValidatorDepList.set("Temperature",250.0); 00316 cheeseTempDep->evaluate(); 00317 TEST_ASSERT( 00318 rangeValidatorDepList.getEntry("Cheese to Fondue").validator() 00319 == 00320 highTempCheeseValidator); 00321 TEST_THROW( 00322 rangeValidatorDepList.validateParameters(rangeValidatorDepList), 00323 Exceptions::InvalidParameterValue); 00324 rangeValidatorDepList.set("Cheese to Fondue", "Provalone"); 00325 TEST_NOTHROW( 00326 rangeValidatorDepList.validateParameters(rangeValidatorDepList)); 00327 rangeValidatorDepList.set("Temperature", 50.0); 00328 cheeseTempDep->evaluate(); 00329 TEST_ASSERT( 00330 rangeValidatorDepList.getEntry("Cheese to Fondue").validator() 00331 == 00332 defaultCheeseValidator 00333 ); 00334 00335 } 00336 00340 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testVisualDeps){ 00341 RCP<ParameterList> My_deplist = RCP<ParameterList>(new ParameterList); 00342 RCP<DependencySheet> depSheet1 = 00343 RCP<DependencySheet>(new DependencySheet); 00344 /* 00345 * Two Simple NumberVisualDependency test 00346 */ 00347 00348 ParameterList 00349 simpleNumDepTestList = My_deplist->sublist( 00350 "NumberVisual Dependency List (double)", 00351 false, 00352 "Number visual Dependency testing list" 00353 ); 00354 00355 simpleNumDepTestList.set("Temperature",101.0); 00356 simpleNumDepTestList.set("Cheese to Fondue", "Swiss", "The cheese to fondue"); 00357 simpleNumDepTestList.set("reverse param", "hello"); 00358 00359 RCP<NumberVisualDependency<double> > simpleNumDep = 00360 RCP<NumberVisualDependency<double> >( 00361 new NumberVisualDependency<double>( 00362 simpleNumDepTestList.getEntryRCP("Temperature"), 00363 simpleNumDepTestList.getEntryRCP("Cheese to Fondue"), 00364 true 00365 ) 00366 ); 00367 RCP<NumberVisualDependency<double> > reverseNumDep = 00368 RCP<NumberVisualDependency<double> >( 00369 new NumberVisualDependency<double>( 00370 simpleNumDepTestList.getEntryRCP("Temperature"), 00371 simpleNumDepTestList.getEntryRCP("reverse param"), 00372 false 00373 ) 00374 ); 00375 depSheet1->addDependency(simpleNumDep); 00376 depSheet1->addDependency(reverseNumDep); 00377 simpleNumDep->evaluate(); 00378 reverseNumDep->evaluate(); 00379 TEST_ASSERT(simpleNumDep->isDependentVisible()); 00380 TEST_ASSERT(!reverseNumDep->isDependentVisible()); 00381 simpleNumDepTestList.set("Temperature",-1.0); 00382 simpleNumDep->evaluate(); 00383 reverseNumDep->evaluate(); 00384 TEST_ASSERT(!simpleNumDep->isDependentVisible()); 00385 TEST_ASSERT(reverseNumDep->isDependentVisible()); 00386 00387 00388 /* 00389 * complex Testing the NumberVisualDependency 00390 */ 00391 ParameterList 00392 doubleVisualDepList = My_deplist->sublist( 00393 "NumberVisual Dependency List (double)", 00394 false, 00395 "Number visual Dependency testing list" 00396 ); 00397 00398 doubleVisualDepList.set( 00399 "Temperature",101.0, "The temperature of the fondue"); 00400 doubleVisualDepList.set( 00401 "Cheese to Fondue", "Swiss", "The cheese to fondue"); 00402 doubleVisualDepList.set("reverse param", "hello"); 00403 RCP<SubtractionFunction<double> > fondueFunc = rcp(new 00404 SubtractionFunction<double>(100)); 00405 00406 RCP<NumberVisualDependency<double> > fondueDep = 00407 RCP<NumberVisualDependency<double> >( 00408 new NumberVisualDependency<double>( 00409 doubleVisualDepList.getEntryRCP("Temperature"), 00410 doubleVisualDepList.getEntryRCP("Cheese to Fondue"), 00411 true, 00412 fondueFunc 00413 ) 00414 ); 00415 RCP<NumberVisualDependency<double> > reverseFondueDep = 00416 RCP<NumberVisualDependency<double> >( 00417 new NumberVisualDependency<double>( 00418 doubleVisualDepList.getEntryRCP("Temperature"), 00419 doubleVisualDepList.getEntryRCP("reverse param"), 00420 false, 00421 fondueFunc 00422 ) 00423 ); 00424 depSheet1->addDependency(fondueDep); 00425 depSheet1->addDependency(reverseFondueDep); 00426 fondueDep->evaluate(); 00427 reverseFondueDep->evaluate(); 00428 TEST_ASSERT(fondueDep->isDependentVisible()); 00429 TEST_ASSERT(!reverseFondueDep->isDependentVisible()); 00430 doubleVisualDepList.set("Temperature",99.0); 00431 fondueDep->evaluate(); 00432 reverseFondueDep->evaluate(); 00433 TEST_ASSERT(!fondueDep->isDependentVisible()); 00434 TEST_ASSERT(reverseFondueDep->isDependentVisible()); 00435 00436 /* 00437 * Testing the BoolVisualDependency 00438 */ 00439 ParameterList& 00440 boolVisDepList = My_deplist->sublist( 00441 "Bool Visual Dependency List", 00442 false, 00443 "Bool Visual Dependency testing list." 00444 ); 00445 boolVisDepList.set( 00446 "ShowPrecs", true, "Whether or not to should the Preciondtioner list"); 00447 ParameterList 00448 Prec_List0 = boolVisDepList.sublist( 00449 "Preconditioner",false,"Sublist that defines the preconditioner."); 00450 Prec_List0.set("Type", "ILU", "The tpye of preconditioner to use"); 00451 RCP<EnhancedNumberValidator<double> > droptolValidator = 00452 rcp(new EnhancedNumberValidator<double>(0,10,1e-3)); 00453 Prec_List0.set( 00454 "Drop Tolerance", 1e-3, 00455 "The tolerance below which entries from the " 00456 "factorization are left out of the factors.", droptolValidator); 00457 RCP<BoolVisualDependency> 00458 precDep1 = RCP<BoolVisualDependency>( 00459 new BoolVisualDependency( 00460 boolVisDepList.getEntryRCP("ShowPrecs"), 00461 boolVisDepList.getEntryRCP("Preconditioner"), 00462 true 00463 ) 00464 ); 00465 depSheet1->addDependency(precDep1); 00466 precDep1->evaluate(); 00467 TEST_ASSERT(precDep1->isDependentVisible()); 00468 boolVisDepList.set("ShowPrecs", false); 00469 precDep1->evaluate(); 00470 TEST_ASSERT(!precDep1->isDependentVisible()); 00471 00472 00473 00474 /* 00475 * Testing the StringVisualDepenency 00476 */ 00477 ParameterList& 00478 stringVisDepList = My_deplist->sublist( 00479 "String Visual Dependency List", 00480 false, 00481 "String Visual Dependency testing list." 00482 ); 00483 RCP<StringToIntegralParameterEntryValidator<int> > 00484 favCheeseValidator = rcp( 00485 new StringToIntegralParameterEntryValidator<int>( 00486 tuple<std::string>( "Swiss", "American", "Cheder" ), 00487 "Favorite Cheese" 00488 ) 00489 ); 00490 00491 stringVisDepList.set("Favorite Cheese", 00492 "American", "Your favorite type of cheese", favCheeseValidator); 00493 RCP<EnhancedNumberValidator<int> > 00494 swissValidator = rcp(new EnhancedNumberValidator<int>(0,10)); 00495 stringVisDepList.set("Swiss rating", 0, 00496 "How you rate swiss on a scale of 1 to 10", swissValidator); 00497 RCP<StringVisualDependency> 00498 swissDep1 = RCP<StringVisualDependency>( 00499 new StringVisualDependency( 00500 stringVisDepList.getEntryRCP("Favorite Cheese"), 00501 stringVisDepList.getEntryRCP("Swiss rating"), 00502 "Swiss", 00503 true 00504 ) 00505 ); 00506 depSheet1->addDependency(swissDep1); 00507 swissDep1->evaluate(); 00508 TEST_ASSERT(!swissDep1->isDependentVisible()); 00509 stringVisDepList.set("Favorite Cheese", "Swiss"); 00510 swissDep1->evaluate(); 00511 TEST_ASSERT(swissDep1->isDependentVisible()); 00512 00513 /* 00514 * String Visual Tester with multiple values 00515 */ 00516 ParameterList multiStringVisDepList = My_deplist->sublist( 00517 "Multi String Visual Dependency List", 00518 false 00519 ); 00520 RCP<StringToIntegralParameterEntryValidator<int> > 00521 favCheeseValidator2 = rcp( 00522 new StringToIntegralParameterEntryValidator<int>( 00523 tuple<std::string>( "Provalone", "Swiss", "American", "Cheder" ), 00524 "Favorite Cheese" 00525 ) 00526 ); 00527 00528 multiStringVisDepList.set( 00529 "Favorite Cheese", "American", 00530 "Your favorite type of cheese", favCheeseValidator2); 00531 multiStringVisDepList.set("Swiss rating", 0, 00532 "How you rate swiss on a scale of 1 to 10", swissValidator); 00533 RCP<StringVisualDependency> 00534 swissDep2 = RCP<StringVisualDependency>( 00535 new StringVisualDependency( 00536 multiStringVisDepList.getEntryRCP("Favorite Cheese"), 00537 multiStringVisDepList.getEntryRCP("Swiss rating"), 00538 tuple<std::string>("Swiss", "Cheder"), 00539 true 00540 ) 00541 ); 00542 depSheet1->addDependency(swissDep2); 00543 swissDep2->evaluate(); 00544 TEST_ASSERT(!swissDep2->isDependentVisible()); 00545 multiStringVisDepList.set("Favorite Cheese", "Cheder"); 00546 swissDep2->evaluate(); 00547 TEST_ASSERT(swissDep2->isDependentVisible()); 00548 00549 /* 00550 * Another test of the NumberVisualDependency. 00551 */ 00552 ParameterList 00553 numberVisDepList = My_deplist->sublist( 00554 "Number Visual Dependency List", 00555 false, 00556 "Number Visual Dependency testing list." 00557 ); 00558 numberVisDepList.set("Ice", 50, "Ice stuff"); 00559 numberVisDepList.set("Room Temp", 10, "Room temperature"); 00560 RCP<SubtractionFunction<int> > visFunc = rcp(new 00561 SubtractionFunction<int>(32)); 00562 RCP<NumberVisualDependency<int> > 00563 iceDep = RCP<NumberVisualDependency<int> >( 00564 new NumberVisualDependency<int>( 00565 numberVisDepList.getEntryRCP("Room Temp"), 00566 numberVisDepList.getEntryRCP("Ice"), 00567 true, 00568 visFunc 00569 ) 00570 ); 00571 depSheet1->addDependency(iceDep); 00572 iceDep->evaluate(); 00573 TEST_ASSERT(!iceDep->isDependentVisible()); 00574 numberVisDepList.set("Room Temp", 33); 00575 iceDep->evaluate(); 00576 TEST_ASSERT(iceDep->isDependentVisible()); 00577 00578 /* 00579 * Test condition visual dependency 00580 */ 00581 RCP<ParameterList> conVisDepList = sublist( 00582 My_deplist,"Condition Visual Dependency List", false); 00583 conVisDepList->set("double param", 4.0, "double parameter"); 00584 conVisDepList->set("bool param", true, "bool parameter"); 00585 conVisDepList->set("string param", "blah", "a string parameter"); 00586 RCP<NumberCondition<double> > numberCon = 00587 rcp( new NumberCondition<double>( 00588 conVisDepList->getEntryRCP("double param"))); 00589 RCP<BoolCondition> boolCon = 00590 rcp(new BoolCondition(conVisDepList->getEntryRCP("bool param"))); 00591 Condition::ConstConditionList conList = 00592 tuple<RCP<const Condition> >(numberCon, boolCon); 00593 RCP<AndCondition> andCon = rcp(new AndCondition(conList)); 00594 RCP<ConditionVisualDependency> conVisDep = 00595 rcp(new ConditionVisualDependency( 00596 andCon, conVisDepList->getEntryRCP("string param"), true)); 00597 depSheet1->addDependency(conVisDep); 00598 conVisDep->evaluate(); 00599 TEST_ASSERT(conVisDep->isDependentVisible()); 00600 conVisDepList->set("bool param", false); 00601 conVisDep->evaluate(); 00602 TEST_ASSERT(!conVisDep->isDependentVisible()); 00603 } 00604 00608 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testTwoDRowDependency){ 00609 RCP<ParameterList> My_deplist = RCP<ParameterList>(new ParameterList); 00610 RCP<DependencySheet> depSheet1 = 00611 RCP<DependencySheet>(new DependencySheet); 00612 00613 ParameterList 00614 rowNumDepList = My_deplist->sublist( 00615 "2D Row Depdency List", false, 00616 "2D Row Dependecy testing list."); 00617 rowNumDepList.set("Num rows", 10, "num rows setter"); 00618 TwoDArray<double> variableRowsArray(11,2,16.5); 00619 RCP<EnhancedNumberValidator<double> > 00620 varRowArrayVali = RCP<EnhancedNumberValidator<double> >( 00621 new EnhancedNumberValidator<double>(10,50,4) 00622 ); 00623 rowNumDepList.set( 00624 "Variable Row Array", variableRowsArray, "variable row array", 00625 RCP<TwoDArrayNumberValidator<double> >( 00626 new TwoDArrayNumberValidator<double>(varRowArrayVali))); 00627 00628 RCP<TwoDRowDependency<int, double> > 00629 arrayRowDep = rcp( 00630 new TwoDRowDependency<int, double>( 00631 rowNumDepList.getEntryRCP("Num rows"), 00632 rowNumDepList.getEntryRCP("Variable Row Array") , 00633 rcp(new AdditionFunction<int>(1)) 00634 ) 00635 ); 00636 depSheet1->addDependency(arrayRowDep); 00637 TwoDArray<double> curArray = 00638 rowNumDepList.get<TwoDArray<double> >("Variable Row Array"); 00639 TEST_EQUALITY_CONST(curArray.getNumRows(),11); 00640 rowNumDepList.set("Num rows", 12); 00641 arrayRowDep()->evaluate(); 00642 curArray = 00643 rowNumDepList.get<TwoDArray<double> >("Variable Row Array"); 00644 TEST_EQUALITY_CONST(curArray.getNumRows(),13); 00645 rowNumDepList.set("Num rows", -2); 00646 TEST_THROW(arrayRowDep()->evaluate(), 00647 Exceptions::InvalidParameterValue); 00648 } 00649 00653 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testTwoDColDependency){ 00654 RCP<ParameterList> My_deplist = RCP<ParameterList>(new ParameterList); 00655 RCP<DependencySheet> depSheet1 = 00656 RCP<DependencySheet>(new DependencySheet); 00657 00658 ParameterList 00659 colNumDepList = My_deplist->sublist( 00660 "2D Col Depdency List", false, 00661 "2D Col Dependecy testing list."); 00662 colNumDepList.set("Num cols", 2, "num cols setter"); 00663 TwoDArray<double> variableColsArray(11,3,16.5); 00664 RCP<EnhancedNumberValidator<double> > 00665 varColArrayVali = RCP<EnhancedNumberValidator<double> >( 00666 new EnhancedNumberValidator<double>(10,50,4) 00667 ); 00668 colNumDepList.set( 00669 "Variable Col Array", variableColsArray, "variable col array", 00670 RCP<TwoDArrayNumberValidator<double> >( 00671 new TwoDArrayNumberValidator<double>(varColArrayVali))); 00672 00673 RCP<TwoDColDependency<int, double> > 00674 arrayColDep = rcp( 00675 new TwoDColDependency<int, double>( 00676 colNumDepList.getEntryRCP("Num cols"), 00677 colNumDepList.getEntryRCP("Variable Col Array") , 00678 rcp(new AdditionFunction<int>(1)) 00679 ) 00680 ); 00681 depSheet1->addDependency(arrayColDep); 00682 TwoDArray<double> curArray = 00683 colNumDepList.get<TwoDArray<double> >("Variable Col Array"); 00684 TEST_EQUALITY_CONST(curArray.getNumCols(),3); 00685 colNumDepList.set("Num cols", 4); 00686 arrayColDep()->evaluate(); 00687 curArray = 00688 colNumDepList.get<TwoDArray<double> >("Variable Col Array"); 00689 TEST_EQUALITY_CONST(curArray.getNumCols(),5); 00690 colNumDepList.set("Num cols", -2); 00691 TEST_THROW(arrayColDep()->evaluate(), 00692 Exceptions::InvalidParameterValue); 00693 } 00694 00695 00699 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testArrayLengthDep){ 00700 RCP<ParameterList> My_deplist = RCP<ParameterList>(new ParameterList); 00701 RCP<DependencySheet> depSheet1 = 00702 RCP<DependencySheet>(new DependencySheet); 00703 00704 ParameterList 00705 numberArrayLengthDepList = My_deplist->sublist( 00706 "Number Array Length Dependency List", false, 00707 "Number Array Length Dependecy testing list."); 00708 numberArrayLengthDepList.set("Array Length", 10, "array length setter"); 00709 Array<double> variableLengthArray(11,23.0); 00710 RCP<EnhancedNumberValidator<double> > 00711 varLengthArrayVali = RCP<EnhancedNumberValidator<double> >( 00712 new EnhancedNumberValidator<double>(10,50,4) 00713 ); 00714 numberArrayLengthDepList.set( 00715 "Variable Length Array", variableLengthArray, "variable length array", 00716 RCP<ArrayNumberValidator<double> >( 00717 new ArrayNumberValidator<double>(varLengthArrayVali))); 00718 00719 RCP<NumberArrayLengthDependency<int, double> > 00720 arrayLengthDep( 00721 new NumberArrayLengthDependency<int, double>( 00722 numberArrayLengthDepList.getEntryRCP("Array Length"), 00723 numberArrayLengthDepList.getEntryRCP("Variable Length Array"), 00724 rcp(new AdditionFunction<int>(1)) 00725 ) 00726 ); 00727 depSheet1->addDependency(arrayLengthDep); 00728 Array<double> curArray = 00729 numberArrayLengthDepList.get<Array<double> >("Variable Length Array"); 00730 TEST_ASSERT(curArray.length() ==11); 00731 numberArrayLengthDepList.set("Array Length", 12); 00732 arrayLengthDep()->evaluate(); 00733 curArray = 00734 numberArrayLengthDepList.get<Array<double> >("Variable Length Array"); 00735 out << curArray.length() << std::endl; 00736 TEST_ASSERT(curArray.length() ==13); 00737 numberArrayLengthDepList.set("Array Length", -2); 00738 TEST_THROW(arrayLengthDep()->evaluate(), 00739 Exceptions::InvalidParameterValue); 00740 } 00741 00745 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testDepExceptions){ 00746 RCP<ParameterList> list1 = RCP<ParameterList>(new ParameterList()); 00747 RCP<ParameterList> list2 = RCP<ParameterList>(new ParameterList()); 00748 00749 list1->set("int parameter", 4, "int parameter"); 00750 list1->set("double parameter", 6.0, "double parameter"); 00751 list1->set("string parameter", "hahahaha", "string parameter"); 00752 Array<double> doubleArray(10,23.0); 00753 list1->set("array parameter", doubleArray, "array parameter"); 00754 list1->set("bool parameter", true, "bool parameter"); 00755 00756 RCP<AdditionFunction<int> > intFuncTester = rcp(new 00757 AdditionFunction<int>(10)); 00758 TEST_THROW(RCP<NumberVisualDependency<int> > numValiDep = 00759 rcp( 00760 new NumberVisualDependency<int>( 00761 list1->getEntryRCP("bool parameter"), 00762 list1->getEntryRCP("double parameter"), 00763 true, 00764 intFuncTester)), 00765 InvalidDependencyException); 00766 00767 /* 00768 * Testing StringVisualDepenendcy exceptions. 00769 */ 00770 RCP<StringVisualDependency> stringVisDep; 00771 TEST_THROW(stringVisDep = RCP<StringVisualDependency>( 00772 new StringVisualDependency( 00773 list1->getEntryRCP("double parameter"), 00774 list1->getEntryRCP("int parameter"), 00775 "cheese", true)), 00776 InvalidDependencyException); 00777 00778 /* 00779 * Testing BoolVisualDependency exceptions. 00780 */ 00781 TEST_THROW(RCP<BoolVisualDependency> boolVisDep = 00782 RCP<BoolVisualDependency>(new BoolVisualDependency( 00783 list1->getEntryRCP("int parameter"), 00784 list1->getEntryRCP("double parameter"), false)), 00785 InvalidDependencyException); 00786 00789 RCP<NumberArrayLengthDependency<int, double> > numArrayLengthDep; 00790 TEST_THROW(numArrayLengthDep = 00791 rcp(new NumberArrayLengthDependency<int, double>( 00792 list1->getEntryRCP("double parameter"), 00793 list1->getEntryRCP("array parameter"))), 00794 InvalidDependencyException); 00795 00796 TEST_THROW(numArrayLengthDep = 00797 rcp(new NumberArrayLengthDependency<int, double>( 00798 list1->getEntryRCP("int parameter"), 00799 list1->getEntryRCP("double parameter"))), 00800 InvalidDependencyException); 00801 00802 /* 00803 * Testing StringValidatorDependency exceptions. 00804 */ 00805 RCP<StringToIntegralParameterEntryValidator<int> > 00806 cheeseValidator = rcp( 00807 new StringToIntegralParameterEntryValidator<int>( 00808 tuple<std::string>( "Swiss", "American", "Super Awesome Cheese"), 00809 "Food Selector" 00810 ) 00811 ); 00812 00813 RCP<StringToIntegralParameterEntryValidator<int> > 00814 sodaValidator = rcp( 00815 new StringToIntegralParameterEntryValidator<int>( 00816 tuple<std::string>( "Pepsi", "Coke", "Kurtis Cola", "Bad Cola" ), 00817 "Food Selector" 00818 ) 00819 ); 00820 00821 RCP<StringToIntegralParameterEntryValidator<int> > 00822 chipsValidator = rcp( 00823 new StringToIntegralParameterEntryValidator<int>( 00824 tuple<std::string>( "Lays", "Doritos", "Kurtis Super Awesome Brand"), 00825 "Food Selector" 00826 ) 00827 ); 00828 00829 00830 list1->set( 00831 "string 2 parameter", "Swiss", 00832 "second string parameter", cheeseValidator); 00833 StringValidatorDependency::ValueToValidatorMap testValidatorMap1; 00834 testValidatorMap1["Cheese"] = cheeseValidator; 00835 testValidatorMap1["Soda"] = sodaValidator; 00836 testValidatorMap1["Chips"] = chipsValidator; 00837 TEST_THROW(RCP<StringValidatorDependency> stringValiDep = 00838 RCP<StringValidatorDependency>( 00839 new StringValidatorDependency( 00840 list1->getEntryRCP("int parameter"), 00841 list1->getEntryRCP("string 2 parameter"), 00842 testValidatorMap1)), 00843 InvalidDependencyException); 00844 RCP<EnhancedNumberValidator<int> > intVali = 00845 rcp(new EnhancedNumberValidator<int>(0,20)); 00846 testValidatorMap1["Candy"] = intVali; 00847 TEST_THROW(RCP<StringValidatorDependency> stringValiDep = 00848 RCP<StringValidatorDependency>( 00849 new StringValidatorDependency( 00850 list1->getEntryRCP("string parameter"), 00851 list1->getEntryRCP("string 2 parameter"), 00852 testValidatorMap1)), 00853 InvalidDependencyException); 00854 00855 StringValidatorDependency::ValueToValidatorMap emptyMap; 00856 TEST_THROW(RCP<StringValidatorDependency> stringValiDep = 00857 RCP<StringValidatorDependency>( 00858 new StringValidatorDependency( 00859 list1->getEntryRCP("string parameter"), 00860 list1->getEntryRCP("string 2 parameter"), 00861 emptyMap)), 00862 InvalidDependencyException); 00863 00864 /* 00865 * Testing BoolValidatorDependency exceptions. 00866 */ 00867 RCP<EnhancedNumberValidator<double> > doubleVali1 = 00868 rcp(new EnhancedNumberValidator<double>(0.0,20.0)); 00869 RCP<EnhancedNumberValidator<double> > doubleVali2 = 00870 rcp(new EnhancedNumberValidator<double>(5.0,20.0)); 00871 list1->set("double parameter", 6.0, "double parameter", doubleVali1); 00872 00873 TEST_THROW(RCP<BoolValidatorDependency> boolValiDep = 00874 RCP<BoolValidatorDependency>( 00875 new BoolValidatorDependency( 00876 list1->getEntryRCP("int parameter"), 00877 list1->getEntryRCP("double parameter"), 00878 doubleVali1, 00879 doubleVali2)), 00880 InvalidDependencyException); 00881 00882 TEST_THROW(RCP<BoolValidatorDependency> boolValiDep = 00883 RCP<BoolValidatorDependency>( 00884 new BoolValidatorDependency( 00885 list1->getEntryRCP("bool parameter"), 00886 list1->getEntryRCP("double parameter"), 00887 intVali, 00888 doubleVali2)), 00889 InvalidDependencyException); 00890 00891 TEST_THROW(RCP<BoolValidatorDependency> boolValiDep = 00892 RCP<BoolValidatorDependency>( 00893 new BoolValidatorDependency( 00894 list1->getEntryRCP("bool parameter"), 00895 list1->getEntryRCP("double parameter"), 00896 doubleVali1, 00897 intVali)), 00898 InvalidDependencyException); 00899 00900 /* 00901 * Testing RangeValidatorDependency exceptions. 00902 */ 00903 list1->set("Cheese to Fondue", "Swiss", "the cheese to fondue"); 00904 RCP<StringToIntegralParameterEntryValidator<int> > 00905 lowTempCheeseValidator = rcp( 00906 new StringToIntegralParameterEntryValidator<int>( 00907 tuple<std::string>( "PepperJack", "Swiss", "American" ), 00908 "Cheese to Fondue" 00909 ) 00910 ); 00911 RCP<StringToIntegralParameterEntryValidator<int> > 00912 highTempCheeseValidator = rcp( 00913 new StringToIntegralParameterEntryValidator<int>( 00914 tuple<std::string>("Munster", "Provalone", 00915 "Kurtis Super Awesome Cheese"), 00916 "Cheese to Fondue" 00917 ) 00918 ); 00919 00920 list1->set( 00921 "Cheese to Fondue", "Swiss", "the cheese to fondue", 00922 lowTempCheeseValidator); 00923 00924 RangeValidatorDependency<double>::RangeToValidatorMap tempranges; 00925 tempranges[std::pair<double,double>(100,200)] = lowTempCheeseValidator; 00926 tempranges[std::pair<double,double>(200,300)] = highTempCheeseValidator; 00927 TEST_THROW( 00928 RCP<RangeValidatorDependency<double> > 00929 cheeseTempDep = RCP<RangeValidatorDependency<double> >( 00930 new RangeValidatorDependency<double>( 00931 list1->getEntryRCP("string parameter"), 00932 list1->getEntryRCP("Cheese to Fondue"), 00933 tempranges 00934 ) 00935 ), 00936 InvalidDependencyException 00937 ); 00938 00939 tempranges[std::pair<double,double>(400,800)] = intVali; 00940 TEST_THROW( 00941 RCP<RangeValidatorDependency<double> > 00942 cheeseTempDep = RCP<RangeValidatorDependency<double> >( 00943 new RangeValidatorDependency<double>( 00944 list1->getEntryRCP("int parameter"), 00945 list1->getEntryRCP("Cheese to Fondue"), 00946 tempranges 00947 ) 00948 ), 00949 InvalidDependencyException 00950 ); 00951 00952 RangeValidatorDependency<double>::RangeToValidatorMap emptyMap2; 00953 TEST_THROW( 00954 RCP<RangeValidatorDependency<double> > 00955 emptyMapDep = RCP<RangeValidatorDependency<double> >( 00956 new RangeValidatorDependency<double>( 00957 list1->getEntryRCP("double parameter"), 00958 list1->getEntryRCP("Cheese to Fondue"), 00959 emptyMap2 00960 ) 00961 ), 00962 InvalidDependencyException 00963 ); 00964 00965 RangeValidatorDependency<int>::RangeToValidatorMap badRanges; 00966 tempranges[std::pair<int,int>(200,100)] = lowTempCheeseValidator; 00967 TEST_THROW( 00968 RCP<RangeValidatorDependency<int> > 00969 cheeseTempDep = RCP<RangeValidatorDependency<int> >( 00970 new RangeValidatorDependency<int>( 00971 list1->getEntryRCP("string parameter"), 00972 list1->getEntryRCP("Cheese to Fondue"), 00973 badRanges 00974 ) 00975 ), 00976 InvalidDependencyException 00977 ); 00978 } 00979 00983 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, DepSheetTest){ 00984 RCP<DependencySheet> depSheet1 = rcp(new DependencySheet); 00985 RCP<BoolVisualDependency> boolDep1 = 00986 DummyObjectGetter<BoolVisualDependency>::getDummyObject(); 00987 TEST_ASSERT(depSheet1->empty()); 00988 depSheet1->addDependency(boolDep1); 00989 TEST_ASSERT(!depSheet1->empty()); 00990 00991 00992 RCP<DependencySheet> depSheet2 = rcp(new DependencySheet); 00993 RCP<StringVisualDependency> stringDep1 = 00994 DummyObjectGetter<StringVisualDependency>::getDummyObject(); 00995 depSheet1->addDependency(stringDep1); 00996 RCP<StringValidatorDependency> stringValiDep1 = 00997 DummyObjectGetter<StringValidatorDependency>::getDummyObject(); 00998 depSheet1->addDependency(stringValiDep1); 00999 01000 depSheet1->addDependencies(depSheet2); 01001 TEST_EQUALITY_CONST(depSheet1->size(), 3); 01002 bool found1 = false; 01003 bool found2 = false; 01004 bool found3 = false; 01005 for( 01006 DependencySheet::DepSet::iterator it = depSheet1->depBegin(); 01007 it != depSheet1->depEnd(); 01008 ++it 01009 ) 01010 { 01011 if(*it == boolDep1){ 01012 found1 = true; 01013 } 01014 else if(*it == stringDep1){ 01015 found2 = true; 01016 } 01017 else if(*it == stringValiDep1){ 01018 found3 = true; 01019 } 01020 } 01021 TEST_ASSERT(found1); 01022 TEST_ASSERT(found2); 01023 TEST_ASSERT(found3); 01024 } 01025 01026 01027 } //namespace Teuchos 01028
1.7.6.1