Optika GUI Toolik Version of the Day
test/dependencies/main.cpp
Go to the documentation of this file.
00001 // @HEADER // ***********************************************************************
00002 // 
00003 //         Optika: A Tool For Developing Parameter Obtaining GUIs
00004 //                Copyright (2009) Sandia Corporation
00005 // 
00006 // Under terms of Contract DE-AC04-94AL85000, with Sandia Corporation, the 
00007 // U.S. Government retains certain rights in this software.
00008 // 
00009 // This library is free software; you can redistribute it and/or modify
00010 // it under the terms of the GNU Lesser General Public License as
00011 // published by the Free Software Foundation; either version 2.1 of the
00012 // License, or (at your option) any later version.
00013 //  
00014 // This library is distributed in the hope that it will be useful, but
00015 // WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 // Lesser General Public License for more details.
00018 //  
00019 // You should have received a copy of the GNU Lesser General Public
00020 // License along with this library; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00022 // USA
00023 // Questions? Contact Kurtis Nusbaum (klnusbaum@gmail.com) 
00024 // 
00025 // ***********************************************************************
00026 // @HEADER
00027 #include "Teuchos_LocalTestingHelpers.hpp"
00028 #include "Teuchos_VerboseObject.hpp"
00029 #include "Teuchos_ParameterList.hpp"
00030 #include "Optika_StandardDependencies.hpp"
00031 #include "Optika_DependencySheet.hpp"
00032 #include "Optika_StandardConditions.hpp"
00033 
00034 int intFuncTester(int argument){
00035   return argument+10;
00036 }
00037 
00038 int intVisualTester(int argument){
00039   if(argument <= 32){
00040     return 1;
00041   }
00042   else{
00043     return 0;
00044   }
00045 }
00046 
00047 double fondueTempTester(double argument){
00048   return argument-100.0;
00049 }
00050 
00051 
00055 int testValiDeps(Teuchos::FancyOStream &out){
00056   bool success = true;
00057   Teuchos::RCP<Teuchos::ParameterList> My_deplist = Teuchos::RCP<Teuchos::ParameterList>(new Teuchos::ParameterList);
00058   Teuchos::RCP<Optika::DependencySheet> depSheet1 = Teuchos::RCP<Optika::DependencySheet>(new Optika::DependencySheet(My_deplist));
00059 
00060   /*
00061    * Testing StringValidatorDependency
00062    */
00063   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00064     stringFoodTypeValidator = Teuchos::rcp(
00065     new Teuchos::StringToIntegralParameterEntryValidator<int>(
00066     Teuchos::tuple<std::string>( "Cheese", "Soda", "Chips" )
00067     ,"Food Type"
00068     )
00069   );
00070 
00071   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00072     cheeseValidator = Teuchos::rcp(
00073     new Teuchos::StringToIntegralParameterEntryValidator<int>(
00074         Teuchos::tuple<std::string>( "Swiss", "American", "Super Awesome Cheese" )
00075       ,"Food Selector"
00076       )
00077   );
00078 
00079   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00080   sodaValidator = Teuchos::rcp(
00081     new Teuchos::StringToIntegralParameterEntryValidator<int>(
00082       Teuchos::tuple<std::string>( "Pepsi", "Coke", "Kurtis Cola", "Bad Cola" )
00083       ,"Food Selector"
00084       )
00085     );
00086 
00087   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00088   chipsValidator = Teuchos::rcp(
00089     new Teuchos::StringToIntegralParameterEntryValidator<int>(
00090       Teuchos::tuple<std::string>( "Lays", "Doritos", "Kurtis Super Awesome Brand" )
00091       ,"Food Selector"
00092     )
00093   );
00094 
00095   Optika::StringValidatorDependency::ValueToValidatorMap testValidatorMap1;
00096   testValidatorMap1["Cheese"] = cheeseValidator;
00097   testValidatorMap1["Soda"] = sodaValidator;
00098   testValidatorMap1["Chips"] = chipsValidator;
00099 
00100   Teuchos::ParameterList& stringValiDepList = My_deplist->sublist("String Validator Dependency", false, "String Validator Dependency testing list.\nWorking June 27th 2009");
00101   stringValiDepList.set("Food Selector", "Swiss", "select the food you want", cheeseValidator);
00102   stringValiDepList.set("Food Type", "Cheese", "String Validator Dependency Tester", stringFoodTypeValidator);
00103 
00104   Teuchos::RCP<Optika::StringValidatorDependency> 
00105   stringValiDep = Teuchos::RCP<Optika::StringValidatorDependency>(
00106     new Optika::StringValidatorDependency(
00107       "Food Type", 
00108       Teuchos::sublist(My_deplist,"String Validator Dependency"),
00109       "Food Selector", 
00110       Teuchos::sublist(My_deplist,"String Validator Dependency"),
00111       testValidatorMap1, 
00112       cheeseValidator
00113     )
00114   );
00115 
00116   depSheet1->addDependency(stringValiDep);
00117   
00118   TEST_NOTHROW(stringValiDepList.validateParameters(stringValiDepList));
00119   TEST_ASSERT(depSheet1->hasDependents(stringValiDepList.getEntryPtr("Food Type")));
00120   Optika::DependencySheet::DepSet stringValiDepSet = depSheet1->getDependenciesForParameter(stringValiDepList.getEntryPtr("Food Type"));
00121   TEST_ASSERT(stringValiDepSet.size() == 1);
00122   stringValiDepList.set("Food Type","Soda");
00123   stringValiDep->evaluate();
00124   TEST_ASSERT(stringValiDepList.getEntry("Food Selector").validator().get()==sodaValidator.get());
00125   TEST_THROW(stringValiDepList.validateParameters(stringValiDepList), Teuchos::Exceptions::InvalidParameterValue);
00126   stringValiDepList.set("Food Selector", "Pepsi");
00127   TEST_NOTHROW(stringValiDepList.validateParameters(stringValiDepList));
00128  
00129 
00130   /*
00131    * Tesing some different aspects of the StringValidatorDependency
00132    */
00133   Teuchos::ParameterList& 
00134   stringValiDepList2 = My_deplist->sublist(
00135     "String Validator Dependency (other validators)",
00136     false,
00137     "String Validator Dependency testing list for EnhancedNumber Validators.\nWorking June 27th 2009"
00138   );
00139 
00140   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00141   stringRangeValidator = Teuchos::rcp(
00142     new Teuchos::StringToIntegralParameterEntryValidator<int>(
00143     Teuchos::tuple<std::string>( "1-10", "10-33", "50-60" ),
00144     "Range selector"
00145     )
00146   );
00147 
00148   Teuchos::RCP<Optika::EnhancedNumberValidator<int> > range110Vali = 
00149   Teuchos::rcp(new Optika::EnhancedNumberValidator<int>(1,10));
00150   Teuchos::RCP<Optika::EnhancedNumberValidator<int> > range1033Vali = 
00151   Teuchos::rcp(new Optika::EnhancedNumberValidator<int>(10,33));
00152   Teuchos::RCP<Optika::EnhancedNumberValidator<int> > range5060Vali = 
00153   Teuchos::rcp(new Optika::EnhancedNumberValidator<int>(50,60));
00154 
00155   stringValiDepList2.set("Range selector", "1-10", "selects the range to validate", stringRangeValidator);
00156 
00157   Optika::StringValidatorDependency::ValueToValidatorMap rangeValidatorMap1;
00158   rangeValidatorMap1["1-10"] = range110Vali;
00159   rangeValidatorMap1["10-33"] = range1033Vali;
00160   rangeValidatorMap1["50-60"] = range5060Vali;
00161   stringValiDepList2.set("RangeValue", 3, "the value of the range", range110Vali);
00162 
00163   Teuchos::RCP<Optika::StringValidatorDependency> 
00164   stringValiDep2 = Teuchos::RCP<Optika::StringValidatorDependency>(
00165     new Optika::StringValidatorDependency(
00166       "Range selector", 
00167       Teuchos::sublist(My_deplist,"String Validator Dependency (other validators)"),
00168       "RangeValue", 
00169       Teuchos::sublist(My_deplist,"String Validator Dependency (other validators)"),
00170       rangeValidatorMap1, 
00171       range110Vali
00172     )
00173   );
00174 
00175   depSheet1->addDependency(stringValiDep2);
00176 
00177   TEST_NOTHROW(stringValiDepList2.validateParameters(stringValiDepList2));
00178   TEST_ASSERT(depSheet1->hasDependents(stringValiDepList2.getEntryPtr("Range selector")));
00179   Optika::DependencySheet::DepSet stringValiDepSet2 = depSheet1->getDependenciesForParameter(stringValiDepList2.getEntryPtr("Range selector"));
00180   TEST_ASSERT(stringValiDepSet2.size() == 1);
00181   stringValiDepList2.set("Range selector","50-60");
00182   stringValiDep2->evaluate();
00183   TEST_ASSERT(stringValiDepList2.getEntry("RangeValue").validator().get() == range5060Vali.get());
00184   TEST_THROW(stringValiDepList2.validateParameters(stringValiDepList2), Teuchos::Exceptions::InvalidParameterValue);
00185   stringValiDepList2.set("RangeValue", 55);
00186   TEST_NOTHROW(stringValiDepList2.validateParameters(stringValiDepList2));
00187 
00188   /*
00189    * Testing the BoolValidatorDependency.
00190    */
00191   Teuchos::ParameterList&
00192   boolValidatorDepList = My_deplist->sublist(
00193     "Bool Validator Dependency List", 
00194     false,
00195     "Bool Validator Dependency testing list.\nWorking June 27th 2009"
00196   );
00197 
00198   boolValidatorDepList.set("Use Validator?", true, "truns the validator on and off");
00199   Teuchos::RCP<Optika::EnhancedNumberValidator<int> > basicVali = Teuchos::rcp(new Optika::EnhancedNumberValidator<int>(1,10));
00200   Teuchos::RCP<Optika::EnhancedNumberValidator<int> > basicVali2 = Teuchos::rcp(new Optika::EnhancedNumberValidator<int>());
00201   boolValidatorDepList.set("do I have a validator?", 4, "does it have a validator?", basicVali);
00202 
00203   Teuchos::RCP<Optika::BoolValidatorDependency> 
00204   boolValiDep = Teuchos::RCP<Optika::BoolValidatorDependency>(
00205     new Optika::BoolValidatorDependency(
00206       "Use Validator?", 
00207       Teuchos::sublist(My_deplist,"Bool Validator Dependency List"),
00208       "do I have a validator?", 
00209       Teuchos::sublist(My_deplist,"Bool Validator Dependency List"),
00210       basicVali, 
00211       basicVali2
00212     )
00213   );
00214 
00215   depSheet1->addDependency(boolValiDep);
00216 
00217   TEST_ASSERT(depSheet1->hasDependents(boolValidatorDepList.getEntryPtr("Use Validator?")));
00218   TEST_ASSERT(boolValidatorDepList.getEntry("do I have a validator?").validator().get() == basicVali.get());
00219   TEST_NOTHROW(boolValidatorDepList.validateParameters(boolValidatorDepList));
00220   Optika::DependencySheet::DepSet boolValiDepSet = depSheet1->getDependenciesForParameter(boolValidatorDepList.getEntryPtr("Use Validator?"));
00221   TEST_ASSERT(boolValiDepSet.size() == 1);
00222   boolValidatorDepList.set("Use Validator?",false);
00223   boolValiDep->evaluate();
00224   TEST_ASSERT(boolValidatorDepList.getEntry("do I have a validator?").validator().get() == basicVali2.get());
00225 
00226 
00227   /*
00228    * Testing the RangeValidatorDependency
00229    */
00230   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00231   lowTempCheeseValidator = Teuchos::rcp(
00232     new Teuchos::StringToIntegralParameterEntryValidator<int>(
00233       Teuchos::tuple<std::string>( "PepperJack", "Swiss", "American" ),
00234       "Cheese to Fondue"
00235     )
00236   );
00237 
00238   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00239   highTempCheeseValidator = Teuchos::rcp(
00240     new Teuchos::StringToIntegralParameterEntryValidator<int>(
00241       Teuchos::tuple<std::string>( "Munster", "Provalone", "Kurtis Super Awesome Cheese"),
00242       "Cheese to Fondue"
00243     )
00244   );
00245 
00246   Teuchos::ParameterList& 
00247   rangeValidatorDepList = My_deplist->sublist(
00248     "Range Validator Dependency List",
00249     false,
00250     "Range Validator Dependency testing list.\nWorking June 27th 2009"
00251   );
00252   rangeValidatorDepList.set("Temperature",101.0, "The temperature of the fondue");
00253   rangeValidatorDepList.set("Cheese to Fondue", "Swiss", "The cheese we'll be using in our fondue pot.", lowTempCheeseValidator);
00254   Optika::RangeValidatorDependency<double>::RangeToValidatorMap tempranges;
00255   tempranges[std::pair<double,double>(100,200)] = lowTempCheeseValidator;
00256   tempranges[std::pair<double,double>(200,300)] = highTempCheeseValidator;
00257   Teuchos::RCP<Optika::RangeValidatorDependency<double> > 
00258   cheeseTempDep = Teuchos::RCP<Optika::RangeValidatorDependency<double> >(
00259     new Optika::RangeValidatorDependency<double>(
00260       "Temperature", 
00261       Teuchos::sublist(My_deplist,"Range Validator Dependency List"),
00262       "Cheese to Fondue", 
00263       Teuchos::sublist(My_deplist,"Range Validator Dependency List"),
00264       tempranges, 
00265       lowTempCheeseValidator
00266     )
00267   );
00268   depSheet1->addDependency(cheeseTempDep);
00269 
00270   TEST_ASSERT(depSheet1->hasDependents(rangeValidatorDepList.getEntryPtr("Temperature")));
00271   Optika::DependencySheet::DepSet rangeValiDepSet = depSheet1->getDependenciesForParameter(rangeValidatorDepList.getEntryPtr("Temperature"));
00272   TEST_ASSERT(rangeValiDepSet.size() == 1);
00273   rangeValidatorDepList.set("Temperature",250.0);
00274   cheeseTempDep->evaluate();
00275   TEST_ASSERT(rangeValidatorDepList.getEntry("Cheese to Fondue").validator().get() == highTempCheeseValidator.get());
00276   TEST_THROW(rangeValidatorDepList.validateParameters(rangeValidatorDepList), Teuchos::Exceptions::InvalidParameterValue);
00277   rangeValidatorDepList.set("Cheese to Fondue", "Provalone");
00278   TEST_NOTHROW(rangeValidatorDepList.validateParameters(rangeValidatorDepList));
00279 
00280   return (success ? 0:1);
00281 }
00282   
00286 int testVisualDeps(Teuchos::FancyOStream &out){
00287   bool success = true;
00288   Teuchos::RCP<Teuchos::ParameterList> My_deplist = Teuchos::RCP<Teuchos::ParameterList>(new Teuchos::ParameterList);
00289   Teuchos::RCP<Optika::DependencySheet> depSheet1 = Teuchos::RCP<Optika::DependencySheet>(new Optika::DependencySheet(My_deplist));
00290 
00291   /*
00292    * Testing the NumberVisualDependency
00293    */
00294   Teuchos::ParameterList&
00295   doubleVisualDepList = My_deplist->sublist(
00296     "NumberVisual Dependency List (double)", 
00297     false, 
00298     "Number visual Dependency testing list.\nWorking June 27th 2009"
00299   );
00300     
00301   doubleVisualDepList.set("Temperature",101.0, "The temperature of the fondue");
00302   doubleVisualDepList.set("Cheese to Fondue", "Swiss", "The cheese to fondue");
00303   double (*fondueFunc)(double);
00304   fondueFunc = fondueTempTester;
00305 
00306   Teuchos::RCP<Optika::NumberVisualDependency<double> > fondueDep = 
00307   Teuchos::RCP<Optika::NumberVisualDependency<double> >(
00308     new Optika::NumberVisualDependency<double>(
00309       "Temperature", 
00310       Teuchos::sublist(My_deplist,"NumberVisual Dependency List (double)"),
00311       "Cheese to Fondue", 
00312       Teuchos::sublist(My_deplist,"NumberVisual Dependency List (double)"),
00313       fondueFunc
00314     )
00315   );
00316   depSheet1->addDependency(fondueDep);
00317   fondueDep->evaluate();
00318   TEST_ASSERT(fondueDep->isDependentVisible());
00319   doubleVisualDepList.set("Temperature",99.0);
00320   fondueDep->evaluate();
00321   TEST_ASSERT(!fondueDep->isDependentVisible());
00322 
00323   /*
00324    * Testing the BoolVisualDependency
00325    */
00326   Teuchos::ParameterList&
00327   boolVisDepList = My_deplist->sublist(
00328     "Bool Visual Dependency List", 
00329     false,
00330     "Bool Visual Dependency testing list.\nWorking June 29 2009"
00331   );
00332   boolVisDepList.set("ShowPrecs", true, "Whether or not to should the Preciondtioner list");
00333   Teuchos::ParameterList&
00334   Prec_List0 = boolVisDepList.sublist("Preconditioner",false,"Sublist that defines the preconditioner.");
00335   Prec_List0.set("Type", "ILU", "The tpye of preconditioner to use");
00336   Teuchos::RCP<Optika::EnhancedNumberValidator<double> > droptolValidator = Teuchos::rcp(new Optika::EnhancedNumberValidator<double>(0,10,1e-3));
00337   Prec_List0.set("Drop Tolerance", 1e-3,"The tolerance below which entries from the\n""factorization are left out of the factors.", droptolValidator);
00338   Teuchos::RCP<Optika::BoolVisualDependency> 
00339   precDep1 = Teuchos::RCP<Optika::BoolVisualDependency>(
00340     new Optika::BoolVisualDependency(
00341       "ShowPrecs", 
00342       Teuchos::sublist(My_deplist,"Bool Visual Dependency List"),
00343       "Preconditioner", 
00344       Teuchos::sublist(My_deplist,"Bool Visual Dependency List"),
00345       true
00346     )
00347   );
00348   depSheet1->addDependency(precDep1);
00349   precDep1->evaluate();
00350   TEST_ASSERT(precDep1->isDependentVisible());
00351   boolVisDepList.set("ShowPrecs", false);
00352   precDep1->evaluate();
00353   TEST_ASSERT(!precDep1->isDependentVisible());
00354 
00355 
00356 
00357   /*
00358    * Testing the StringVisualDepenency
00359    */
00360   Teuchos::ParameterList&
00361     stringVisDepList = My_deplist->sublist(
00362     "String Visual Dependency List",
00363     false,
00364     "String Visual Dependency testing list.\nWorking June 29 2009"
00365   );
00366   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00367   favCheeseValidator = Teuchos::rcp(
00368     new Teuchos::StringToIntegralParameterEntryValidator<int>(
00369       Teuchos::tuple<std::string>( "Swiss", "American", "Cheder" ),
00370       "Favorite Cheese"
00371     )
00372   );
00373    
00374   stringVisDepList.set("Favorite Cheese", "American", "Your favorite type of cheese", favCheeseValidator);
00375   Teuchos::RCP<Optika::EnhancedNumberValidator<int> > 
00376   swissValidator = Teuchos::rcp(new Optika::EnhancedNumberValidator<int>(0,10));
00377   stringVisDepList.set("Swiss rating", 0, "How you rate swiss on a scale of 1 to 10", swissValidator);
00378   Teuchos::RCP<Optika::StringVisualDependency> 
00379   swissDep1 = Teuchos::RCP<Optika::StringVisualDependency>(
00380     new Optika::StringVisualDependency(
00381       "Favorite Cheese", 
00382       Teuchos::sublist(My_deplist,"String Visual Dependency List"),
00383       "Swiss rating", 
00384       Teuchos::sublist(My_deplist,"String Visual Dependency List"),
00385       "Swiss", 
00386       true
00387     )
00388   );
00389   depSheet1->addDependency(swissDep1);
00390   swissDep1->evaluate();
00391   TEST_ASSERT(!swissDep1->isDependentVisible());
00392   stringVisDepList.set("Favorite Cheese", "Swiss");
00393   swissDep1->evaluate();
00394   TEST_ASSERT(swissDep1->isDependentVisible());
00395 
00396   /*
00397    * String Visual Tester with multiple values
00398    */
00399   Teuchos::ParameterList&
00400     multiStringVisDepList = My_deplist->sublist(
00401     "Multi String Visual Dependency List",
00402     false
00403   );
00404   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00405   favCheeseValidator2 = Teuchos::rcp(
00406     new Teuchos::StringToIntegralParameterEntryValidator<int>(
00407       Teuchos::tuple<std::string>( "Provalone", "Swiss", "American", "Cheder" ),
00408       "Favorite Cheese"
00409     )
00410   );
00411    
00412   multiStringVisDepList.set("Favorite Cheese", "American", "Your favorite type of cheese", favCheeseValidator2);
00413   multiStringVisDepList.set("Swiss rating", 0, "How you rate swiss on a scale of 1 to 10", swissValidator);
00414   Teuchos::RCP<Optika::StringVisualDependency> 
00415   swissDep2 = Teuchos::RCP<Optika::StringVisualDependency>(
00416     new Optika::StringVisualDependency(
00417       "Favorite Cheese", 
00418       Teuchos::sublist(My_deplist,"Multi String Visual Dependency List"),
00419       "Swiss rating", 
00420       Teuchos::sublist(My_deplist,"Multi String Visual Dependency List"),
00421       Teuchos::tuple<std::string>("Swiss", "Cheder"), 
00422       true
00423     )
00424   );
00425   depSheet1->addDependency(swissDep2);
00426   swissDep2->evaluate();
00427   TEST_ASSERT(!swissDep2->isDependentVisible());
00428   multiStringVisDepList.set("Favorite Cheese", "Cheder");
00429   swissDep2->evaluate();
00430   TEST_ASSERT(swissDep2->isDependentVisible());
00431 
00432   /*
00433    * Another test of the NumberVisualDependency.
00434    */
00435   int (*visfunc)(int);
00436   visfunc = intVisualTester;
00437   Teuchos::ParameterList&
00438     numberVisDepList = My_deplist->sublist(
00439     "Number Visual Dependency List", 
00440     false, 
00441     "Number Visual Dependency testing list.\nWorking June 27th 2009"
00442   );
00443   numberVisDepList.set("Ice", 50, "Ice stuff");
00444   numberVisDepList.set("Room Temp", 10, "Room temperature");
00445   Teuchos::RCP<Optika::NumberVisualDependency<int> > 
00446   iceDep = Teuchos::RCP<Optika::NumberVisualDependency<int> >(
00447     new Optika::NumberVisualDependency<int>(
00448       "Room Temp", 
00449       Teuchos::sublist(My_deplist,"Number Visual Dependency List"),
00450       "Ice", 
00451       Teuchos::sublist(My_deplist,"Number Visual Dependency List"),
00452       visfunc
00453     )
00454   );
00455   depSheet1->addDependency(iceDep);
00456   iceDep->evaluate();
00457   TEST_ASSERT(iceDep->isDependentVisible());
00458   numberVisDepList.set("Room Temp", 33);
00459   iceDep->evaluate();
00460   TEST_ASSERT(!iceDep->isDependentVisible());
00461 
00462   /*
00463    * Test condition visual dependency
00464    */
00465   Teuchos::RCP<Teuchos::ParameterList> conVisDepList = Teuchos::sublist(My_deplist,"Condition Visual Dependency List", false);
00466   conVisDepList->set("double param", 4.0, "double parameter");
00467   conVisDepList->set("bool param", true, "bool parameter");
00468   conVisDepList->set("string param", "blah", "a string parameter");
00469   Teuchos::RCP<Optika::NumberCondition<double> > numberCon = Teuchos::rcp( new Optika::NumberCondition<double>("double param", conVisDepList, true));
00470   Teuchos::RCP<Optika::BoolCondition> boolCon = Teuchos::rcp(new Optika::BoolCondition("bool param", conVisDepList));
00471   Optika::Condition::ConditionList conList = Teuchos::tuple<Teuchos::RCP<Optika::Condition> >(numberCon, boolCon);
00472   Teuchos::RCP<Optika::AndCondition> andCon = Teuchos::rcp(new Optika::AndCondition(conList));
00473   Teuchos::RCP<Optika::ConditionVisualDependency> conVisDep = Teuchos::rcp(new Optika::ConditionVisualDependency(andCon, "string param", conVisDepList, true));
00474   depSheet1->addDependency(conVisDep);
00475   conVisDep->evaluate();
00476   TEST_ASSERT(conVisDep->isDependentVisible());
00477   conVisDepList->set("bool param", false);
00478   conVisDep->evaluate();
00479   TEST_ASSERT(!conVisDep->isDependentVisible());
00480 
00481 
00482 
00483   return (success ? 0:1);
00484 }
00485 
00486 
00490 int testArrayLengthDep(Teuchos::FancyOStream &out){
00491   bool success = true;
00492   Teuchos::RCP<Teuchos::ParameterList> My_deplist = Teuchos::RCP<Teuchos::ParameterList>(new Teuchos::ParameterList);
00493   Teuchos::RCP<Optika::DependencySheet> depSheet1 = Teuchos::RCP<Optika::DependencySheet>(new Optika::DependencySheet(My_deplist));
00494 
00495   Teuchos::ParameterList&
00496   numberArrayLengthDepList = My_deplist->sublist("Number Array Length Dependency List", false, "Number Array Length Dependecy testing list.\nWorking June 27th 2009");
00497   numberArrayLengthDepList.set("Array Length", 10, "array length setter");
00498   Teuchos::Array<double> variableLengthArray(10,23.0);
00499   Teuchos::RCP<Optika::EnhancedNumberValidator<double> > 
00500   varLengthArrayVali = Teuchos::RCP<Optika::EnhancedNumberValidator<double> >(
00501       new Optika::EnhancedNumberValidator<double>(10,50,4) 
00502   );
00503   numberArrayLengthDepList.set("Variable Length Array", variableLengthArray, "variable length array",
00504   Teuchos::RCP<Optika::ArrayNumberValidator<double> >(new Optika::ArrayNumberValidator<double>(varLengthArrayVali)));
00505 
00506   Teuchos::RCP<Optika::NumberArrayLengthDependency> 
00507   arrayLengthDep = Teuchos::RCP<Optika::NumberArrayLengthDependency>(
00508       new Optika::NumberArrayLengthDependency(
00509       "Array Length", 
00510       Teuchos::sublist(My_deplist,"Number Array Length Dependency List"),
00511       "Variable Length Array", 
00512       Teuchos::sublist(My_deplist,"Number Array Length Dependency List")
00513     )
00514   );
00515   depSheet1->addDependency(arrayLengthDep);
00516   Teuchos::Array<double> dummyType;
00517   TEST_ASSERT(numberArrayLengthDepList.get("Variable Length Array", dummyType).length() ==10);
00518   numberArrayLengthDepList.set("Array Length", 12);
00519   arrayLengthDep()->evaluate();
00520   TEST_ASSERT(numberArrayLengthDepList.get("Variable Length Array", dummyType).length() ==12);
00521   numberArrayLengthDepList.set("Array Length", -1);
00522   TEST_THROW(arrayLengthDep()->evaluate(), Teuchos::Exceptions::InvalidParameterValue);
00523 
00524   return (success ? 0:1);
00525 }
00526 
00530 int testNumberValiAspDep(Teuchos::FancyOStream &out){
00531   bool success = true;
00532   Teuchos::RCP<Teuchos::ParameterList> My_deplist = Teuchos::RCP<Teuchos::ParameterList>(new Teuchos::ParameterList);
00533   Teuchos::RCP<Optika::DependencySheet> depSheet1 = Teuchos::RCP<Optika::DependencySheet>(new Optika::DependencySheet(My_deplist));
00534 
00535   Teuchos::ParameterList&
00536   numberValiAspDepList = My_deplist->sublist(
00537     "Number Validator Aspect Dependency List",
00538     false,
00539     "Number Validator Aspect Dependency testing list.\nWorking June 27th 2009"
00540   );
00541   Teuchos::RCP<Optika::EnhancedNumberValidator<int> > intVali2 = 
00542   Teuchos::rcp(new Optika::EnhancedNumberValidator<int>(0,20));
00543   numberValiAspDepList.set("Int", 8, "Int tester", intVali2);
00544   numberValiAspDepList.set("Int2", 8, "int2 tester", intVali2);
00545   numberValiAspDepList.set("Int dependee", 1, "Int dependee");
00546 
00547   int (*func)(int);
00548   func = intFuncTester;
00549 
00550   Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> > 
00551   intDep1 = Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> >(
00552     new Optika::NumberValidatorAspectDependency<int>(
00553       "Int dependee",
00554       Teuchos::sublist(My_deplist,"Number Validator Aspect Dependency List"),
00555       "Int",
00556       Teuchos::sublist(My_deplist,"Number Validator Aspect Dependency List"),
00557       intVali2,
00558       Optika::NumberValidatorAspectDependency<int>::Max,
00559       func
00560     )
00561   );
00562   
00563   Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> > 
00564   intDep2 = Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> >(
00565     new Optika::NumberValidatorAspectDependency<int>(
00566       "Int dependee",
00567       Teuchos::sublist(My_deplist,"Number Validator Aspect Dependency List"),
00568       "Int2",
00569       Teuchos::sublist(My_deplist,"Number Validator Aspect Dependency List"),
00570       intVali2,
00571       Optika::NumberValidatorAspectDependency<int>::Max,
00572       func
00573     )
00574   );
00575 
00576   depSheet1->addDependency(intDep1);
00577   depSheet1->addDependency(intDep2);
00578 
00579   TEST_ASSERT(Teuchos::rcp_static_cast<const Optika::EnhancedNumberValidator<int> >(numberValiAspDepList.getEntry("Int").validator())->max() == 20);
00580   TEST_ASSERT(Teuchos::rcp_static_cast<const Optika::EnhancedNumberValidator<int> >(numberValiAspDepList.getEntry("Int2").validator())->max() == 20);
00581   intDep1->evaluate();
00582   TEST_ASSERT(Teuchos::rcp_static_cast<const Optika::EnhancedNumberValidator<int> >(numberValiAspDepList.getEntry("Int").validator())->max() == 11);
00583   TEST_ASSERT(Teuchos::rcp_static_cast<const Optika::EnhancedNumberValidator<int> >(numberValiAspDepList.getEntry("Int2").validator())->max() == 11);
00584 
00585 
00586   return (success ? 0:1);
00587 }
00588 
00592 int testDepExceptions(Teuchos::FancyOStream &out){
00593   bool success = true;
00594   Teuchos::RCP<Teuchos::ParameterList> list1 = Teuchos::RCP<Teuchos::ParameterList>(new Teuchos::ParameterList());
00595   Teuchos::RCP<Teuchos::ParameterList> list2 = Teuchos::RCP<Teuchos::ParameterList>(new Teuchos::ParameterList());
00596 
00597   list1->set("int parameter", 4, "int parameter");
00598   list1->set("double parameter", 6.0, "double parameter");
00599   list1->set("string parameter", "hahahaha", "string parameter");
00600   Teuchos::Array<double> doubleArray(10,23.0);
00601   list1->set("array parameter", doubleArray, "array parameter");
00602   list1->set("bool parameter", true, "bool parameter");
00603 
00604   /*
00605    * Testing StringVisualDepenendcy exceptions.
00606    */
00607   Teuchos::RCP<Optika::StringVisualDependency> stringVisDep;
00608   TEST_THROW(stringVisDep = Teuchos::RCP<Optika::StringVisualDependency>(new Optika::StringVisualDependency("not in list", list1, "int parameter", list1, "cheese", true)), Optika::InvalidDependencyException);
00609   TEST_THROW(stringVisDep = Teuchos::RCP<Optika::StringVisualDependency>(new Optika::StringVisualDependency("string parameter", list1, "not in list", list1, "cheese", true)), Optika::InvalidDependencyException);
00610   TEST_THROW(stringVisDep = Teuchos::RCP<Optika::StringVisualDependency>(new Optika::StringVisualDependency("double parameter", list1, "int parameter", list1, "cheese", true)), Optika::InvalidDependencyException);
00611 
00612   TEST_THROW(Teuchos::RCP<Optika::BoolVisualDependency> boolVisDep = Teuchos::RCP<Optika::BoolVisualDependency>(new Optika::BoolVisualDependency("int parameter", list1, "double parameter", list1, false)), Optika::InvalidDependencyException);
00613 
00614   TEST_THROW(Teuchos::RCP<Optika::NumberArrayLengthDependency> numArrayLengthDep = Teuchos::RCP<Optika::NumberArrayLengthDependency>(new Optika::NumberArrayLengthDependency("double parameter", list1, "array parameter", list1)), Optika::InvalidDependencyException);
00615   TEST_THROW(Teuchos::RCP<Optika::NumberArrayLengthDependency> numArrayLengthDep = Teuchos::RCP<Optika::NumberArrayLengthDependency>(new Optika::NumberArrayLengthDependency("int parameter", list1, "double parameter", list1)), Optika::InvalidDependencyException);
00616 
00617   /*
00618    * Testing StringValidatorDependency exceptions.
00619    */
00620   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00621     cheeseValidator = Teuchos::rcp(
00622     new Teuchos::StringToIntegralParameterEntryValidator<int>(
00623         Teuchos::tuple<std::string>( "Swiss", "American", "Super Awesome Cheese" )
00624       ,"Food Selector"
00625       )
00626   );
00627 
00628   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00629   sodaValidator = Teuchos::rcp(
00630     new Teuchos::StringToIntegralParameterEntryValidator<int>(
00631       Teuchos::tuple<std::string>( "Pepsi", "Coke", "Kurtis Cola", "Bad Cola" )
00632       ,"Food Selector"
00633       )
00634     );
00635 
00636   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00637   chipsValidator = Teuchos::rcp(
00638     new Teuchos::StringToIntegralParameterEntryValidator<int>(
00639       Teuchos::tuple<std::string>( "Lays", "Doritos", "Kurtis Super Awesome Brand" )
00640       ,"Food Selector"
00641     )
00642   );
00643 
00644 
00645   list1->set("string 2 parameter", "Swiss", "second string parameter", cheeseValidator);
00646   Optika::StringValidatorDependency::ValueToValidatorMap testValidatorMap1;
00647   testValidatorMap1["Cheese"] = cheeseValidator;
00648   testValidatorMap1["Soda"] = sodaValidator;
00649   testValidatorMap1["Chips"] = chipsValidator;
00650   TEST_THROW(Teuchos::RCP<Optika::StringValidatorDependency> stringValiDep = Teuchos::RCP<Optika::StringValidatorDependency>(new Optika::StringValidatorDependency("int parameter", list1, "string 2 parameter", list1, testValidatorMap1, cheeseValidator)), Optika::InvalidDependencyException);
00651   Teuchos::RCP<Optika::EnhancedNumberValidator<int> > intVali = Teuchos::rcp(new Optika::EnhancedNumberValidator<int>(0,20));
00652   testValidatorMap1["Candy"] = intVali;
00653   TEST_THROW(Teuchos::RCP<Optika::StringValidatorDependency> stringValiDep = Teuchos::RCP<Optika::StringValidatorDependency>(new Optika::StringValidatorDependency("string parameter", list1, "string 2 parameter", list1, testValidatorMap1, cheeseValidator)), Optika::InvalidDependencyException);
00654   
00655   /*
00656    * Testing BoolValidatorDependency exceptions.
00657    */
00658   Teuchos::RCP<Optika::EnhancedNumberValidator<double> > doubleVali1 = Teuchos::rcp(new Optika::EnhancedNumberValidator<double>(0.0,20.0));
00659   Teuchos::RCP<Optika::EnhancedNumberValidator<double> > doubleVali2 = Teuchos::rcp(new Optika::EnhancedNumberValidator<double>(5.0,20.0));
00660   list1->set("double parameter", 6.0, "double parameter", doubleVali1);
00661   TEST_THROW(Teuchos::RCP<Optika::BoolValidatorDependency> boolValiDep = Teuchos::RCP<Optika::BoolValidatorDependency>(new Optika::BoolValidatorDependency("int parameter", list1, "double parameter", list1, doubleVali1, doubleVali2)), Optika::InvalidDependencyException);
00662   TEST_THROW(Teuchos::RCP<Optika::BoolValidatorDependency> boolValiDep = Teuchos::RCP<Optika::BoolValidatorDependency>(new Optika::BoolValidatorDependency("bool parameter", list1, "double parameter", list1, intVali, doubleVali2)), Optika::InvalidDependencyException);
00663   TEST_THROW(Teuchos::RCP<Optika::BoolValidatorDependency> boolValiDep = Teuchos::RCP<Optika::BoolValidatorDependency>(new Optika::BoolValidatorDependency("bool parameter", list1, "double parameter", list1, doubleVali1, intVali)), Optika::InvalidDependencyException);
00664 
00665   TEST_THROW(Teuchos::RCP<Optika::NumberVisualDependency<int> > boolValiDep = Teuchos::RCP<Optika::NumberVisualDependency<int> >(new Optika::NumberVisualDependency<int>("bool parameter", list1, "double parameter", list1, intFuncTester)), Optika::InvalidDependencyException);
00666 
00667 
00668   /*
00669    * Testing NumberValidatorAspectDependency exceptions.
00670    */
00671   list1->set("int 2 parameter", 6, "int 2 parameter");
00672   TEST_THROW(Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> > 
00673     intDep1 = Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> >(
00674       new Optika::NumberValidatorAspectDependency<int>(
00675         "int parameter",
00676         list1,
00677         "int 2 parameter",
00678         list1,
00679         intVali,
00680         Optika::NumberValidatorAspectDependency<int>::Max,
00681         intFuncTester
00682       )
00683     ),
00684     Optika::InvalidDependencyException
00685   );
00686 
00687   list1->set("int 2 parameter", 6, "int 2 parameter", intVali);
00688   TEST_THROW(Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> > 
00689     intDep1 = Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> >(
00690       new Optika::NumberValidatorAspectDependency<int>(
00691         "string parameter",
00692         list1,
00693         "int 2 parameter",
00694         list1,
00695         intVali,
00696         Optika::NumberValidatorAspectDependency<int>::Max,
00697         intFuncTester
00698       )
00699     ),
00700     Optika::InvalidDependencyException
00701   );
00702   Teuchos::RCP<Optika::EnhancedNumberValidator<int> > intVali2 = Teuchos::rcp(new Optika::EnhancedNumberValidator<int>(5,20));
00703   TEST_THROW(Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> > 
00704     intDep1 = Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> >(
00705       new Optika::NumberValidatorAspectDependency<int>(
00706         "int parameter",
00707         list1,
00708         "int 2 parameter",
00709         list1,
00710         intVali2,
00711         Optika::NumberValidatorAspectDependency<int>::Max,
00712         intFuncTester
00713       )
00714     ),
00715     Optika::InvalidDependencyException
00716   );
00717 
00718   TEST_THROW(Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> > 
00719     intDep1 = Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> >(
00720       new Optika::NumberValidatorAspectDependency<int>(
00721         "int parameter",
00722         list1,
00723         "double parameter",
00724         list1,
00725         intVali,
00726         Optika::NumberValidatorAspectDependency<int>::Max,
00727         intFuncTester
00728       )
00729     ),
00730     Optika::InvalidDependencyException
00731   );
00732 
00733   TEST_THROW(Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> > 
00734     intDep1 = Teuchos::RCP<Optika::NumberValidatorAspectDependency<int> >(
00735       new Optika::NumberValidatorAspectDependency<int>(
00736         "double parameter",
00737         list1,
00738         "int parameter",
00739         list1,
00740         intVali,
00741         Optika::NumberValidatorAspectDependency<int>::Max,
00742         intFuncTester
00743       )
00744     ),
00745     Optika::InvalidDependencyException
00746   );
00747 
00748   /*
00749    * Testing RangeValidatorDependency exceptions.
00750    */
00751   list1->set("Cheese to Fondue", "Swiss", "the cheese to fondue");
00752   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00753   lowTempCheeseValidator = Teuchos::rcp(
00754     new Teuchos::StringToIntegralParameterEntryValidator<int>(
00755       Teuchos::tuple<std::string>( "PepperJack", "Swiss", "American" ),
00756       "Cheese to Fondue"
00757     )
00758   );
00759   Teuchos::RCP<Teuchos::StringToIntegralParameterEntryValidator<int> >
00760   highTempCheeseValidator = Teuchos::rcp(
00761     new Teuchos::StringToIntegralParameterEntryValidator<int>(
00762       Teuchos::tuple<std::string>( "Munster", "Provalone", "Kurtis Super Awesome Cheese"),
00763       "Cheese to Fondue"
00764     )
00765   );
00766   list1->set("Cheese to Fondue", "Swiss", "the cheese to fondue", lowTempCheeseValidator);
00767   Optika::RangeValidatorDependency<double>::RangeToValidatorMap tempranges;
00768   tempranges[std::pair<double,double>(100,200)] = lowTempCheeseValidator;
00769   tempranges[std::pair<double,double>(200,300)] = highTempCheeseValidator;
00770   TEST_THROW(
00771     Teuchos::RCP<Optika::RangeValidatorDependency<double> > 
00772     cheeseTempDep = Teuchos::RCP<Optika::RangeValidatorDependency<double> >(
00773       new Optika::RangeValidatorDependency<double>(
00774         "string parameter", 
00775         list1,  
00776         "Cheese to Fondue", 
00777         list1,  
00778         tempranges, 
00779         lowTempCheeseValidator
00780       )
00781     ),
00782     Optika::InvalidDependencyException
00783   );
00784   tempranges[std::pair<double,double>(400,800)] = intVali;
00785   TEST_THROW(
00786     Teuchos::RCP<Optika::RangeValidatorDependency<double> > 
00787     cheeseTempDep = Teuchos::RCP<Optika::RangeValidatorDependency<double> >(
00788       new Optika::RangeValidatorDependency<double>(
00789         "int parameter", 
00790         list1,  
00791         "Cheese to Fondue", 
00792         list1,
00793         tempranges, 
00794         lowTempCheeseValidator
00795       )
00796     ),
00797     Optika::InvalidDependencyException
00798   );
00799 
00800 
00801   /*
00802    * Testing DependencySheet exceptions.
00803    */
00804   Teuchos::RCP<Optika::DependencySheet> depSheet1 = Teuchos::RCP<Optika::DependencySheet>(new Optika::DependencySheet(list1));
00805   Teuchos::RCP<Optika::DependencySheet> depSheet2 = Teuchos::RCP<Optika::DependencySheet>(new Optika::DependencySheet(list2));
00806 
00807   list2->set("list2 double", 4.0, "a double parameter in list 2");
00808   list2->set("list2 bool", true, "a bool parameter in list2");
00809 
00810   Teuchos::RCP<Optika::BoolVisualDependency> boolVisDep = Teuchos::RCP<Optika::BoolVisualDependency>(new Optika::BoolVisualDependency("bool parameter", list1, "list2 double", list2, false));
00811   TEST_THROW(depSheet2->addDependency(boolVisDep), Optika::InvalidDependencyException);
00812   boolVisDep = Teuchos::RCP<Optika::BoolVisualDependency>(new Optika::BoolVisualDependency("list2 bool", list2, "double parameter", list1, false));
00813   TEST_THROW(depSheet2->addDependency(boolVisDep), Optika::InvalidDependencyException);
00814 
00815 
00816   return (success ? 0:1);
00817 }
00818 
00819 int main(int argc, char* argv[]){
00820   bool success = true;
00821   Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::VerboseObjectBase::getDefaultOStream();
00822   if(testValiDeps(*out) == 1){
00823     success = false;
00824   }
00825   if(testVisualDeps(*out) == 1){
00826     success = false;
00827   }
00828   if(testArrayLengthDep(*out) == 1){
00829     success = false;
00830   }
00831   if(testNumberValiAspDep(*out) == 1){
00832     success = false;
00833   }
00834 
00835   if(testDepExceptions(*out) ==1){
00836     success = false;
00837   }
00838   return (success ? 0:1);
00839 }
00840 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends