Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Dependencies_UnitTests.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
48 
49 
50 namespace Teuchos{
51 
55 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testValiDeps){
56  RCP<ParameterList> My_deplist = rcp(new ParameterList);
57  RCP<DependencySheet> depSheet1 = rcp(new DependencySheet);
58 
59  /*
60  * Testing StringValidatorDependency
61  */
63  stringFoodTypeValidator = rcp(
65  tuple<std::string>( "Cheese", "Soda", "Chips" )
66  ,"Food Type"
67  )
68  );
69 
71  cheeseValidator = rcp(
73  tuple<std::string>( "Swiss", "American", "Super Awesome Cheese" )
74  ,"Food Selector"
75  )
76  );
77 
79  sodaValidator = rcp(
81  tuple<std::string>( "Pepsi", "Coke", "Kurtis Cola", "Bad Cola" )
82  ,"Food Selector"
83  )
84  );
85 
87  chipsValidator = rcp(
89  tuple<std::string>( "Lays", "Doritos", "Kurtis Super Awesome Brand" )
90  ,"Food Selector"
91  )
92  );
93 
95  testValidatorMap1["Cheese"] = cheeseValidator;
96  testValidatorMap1["Soda"] = sodaValidator;
97  testValidatorMap1["Chips"] = chipsValidator;
98 
99  ParameterList stringValiDepList = My_deplist->sublist(
100  "String Validator Dependency", false,
101  "String Validator Dependency testing list.");
102  stringValiDepList.set(
103  "Food Selector", "Swiss", "select the food you want", cheeseValidator);
104  stringValiDepList.set(
105  "Food Type",
106  "Cheese",
107  "String Validator Dependency Tester",
108  stringFoodTypeValidator);
109 
111  stringValiDep = rcp(
113  stringValiDepList.getEntryRCP("Food Type"),
114  stringValiDepList.getEntryRCP("Food Selector"),
115  testValidatorMap1,
116  cheeseValidator
117  )
118  );
119 
120  depSheet1->addDependency(stringValiDep);
121 
122  TEST_NOTHROW(stringValiDepList.validateParameters(stringValiDepList));
123  TEST_ASSERT(depSheet1->hasDependents(
124  stringValiDepList.getEntryRCP("Food Type")));
125  RCP<const DependencySheet::DepSet> stringValiDepSet =
126  depSheet1->getDependenciesForParameter(
127  stringValiDepList.getEntryRCP("Food Type"));
128  TEST_ASSERT(stringValiDepSet->size() == 1);
129  stringValiDepList.set("Food Type","Soda");
130  stringValiDep->evaluate();
131  TEST_ASSERT(stringValiDepList.getEntry("Food Selector").validator()
132  ==
133  sodaValidator);
134  TEST_THROW(stringValiDepList.validateParameters(stringValiDepList),
136  stringValiDepList.set("Food Selector", "Pepsi");
137  TEST_NOTHROW(stringValiDepList.validateParameters(stringValiDepList));
138 
139 
140  /*
141  * Tesing some different aspects of the StringValidatorDependency
142  */
144  stringValiDepList2 = My_deplist->sublist(
145  "String Validator Dependency (other validators)",
146  false,
147  "String validator testing"
148  );
149 
151  stringRangeValidator = rcp(
153  tuple<std::string>( "1-10", "10-33", "50-60" ),
154  "Range selector"
155  )
156  );
157 
158  RCP<EnhancedNumberValidator<int> > range110Vali =
160  RCP<EnhancedNumberValidator<int> > range1033Vali =
161  rcp(new EnhancedNumberValidator<int>(10,33));
162  RCP<EnhancedNumberValidator<int> > range5060Vali =
163  rcp(new EnhancedNumberValidator<int>(50,60));
164 
165  stringValiDepList2.set("Range selector", "1-10",
166  "selects the range to validate", stringRangeValidator);
167 
169  rangeValidatorMap1["1-10"] = range110Vali;
170  rangeValidatorMap1["10-33"] = range1033Vali;
171  rangeValidatorMap1["50-60"] = range5060Vali;
172  stringValiDepList2.set(
173  "RangeValue", 3, "the value of the range", range110Vali);
174 
176  stringValiDep2 = RCP<StringValidatorDependency>(
178  stringValiDepList2.getEntryRCP("Range selector"),
179  stringValiDepList2.getEntryRCP("RangeValue"),
180  rangeValidatorMap1,
181  range110Vali
182  )
183  );
184 
185  depSheet1->addDependency(stringValiDep2);
186 
187  TEST_NOTHROW(stringValiDepList2.validateParameters(stringValiDepList2));
188  TEST_ASSERT(depSheet1->hasDependents(
189  stringValiDepList2.getEntryRCP("Range selector")));
190  RCP<const DependencySheet::DepSet> stringValiDepSet2 =
191  depSheet1->getDependenciesForParameter(
192  stringValiDepList2.getEntryRCP("Range selector"));
193  TEST_ASSERT(stringValiDepSet2->size() == 1);
194  stringValiDepList2.set("Range selector","50-60");
195  stringValiDep2->evaluate();
196  TEST_ASSERT(stringValiDepList2.getEntry("RangeValue").validator()
197  ==
198  range5060Vali);
199  TEST_THROW(stringValiDepList2.validateParameters(stringValiDepList2),
201  stringValiDepList2.set("RangeValue", 55);
202  TEST_NOTHROW(stringValiDepList2.validateParameters(stringValiDepList2));
203 
204  /*
205  * Testing the BoolValidatorDependency.
206  */
208  boolValidatorDepList = My_deplist->sublist(
209  "Bool Validator Dependency List",
210  false,
211  "Bool Validator Dependency testing list."
212  );
213 
214  boolValidatorDepList.set("Use Validator?",
215  true, "truns the validator on and off");
218  RCP<EnhancedNumberValidator<int> > basicVali2 =
220  boolValidatorDepList.set("do I have a validator?",
221  4, "does it have a validator?", basicVali);
222 
224  boolValiDep = RCP<BoolValidatorDependency>(
226  boolValidatorDepList.getEntryRCP("Use Validator?"),
227  boolValidatorDepList.getEntryRCP("do I have a validator?"),
228  basicVali,
229  basicVali2
230  )
231  );
232 
233  depSheet1->addDependency(boolValiDep);
234 
235  TEST_ASSERT(depSheet1->hasDependents(
236  boolValidatorDepList.getEntryRCP("Use Validator?")));
237  TEST_ASSERT(
238  boolValidatorDepList.getEntry("do I have a validator?").validator()
239  ==
240  basicVali);
241  TEST_NOTHROW(
242  boolValidatorDepList.validateParameters(boolValidatorDepList));
243  RCP<const DependencySheet::DepSet> boolValiDepSet =
244  depSheet1->getDependenciesForParameter(boolValidatorDepList.getEntryRCP(
245  "Use Validator?"));
246  TEST_ASSERT(boolValiDepSet->size() == 1);
247  boolValidatorDepList.set("Use Validator?",false);
248  boolValiDep->evaluate();
249  TEST_ASSERT(
250  boolValidatorDepList.getEntry("do I have a validator?").validator()
251  ==
252  basicVali2);
253 
254 
255  /*
256  * Testing the RangeValidatorDependency
257  */
259  lowTempCheeseValidator = rcp(
261  tuple<std::string>( "PepperJack", "Swiss", "American" ),
262  "Cheese to Fondue"
263  )
264  );
265 
267  highTempCheeseValidator = rcp(
269  tuple<std::string>(
270  "Munster", "Provalone", "Kurtis Super Awesome Cheese"),
271  "Cheese to Fondue"
272  )
273  );
274 
276  defaultCheeseValidator = rcp(
278  tuple<std::string>(
279  "Other cheese", "other cheese 1", "other cheese 3"),
280  "Cheese to Fondue"
281  )
282  );
283 
285  rangeValidatorDepList = My_deplist->sublist(
286  "Range Validator Dependency List",
287  false,
288  "Range Validator Dependency testing list.\nWorking June 27th 2009"
289  );
290  rangeValidatorDepList.set(
291  "Temperature",101.0, "The temperature of the fondue");
292  rangeValidatorDepList.set(
293  "Cheese to Fondue", "Swiss",
294  "The cheese we'll be using in our fondue pot.", lowTempCheeseValidator);
296  tempranges[std::pair<double,double>(100,200)] = lowTempCheeseValidator;
297  tempranges[std::pair<double,double>(200,300)] = highTempCheeseValidator;
299  cheeseTempDep = RCP<RangeValidatorDependency<double> >(
301  rangeValidatorDepList.getEntryRCP("Temperature"),
302  rangeValidatorDepList.getEntryRCP("Cheese to Fondue"),
303  tempranges,
304  defaultCheeseValidator
305  )
306  );
307  depSheet1->addDependency(cheeseTempDep);
308 
309  TEST_ASSERT(depSheet1->hasDependents(
310  rangeValidatorDepList.getEntryRCP("Temperature")));
311  RCP<const DependencySheet::DepSet> rangeValiDepSet =
312  depSheet1->getDependenciesForParameter(
313  rangeValidatorDepList.getEntryRCP("Temperature"));
314  TEST_ASSERT(rangeValiDepSet->size() == 1);
315  rangeValidatorDepList.set("Temperature",250.0);
316  cheeseTempDep->evaluate();
317  TEST_ASSERT(
318  rangeValidatorDepList.getEntry("Cheese to Fondue").validator()
319  ==
320  highTempCheeseValidator);
321  TEST_THROW(
322  rangeValidatorDepList.validateParameters(rangeValidatorDepList),
324  rangeValidatorDepList.set("Cheese to Fondue", "Provalone");
325  TEST_NOTHROW(
326  rangeValidatorDepList.validateParameters(rangeValidatorDepList));
327  rangeValidatorDepList.set("Temperature", 50.0);
328  cheeseTempDep->evaluate();
329  TEST_ASSERT(
330  rangeValidatorDepList.getEntry("Cheese to Fondue").validator()
331  ==
332  defaultCheeseValidator
333  );
334 
335 }
336 
340 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testVisualDeps){
342  RCP<DependencySheet> depSheet1 =
344  /*
345  * Two Simple NumberVisualDependency test
346  */
347 
349  simpleNumDepTestList = My_deplist->sublist(
350  "NumberVisual Dependency List (double)",
351  false,
352  "Number visual Dependency testing list"
353  );
354 
355  simpleNumDepTestList.set("Temperature",101.0);
356  simpleNumDepTestList.set("Cheese to Fondue", "Swiss", "The cheese to fondue");
357  simpleNumDepTestList.set("reverse param", "hello");
358 
359  RCP<NumberVisualDependency<double> > simpleNumDep =
362  simpleNumDepTestList.getEntryRCP("Temperature"),
363  simpleNumDepTestList.getEntryRCP("Cheese to Fondue"),
364  true
365  )
366  );
367  RCP<NumberVisualDependency<double> > reverseNumDep =
370  simpleNumDepTestList.getEntryRCP("Temperature"),
371  simpleNumDepTestList.getEntryRCP("reverse param"),
372  false
373  )
374  );
375  depSheet1->addDependency(simpleNumDep);
376  depSheet1->addDependency(reverseNumDep);
377  simpleNumDep->evaluate();
378  reverseNumDep->evaluate();
379  TEST_ASSERT(simpleNumDep->isDependentVisible());
380  TEST_ASSERT(!reverseNumDep->isDependentVisible());
381  simpleNumDepTestList.set("Temperature",-1.0);
382  simpleNumDep->evaluate();
383  reverseNumDep->evaluate();
384  TEST_ASSERT(!simpleNumDep->isDependentVisible());
385  TEST_ASSERT(reverseNumDep->isDependentVisible());
386 
387 
388  /*
389  * complex Testing the NumberVisualDependency
390  */
392  doubleVisualDepList = My_deplist->sublist(
393  "NumberVisual Dependency List (double)",
394  false,
395  "Number visual Dependency testing list"
396  );
397 
398  doubleVisualDepList.set(
399  "Temperature",101.0, "The temperature of the fondue");
400  doubleVisualDepList.set(
401  "Cheese to Fondue", "Swiss", "The cheese to fondue");
402  doubleVisualDepList.set("reverse param", "hello");
403  RCP<SubtractionFunction<double> > fondueFunc = rcp(new
405 
409  doubleVisualDepList.getEntryRCP("Temperature"),
410  doubleVisualDepList.getEntryRCP("Cheese to Fondue"),
411  true,
412  fondueFunc
413  )
414  );
415  RCP<NumberVisualDependency<double> > reverseFondueDep =
418  doubleVisualDepList.getEntryRCP("Temperature"),
419  doubleVisualDepList.getEntryRCP("reverse param"),
420  false,
421  fondueFunc
422  )
423  );
424  depSheet1->addDependency(fondueDep);
425  depSheet1->addDependency(reverseFondueDep);
426  fondueDep->evaluate();
427  reverseFondueDep->evaluate();
428  TEST_ASSERT(fondueDep->isDependentVisible());
429  TEST_ASSERT(!reverseFondueDep->isDependentVisible());
430  doubleVisualDepList.set("Temperature",99.0);
431  fondueDep->evaluate();
432  reverseFondueDep->evaluate();
433  TEST_ASSERT(!fondueDep->isDependentVisible());
434  TEST_ASSERT(reverseFondueDep->isDependentVisible());
435 
436  /*
437  * Testing the BoolVisualDependency
438  */
440  boolVisDepList = My_deplist->sublist(
441  "Bool Visual Dependency List",
442  false,
443  "Bool Visual Dependency testing list."
444  );
445  boolVisDepList.set(
446  "ShowPrecs", true, "Whether or not to should the Preciondtioner list");
448  Prec_List0 = boolVisDepList.sublist(
449  "Preconditioner",false,"Sublist that defines the preconditioner.");
450  Prec_List0.set("Type", "ILU", "The tpye of preconditioner to use");
451  RCP<EnhancedNumberValidator<double> > droptolValidator =
452  rcp(new EnhancedNumberValidator<double>(0,10,1e-3));
453  Prec_List0.set(
454  "Drop Tolerance", 1e-3,
455  "The tolerance below which entries from the "
456  "factorization are left out of the factors.", droptolValidator);
458  precDep1 = RCP<BoolVisualDependency>(
460  boolVisDepList.getEntryRCP("ShowPrecs"),
461  boolVisDepList.getEntryRCP("Preconditioner"),
462  true
463  )
464  );
465  depSheet1->addDependency(precDep1);
466  precDep1->evaluate();
467  TEST_ASSERT(precDep1->isDependentVisible());
468  boolVisDepList.set("ShowPrecs", false);
469  precDep1->evaluate();
470  TEST_ASSERT(!precDep1->isDependentVisible());
471 
472 
473 
474  /*
475  * Testing the StringVisualDepenency
476  */
478  stringVisDepList = My_deplist->sublist(
479  "String Visual Dependency List",
480  false,
481  "String Visual Dependency testing list."
482  );
484  favCheeseValidator = rcp(
486  tuple<std::string>( "Swiss", "American", "Cheder" ),
487  "Favorite Cheese"
488  )
489  );
490 
491  stringVisDepList.set("Favorite Cheese",
492  "American", "Your favorite type of cheese", favCheeseValidator);
494  swissValidator = rcp(new EnhancedNumberValidator<int>(0,10));
495  stringVisDepList.set("Swiss rating", 0,
496  "How you rate swiss on a scale of 1 to 10", swissValidator);
498  swissDep1 = RCP<StringVisualDependency>(
500  stringVisDepList.getEntryRCP("Favorite Cheese"),
501  stringVisDepList.getEntryRCP("Swiss rating"),
502  "Swiss",
503  true
504  )
505  );
506  depSheet1->addDependency(swissDep1);
507  swissDep1->evaluate();
508  TEST_ASSERT(!swissDep1->isDependentVisible());
509  stringVisDepList.set("Favorite Cheese", "Swiss");
510  swissDep1->evaluate();
511  TEST_ASSERT(swissDep1->isDependentVisible());
512 
513  /*
514  * String Visual Tester with multiple values
515  */
516  ParameterList multiStringVisDepList = My_deplist->sublist(
517  "Multi String Visual Dependency List",
518  false
519  );
521  favCheeseValidator2 = rcp(
523  tuple<std::string>( "Provalone", "Swiss", "American", "Cheder" ),
524  "Favorite Cheese"
525  )
526  );
527 
528  multiStringVisDepList.set(
529  "Favorite Cheese", "American",
530  "Your favorite type of cheese", favCheeseValidator2);
531  multiStringVisDepList.set("Swiss rating", 0,
532  "How you rate swiss on a scale of 1 to 10", swissValidator);
534  swissDep2 = RCP<StringVisualDependency>(
536  multiStringVisDepList.getEntryRCP("Favorite Cheese"),
537  multiStringVisDepList.getEntryRCP("Swiss rating"),
538  tuple<std::string>("Swiss", "Cheder"),
539  true
540  )
541  );
542  depSheet1->addDependency(swissDep2);
543  swissDep2->evaluate();
544  TEST_ASSERT(!swissDep2->isDependentVisible());
545  multiStringVisDepList.set("Favorite Cheese", "Cheder");
546  swissDep2->evaluate();
547  TEST_ASSERT(swissDep2->isDependentVisible());
548 
549  /*
550  * Another test of the NumberVisualDependency.
551  */
553  numberVisDepList = My_deplist->sublist(
554  "Number Visual Dependency List",
555  false,
556  "Number Visual Dependency testing list."
557  );
558  numberVisDepList.set("Ice", 50, "Ice stuff");
559  numberVisDepList.set("Room Temp", 10, "Room temperature");
560  RCP<SubtractionFunction<int> > visFunc = rcp(new
565  numberVisDepList.getEntryRCP("Room Temp"),
566  numberVisDepList.getEntryRCP("Ice"),
567  true,
568  visFunc
569  )
570  );
571  depSheet1->addDependency(iceDep);
572  iceDep->evaluate();
573  TEST_ASSERT(!iceDep->isDependentVisible());
574  numberVisDepList.set("Room Temp", 33);
575  iceDep->evaluate();
576  TEST_ASSERT(iceDep->isDependentVisible());
577 
578  /*
579  * Test condition visual dependency
580  */
581  RCP<ParameterList> conVisDepList = sublist(
582  My_deplist,"Condition Visual Dependency List", false);
583  conVisDepList->set("double param", 4.0, "double parameter");
584  conVisDepList->set("bool param", true, "bool parameter");
585  conVisDepList->set("string param", "blah", "a string parameter");
586  RCP<NumberCondition<double> > numberCon =
588  conVisDepList->getEntryRCP("double param")));
589  RCP<BoolCondition> boolCon =
590  rcp(new BoolCondition(conVisDepList->getEntryRCP("bool param")));
592  tuple<RCP<const Condition> >(numberCon, boolCon);
593  RCP<AndCondition> andCon = rcp(new AndCondition(conList));
596  andCon, conVisDepList->getEntryRCP("string param"), true));
597  depSheet1->addDependency(conVisDep);
598  conVisDep->evaluate();
599  TEST_ASSERT(conVisDep->isDependentVisible());
600  conVisDepList->set("bool param", false);
601  conVisDep->evaluate();
602  TEST_ASSERT(!conVisDep->isDependentVisible());
603 }
604 
608 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testTwoDRowDependency){
610  RCP<DependencySheet> depSheet1 =
612 
614  rowNumDepList = My_deplist->sublist(
615  "2D Row Depdency List", false,
616  "2D Row Dependecy testing list.");
617  rowNumDepList.set("Num rows", 10, "num rows setter");
618  TwoDArray<double> variableRowsArray(11,2,16.5);
620  varRowArrayVali = RCP<EnhancedNumberValidator<double> >(
622  );
623  rowNumDepList.set(
624  "Variable Row Array", variableRowsArray, "variable row array",
626  new TwoDArrayNumberValidator<double>(varRowArrayVali)));
627 
629  arrayRowDep = rcp(
631  rowNumDepList.getEntryRCP("Num rows"),
632  rowNumDepList.getEntryRCP("Variable Row Array") ,
633  rcp(new AdditionFunction<int>(1))
634  )
635  );
636  depSheet1->addDependency(arrayRowDep);
637  TwoDArray<double> curArray =
638  rowNumDepList.get<TwoDArray<double> >("Variable Row Array");
639  TEST_EQUALITY_CONST(curArray.getNumRows(),11);
640  rowNumDepList.set("Num rows", 12);
641  arrayRowDep()->evaluate();
642  curArray =
643  rowNumDepList.get<TwoDArray<double> >("Variable Row Array");
644  TEST_EQUALITY_CONST(curArray.getNumRows(),13);
645  rowNumDepList.set("Num rows", -2);
646  TEST_THROW(arrayRowDep()->evaluate(),
648 }
649 
653 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testTwoDColDependency){
655  RCP<DependencySheet> depSheet1 =
657 
659  colNumDepList = My_deplist->sublist(
660  "2D Col Depdency List", false,
661  "2D Col Dependecy testing list.");
662  colNumDepList.set("Num cols", 2, "num cols setter");
663  TwoDArray<double> variableColsArray(11,3,16.5);
665  varColArrayVali = RCP<EnhancedNumberValidator<double> >(
667  );
668  colNumDepList.set(
669  "Variable Col Array", variableColsArray, "variable col array",
671  new TwoDArrayNumberValidator<double>(varColArrayVali)));
672 
674  arrayColDep = rcp(
676  colNumDepList.getEntryRCP("Num cols"),
677  colNumDepList.getEntryRCP("Variable Col Array") ,
678  rcp(new AdditionFunction<int>(1))
679  )
680  );
681  depSheet1->addDependency(arrayColDep);
682  TwoDArray<double> curArray =
683  colNumDepList.get<TwoDArray<double> >("Variable Col Array");
684  TEST_EQUALITY_CONST(curArray.getNumCols(),3);
685  colNumDepList.set("Num cols", 4);
686  arrayColDep()->evaluate();
687  curArray =
688  colNumDepList.get<TwoDArray<double> >("Variable Col Array");
689  TEST_EQUALITY_CONST(curArray.getNumCols(),5);
690  colNumDepList.set("Num cols", -2);
691  TEST_THROW(arrayColDep()->evaluate(),
693 }
694 
695 
699 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testArrayLengthDep){
701  RCP<DependencySheet> depSheet1 =
703 
705  numberArrayLengthDepList = My_deplist->sublist(
706  "Number Array Length Dependency List", false,
707  "Number Array Length Dependecy testing list.");
708  numberArrayLengthDepList.set("Array Length", 10, "array length setter");
709  Array<double> variableLengthArray(11,23.0);
711  varLengthArrayVali = RCP<EnhancedNumberValidator<double> >(
713  );
714  numberArrayLengthDepList.set(
715  "Variable Length Array", variableLengthArray, "variable length array",
717  new ArrayNumberValidator<double>(varLengthArrayVali)));
718 
720  arrayLengthDep(
722  numberArrayLengthDepList.getEntryRCP("Array Length"),
723  numberArrayLengthDepList.getEntryRCP("Variable Length Array"),
724  rcp(new AdditionFunction<int>(1))
725  )
726  );
727  depSheet1->addDependency(arrayLengthDep);
728  Array<double> curArray =
729  numberArrayLengthDepList.get<Array<double> >("Variable Length Array");
730  TEST_ASSERT(curArray.length() ==11);
731  numberArrayLengthDepList.set("Array Length", 12);
732  arrayLengthDep()->evaluate();
733  curArray =
734  numberArrayLengthDepList.get<Array<double> >("Variable Length Array");
735  out << curArray.length() << std::endl;
736  TEST_ASSERT(curArray.length() ==13);
737  numberArrayLengthDepList.set("Array Length", -2);
738  TEST_THROW(arrayLengthDep()->evaluate(),
740 }
741 
745 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testDepExceptions){
748 
749  list1->set("int parameter", 4, "int parameter");
750  list1->set("double parameter", 6.0, "double parameter");
751  list1->set("string parameter", "hahahaha", "string parameter");
752  Array<double> doubleArray(10,23.0);
753  list1->set("array parameter", doubleArray, "array parameter");
754  list1->set("bool parameter", true, "bool parameter");
755 
756  RCP<AdditionFunction<int> > intFuncTester = rcp(new
759  rcp(
761  list1->getEntryRCP("bool parameter"),
762  list1->getEntryRCP("double parameter"),
763  true,
764  intFuncTester)),
766 
767  /*
768  * Testing StringVisualDepenendcy exceptions.
769  */
770  RCP<StringVisualDependency> stringVisDep;
773  list1->getEntryRCP("double parameter"),
774  list1->getEntryRCP("int parameter"),
775  "cheese", true)),
777 
778  /*
779  * Testing BoolVisualDependency exceptions.
780  */
783  list1->getEntryRCP("int parameter"),
784  list1->getEntryRCP("double parameter"), false)),
786 
790  TEST_THROW(numArrayLengthDep =
792  list1->getEntryRCP("double parameter"),
793  list1->getEntryRCP("array parameter"))),
795 
796  TEST_THROW(numArrayLengthDep =
798  list1->getEntryRCP("int parameter"),
799  list1->getEntryRCP("double parameter"))),
801 
802  /*
803  * Testing StringValidatorDependency exceptions.
804  */
806  cheeseValidator = rcp(
808  tuple<std::string>( "Swiss", "American", "Super Awesome Cheese"),
809  "Food Selector"
810  )
811  );
812 
814  sodaValidator = rcp(
816  tuple<std::string>( "Pepsi", "Coke", "Kurtis Cola", "Bad Cola" ),
817  "Food Selector"
818  )
819  );
820 
822  chipsValidator = rcp(
824  tuple<std::string>( "Lays", "Doritos", "Kurtis Super Awesome Brand"),
825  "Food Selector"
826  )
827  );
828 
829 
830  list1->set(
831  "string 2 parameter", "Swiss",
832  "second string parameter", cheeseValidator);
834  testValidatorMap1["Cheese"] = cheeseValidator;
835  testValidatorMap1["Soda"] = sodaValidator;
836  testValidatorMap1["Chips"] = chipsValidator;
840  list1->getEntryRCP("int parameter"),
841  list1->getEntryRCP("string 2 parameter"),
842  testValidatorMap1)),
846  testValidatorMap1["Candy"] = intVali;
850  list1->getEntryRCP("string parameter"),
851  list1->getEntryRCP("string 2 parameter"),
852  testValidatorMap1)),
854 
859  list1->getEntryRCP("string parameter"),
860  list1->getEntryRCP("string 2 parameter"),
861  emptyMap)),
863 
864  /*
865  * Testing BoolValidatorDependency exceptions.
866  */
868  rcp(new EnhancedNumberValidator<double>(0.0,20.0));
870  rcp(new EnhancedNumberValidator<double>(5.0,20.0));
871  list1->set("double parameter", 6.0, "double parameter", doubleVali1);
872 
876  list1->getEntryRCP("int parameter"),
877  list1->getEntryRCP("double parameter"),
878  doubleVali1,
879  doubleVali2)),
881 
885  list1->getEntryRCP("bool parameter"),
886  list1->getEntryRCP("double parameter"),
887  intVali,
888  doubleVali2)),
890 
894  list1->getEntryRCP("bool parameter"),
895  list1->getEntryRCP("double parameter"),
896  doubleVali1,
897  intVali)),
899 
900  /*
901  * Testing RangeValidatorDependency exceptions.
902  */
903  list1->set("Cheese to Fondue", "Swiss", "the cheese to fondue");
905  lowTempCheeseValidator = rcp(
907  tuple<std::string>( "PepperJack", "Swiss", "American" ),
908  "Cheese to Fondue"
909  )
910  );
912  highTempCheeseValidator = rcp(
914  tuple<std::string>("Munster", "Provalone",
915  "Kurtis Super Awesome Cheese"),
916  "Cheese to Fondue"
917  )
918  );
919 
920  list1->set(
921  "Cheese to Fondue", "Swiss", "the cheese to fondue",
922  lowTempCheeseValidator);
923 
925  tempranges[std::pair<double,double>(100,200)] = lowTempCheeseValidator;
926  tempranges[std::pair<double,double>(200,300)] = highTempCheeseValidator;
927  TEST_THROW(
929  cheeseTempDep = RCP<RangeValidatorDependency<double> >(
931  list1->getEntryRCP("string parameter"),
932  list1->getEntryRCP("Cheese to Fondue"),
933  tempranges
934  )
935  ),
937  );
938 
939  tempranges[std::pair<double,double>(400,800)] = intVali;
940  TEST_THROW(
942  cheeseTempDep = RCP<RangeValidatorDependency<double> >(
944  list1->getEntryRCP("int parameter"),
945  list1->getEntryRCP("Cheese to Fondue"),
946  tempranges
947  )
948  ),
950  );
951 
953  TEST_THROW(
955  emptyMapDep = RCP<RangeValidatorDependency<double> >(
957  list1->getEntryRCP("double parameter"),
958  list1->getEntryRCP("Cheese to Fondue"),
959  emptyMap2
960  )
961  ),
963  );
964 
966  tempranges[std::pair<int,int>(200,100)] = lowTempCheeseValidator;
967  TEST_THROW(
969  cheeseTempDep = RCP<RangeValidatorDependency<int> >(
971  list1->getEntryRCP("string parameter"),
972  list1->getEntryRCP("Cheese to Fondue"),
973  badRanges
974  )
975  ),
977  );
978 }
979 
983 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, DepSheetTest){
984  RCP<DependencySheet> depSheet1 = rcp(new DependencySheet);
985  RCP<BoolVisualDependency> boolDep1 =
987  TEST_ASSERT(depSheet1->empty());
988  depSheet1->addDependency(boolDep1);
989  TEST_ASSERT(!depSheet1->empty());
990 
991 
992  RCP<DependencySheet> depSheet2 = rcp(new DependencySheet);
993  RCP<StringVisualDependency> stringDep1 =
995  depSheet1->addDependency(stringDep1);
996  RCP<StringValidatorDependency> stringValiDep1 =
998  depSheet1->addDependency(stringValiDep1);
999 
1000  depSheet1->addDependencies(depSheet2);
1001  TEST_EQUALITY_CONST(depSheet1->size(), 3);
1002  bool found1 = false;
1003  bool found2 = false;
1004  bool found3 = false;
1005  for(
1006  DependencySheet::DepSet::iterator it = depSheet1->depBegin();
1007  it != depSheet1->depEnd();
1008  ++it
1009  )
1010  {
1011  if(*it == boolDep1){
1012  found1 = true;
1013  }
1014  else if(*it == stringDep1){
1015  found2 = true;
1016  }
1017  else if(*it == stringValiDep1){
1018  found3 = true;
1019  }
1020  }
1021  TEST_ASSERT(found1);
1022  TEST_ASSERT(found2);
1023  TEST_ASSERT(found3);
1024 }
1025 
1026 
1027 } //namespace Teuchos
1028 
A Dependency sheet keeps track of dependencies between various ParameterEntries.
A dependency in which the number of rows in a parameter with a TwoDArray depends on the value of anot...
#define TEST_ASSERT(v1)
Assert the given statement is true.
static RCP< T > getDummyObject()
Retrieves a dummy object of type T.
A BoolValidatorDependency says the following about the relationship between two parameters: Dependeni...
RCP< ParameterEntry > getEntryRCP(const std::string &name)
Retrieves the RCP for an entry with the name name if it exists.
A string visual depdencies says the following about the relationship between two elements in a Parame...
Convience class for EnhancedNumberValidators that are to be applied to arrays.
#define TEST_NOTHROW(code)
Asserr that the statement &#39;code&#39; does not thrown any excpetions.
A bool visual dependency says the following about the relationship between two elements in a Paramete...
RCP< const ParameterEntryValidator > validator() const
Return the (optional) validator object.
A dependency in which the number of rows in a parameter with a TwoDArray depends on the value of anot...
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Set a parameter whose value has type T.
A simple function object that adds a specififed value from the given arguement in the runFunction fun...
A Bool Logic Condition that returns the result or perfroming a logical AND on the conditions...
DepSet::iterator depBegin()
Returns an iterator to the beginning of all the dependees in the sheet.
#define TEST_THROW(code, ExceptType)
Assert that the statement &#39;code&#39; throws the exception &#39;ExceptType&#39; (otherwise the test fails)...
T * get() const
Get the raw C++ pointer to the underlying object.
std::map< std::string, RCP< const ParameterEntryValidator > > ValueToValidatorMap
Conveniece typedef.
A Number Condition is a Parameter Condition that evaluates whether or not a number parameter is great...
A RangeValidatorDependency says the following about the relationship between two parameters: Dependen...
void addDependency(RCP< Dependency > dependency)
Adds a dependency to the sheet.
A simple function object that subtracts a specififed value from the given arguement in the runFunctio...
TEUCHOS_UNIT_TEST(ConstNonconstObjectContainer, create)
bool hasDependents(RCP< const ParameterEntry > dependee) const
Determines whether or not a parameter is depended upon by any another parameters or parameter lists...
A thin wrapper around the Array class which causes it to be interpreted as a 2D Array.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Templated Parameter List class.
DepSet::size_type size()
Returns the number of Dependencies in this DependencySheet.
Convience class for EnhancedNumberValidators that are to be applied to TwoDArray. ...
Unit testing support.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
size_type getNumCols() const
returns the number of columns in the TwoDArray.
bool empty() const
Determines whether or not this dependency sheet has any dependencies.
A NumberArrayLengthDependency says the following about the relationship between two parameters: The l...
void addDependencies(RCP< DependencySheet > otherSheet)
Adds a dependencies from another she to this sheet.
A list of parameters of arbitrary type.
A collection of standard dependencies.
void validateParameters(ParameterList const &validParamList, int const depth=1000, EValidateUsed const validateUsed=VALIDATE_USED_ENABLED, EValidateDefaults const validateDefaults=VALIDATE_DEFAULTS_ENABLED) const
Validate the parameters in this list given valid selections in the input list.
A Bool Condition is a Parameter Condition that evaluates whether or not a Boolean parameter is ture...
size_type getNumRows() const
returns the number of rows in the TwoDArray.
DataStructure keeping track of dependencies.
A StringValidatorDependency says the following about the relationship between two parameters: Depende...
Class uesd to validate a particular type of number.
int length() const
Return number of elements in the array.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Creates an empty sublist and returns a reference to the sublist name. If the list already exists...
Smart reference counting pointer class for automatic garbage collection.
A condition visual dependency says the following about the relationship between elements in a Paramet...
bool isDependentVisible() const
Determines whether or not the dependent is currently visible.
ParameterEntry & getEntry(const std::string &name)
Retrieves an entry with the name name.
A number visual dependency says the following about the relationship between two elements in a Parame...
std::map< Range, RCP< const ParameterEntryValidator > > RangeToValidatorMap
Convenience typedef.
Standard Conditions to be used.
RCP< const DepSet > getDependenciesForParameter(RCP< const ParameterEntry > dependee) const
Returns a set of all the dependencies associated with a particular dependee. If no dependencies with ...
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...