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 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
16 
17 
18 namespace Teuchos{
19 
23 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testValiDeps){
24  RCP<ParameterList> My_deplist = rcp(new ParameterList);
25  RCP<DependencySheet> depSheet1 = rcp(new DependencySheet);
26 
27  /*
28  * Testing StringValidatorDependency
29  */
31  stringFoodTypeValidator = rcp(
33  tuple<std::string>( "Cheese", "Soda", "Chips" )
34  ,"Food Type"
35  )
36  );
37 
39  cheeseValidator = rcp(
41  tuple<std::string>( "Swiss", "American", "Super Awesome Cheese" )
42  ,"Food Selector"
43  )
44  );
45 
47  sodaValidator = rcp(
49  tuple<std::string>( "Pepsi", "Coke", "Kurtis Cola", "Bad Cola" )
50  ,"Food Selector"
51  )
52  );
53 
55  chipsValidator = rcp(
57  tuple<std::string>( "Lays", "Doritos", "Kurtis Super Awesome Brand" )
58  ,"Food Selector"
59  )
60  );
61 
63  testValidatorMap1["Cheese"] = cheeseValidator;
64  testValidatorMap1["Soda"] = sodaValidator;
65  testValidatorMap1["Chips"] = chipsValidator;
66 
67  ParameterList stringValiDepList = My_deplist->sublist(
68  "String Validator Dependency", false,
69  "String Validator Dependency testing list.");
70  stringValiDepList.set(
71  "Food Selector", "Swiss", "select the food you want", cheeseValidator);
72  stringValiDepList.set(
73  "Food Type",
74  "Cheese",
75  "String Validator Dependency Tester",
76  stringFoodTypeValidator);
77 
79  stringValiDep = rcp(
81  stringValiDepList.getEntryRCP("Food Type"),
82  stringValiDepList.getEntryRCP("Food Selector"),
83  testValidatorMap1,
84  cheeseValidator
85  )
86  );
87 
88  depSheet1->addDependency(stringValiDep);
89 
90  TEST_NOTHROW(stringValiDepList.validateParameters(stringValiDepList));
91  TEST_ASSERT(depSheet1->hasDependents(
92  stringValiDepList.getEntryRCP("Food Type")));
93  RCP<const DependencySheet::DepSet> stringValiDepSet =
94  depSheet1->getDependenciesForParameter(
95  stringValiDepList.getEntryRCP("Food Type"));
96  TEST_ASSERT(stringValiDepSet->size() == 1);
97  stringValiDepList.set("Food Type","Soda");
98  stringValiDep->evaluate();
99  TEST_ASSERT(stringValiDepList.getEntry("Food Selector").validator()
100  ==
101  sodaValidator);
102  TEST_THROW(stringValiDepList.validateParameters(stringValiDepList),
104  stringValiDepList.set("Food Selector", "Pepsi");
105  TEST_NOTHROW(stringValiDepList.validateParameters(stringValiDepList));
106 
107 
108  /*
109  * Tesing some different aspects of the StringValidatorDependency
110  */
112  stringValiDepList2 = My_deplist->sublist(
113  "String Validator Dependency (other validators)",
114  false,
115  "String validator testing"
116  );
117 
119  stringRangeValidator = rcp(
121  tuple<std::string>( "1-10", "10-33", "50-60" ),
122  "Range selector"
123  )
124  );
125 
126  RCP<EnhancedNumberValidator<int> > range110Vali =
128  RCP<EnhancedNumberValidator<int> > range1033Vali =
129  rcp(new EnhancedNumberValidator<int>(10,33));
130  RCP<EnhancedNumberValidator<int> > range5060Vali =
131  rcp(new EnhancedNumberValidator<int>(50,60));
132 
133  stringValiDepList2.set("Range selector", "1-10",
134  "selects the range to validate", stringRangeValidator);
135 
137  rangeValidatorMap1["1-10"] = range110Vali;
138  rangeValidatorMap1["10-33"] = range1033Vali;
139  rangeValidatorMap1["50-60"] = range5060Vali;
140  stringValiDepList2.set(
141  "RangeValue", 3, "the value of the range", range110Vali);
142 
144  stringValiDep2 = RCP<StringValidatorDependency>(
146  stringValiDepList2.getEntryRCP("Range selector"),
147  stringValiDepList2.getEntryRCP("RangeValue"),
148  rangeValidatorMap1,
149  range110Vali
150  )
151  );
152 
153  depSheet1->addDependency(stringValiDep2);
154 
155  TEST_NOTHROW(stringValiDepList2.validateParameters(stringValiDepList2));
156  TEST_ASSERT(depSheet1->hasDependents(
157  stringValiDepList2.getEntryRCP("Range selector")));
158  RCP<const DependencySheet::DepSet> stringValiDepSet2 =
159  depSheet1->getDependenciesForParameter(
160  stringValiDepList2.getEntryRCP("Range selector"));
161  TEST_ASSERT(stringValiDepSet2->size() == 1);
162  stringValiDepList2.set("Range selector","50-60");
163  stringValiDep2->evaluate();
164  TEST_ASSERT(stringValiDepList2.getEntry("RangeValue").validator()
165  ==
166  range5060Vali);
167  TEST_THROW(stringValiDepList2.validateParameters(stringValiDepList2),
169  stringValiDepList2.set("RangeValue", 55);
170  TEST_NOTHROW(stringValiDepList2.validateParameters(stringValiDepList2));
171 
172  /*
173  * Testing the BoolValidatorDependency.
174  */
176  boolValidatorDepList = My_deplist->sublist(
177  "Bool Validator Dependency List",
178  false,
179  "Bool Validator Dependency testing list."
180  );
181 
182  boolValidatorDepList.set("Use Validator?",
183  true, "truns the validator on and off");
186  RCP<EnhancedNumberValidator<int> > basicVali2 =
188  boolValidatorDepList.set("do I have a validator?",
189  4, "does it have a validator?", basicVali);
190 
192  boolValiDep = RCP<BoolValidatorDependency>(
194  boolValidatorDepList.getEntryRCP("Use Validator?"),
195  boolValidatorDepList.getEntryRCP("do I have a validator?"),
196  basicVali,
197  basicVali2
198  )
199  );
200 
201  depSheet1->addDependency(boolValiDep);
202 
203  TEST_ASSERT(depSheet1->hasDependents(
204  boolValidatorDepList.getEntryRCP("Use Validator?")));
205  TEST_ASSERT(
206  boolValidatorDepList.getEntry("do I have a validator?").validator()
207  ==
208  basicVali);
209  TEST_NOTHROW(
210  boolValidatorDepList.validateParameters(boolValidatorDepList));
211  RCP<const DependencySheet::DepSet> boolValiDepSet =
212  depSheet1->getDependenciesForParameter(boolValidatorDepList.getEntryRCP(
213  "Use Validator?"));
214  TEST_ASSERT(boolValiDepSet->size() == 1);
215  boolValidatorDepList.set("Use Validator?",false);
216  boolValiDep->evaluate();
217  TEST_ASSERT(
218  boolValidatorDepList.getEntry("do I have a validator?").validator()
219  ==
220  basicVali2);
221 
222 
223  /*
224  * Testing the RangeValidatorDependency
225  */
227  lowTempCheeseValidator = rcp(
229  tuple<std::string>( "PepperJack", "Swiss", "American" ),
230  "Cheese to Fondue"
231  )
232  );
233 
235  highTempCheeseValidator = rcp(
237  tuple<std::string>(
238  "Munster", "Provalone", "Kurtis Super Awesome Cheese"),
239  "Cheese to Fondue"
240  )
241  );
242 
244  defaultCheeseValidator = rcp(
246  tuple<std::string>(
247  "Other cheese", "other cheese 1", "other cheese 3"),
248  "Cheese to Fondue"
249  )
250  );
251 
253  rangeValidatorDepList = My_deplist->sublist(
254  "Range Validator Dependency List",
255  false,
256  "Range Validator Dependency testing list.\nWorking June 27th 2009"
257  );
258  rangeValidatorDepList.set(
259  "Temperature",101.0, "The temperature of the fondue");
260  rangeValidatorDepList.set(
261  "Cheese to Fondue", "Swiss",
262  "The cheese we'll be using in our fondue pot.", lowTempCheeseValidator);
264  tempranges[std::pair<double,double>(100,200)] = lowTempCheeseValidator;
265  tempranges[std::pair<double,double>(200,300)] = highTempCheeseValidator;
267  cheeseTempDep = RCP<RangeValidatorDependency<double> >(
269  rangeValidatorDepList.getEntryRCP("Temperature"),
270  rangeValidatorDepList.getEntryRCP("Cheese to Fondue"),
271  tempranges,
272  defaultCheeseValidator
273  )
274  );
275  depSheet1->addDependency(cheeseTempDep);
276 
277  TEST_ASSERT(depSheet1->hasDependents(
278  rangeValidatorDepList.getEntryRCP("Temperature")));
279  RCP<const DependencySheet::DepSet> rangeValiDepSet =
280  depSheet1->getDependenciesForParameter(
281  rangeValidatorDepList.getEntryRCP("Temperature"));
282  TEST_ASSERT(rangeValiDepSet->size() == 1);
283  rangeValidatorDepList.set("Temperature",250.0);
284  cheeseTempDep->evaluate();
285  TEST_ASSERT(
286  rangeValidatorDepList.getEntry("Cheese to Fondue").validator()
287  ==
288  highTempCheeseValidator);
289  TEST_THROW(
290  rangeValidatorDepList.validateParameters(rangeValidatorDepList),
292  rangeValidatorDepList.set("Cheese to Fondue", "Provalone");
293  TEST_NOTHROW(
294  rangeValidatorDepList.validateParameters(rangeValidatorDepList));
295  rangeValidatorDepList.set("Temperature", 50.0);
296  cheeseTempDep->evaluate();
297  TEST_ASSERT(
298  rangeValidatorDepList.getEntry("Cheese to Fondue").validator()
299  ==
300  defaultCheeseValidator
301  );
302 
303 }
304 
308 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testVisualDeps){
310  RCP<DependencySheet> depSheet1 =
312  /*
313  * Two Simple NumberVisualDependency test
314  */
315 
317  simpleNumDepTestList = My_deplist->sublist(
318  "NumberVisual Dependency List (double)",
319  false,
320  "Number visual Dependency testing list"
321  );
322 
323  simpleNumDepTestList.set("Temperature",101.0);
324  simpleNumDepTestList.set("Cheese to Fondue", "Swiss", "The cheese to fondue");
325  simpleNumDepTestList.set("reverse param", "hello");
326 
327  RCP<NumberVisualDependency<double> > simpleNumDep =
330  simpleNumDepTestList.getEntryRCP("Temperature"),
331  simpleNumDepTestList.getEntryRCP("Cheese to Fondue"),
332  true
333  )
334  );
335  RCP<NumberVisualDependency<double> > reverseNumDep =
338  simpleNumDepTestList.getEntryRCP("Temperature"),
339  simpleNumDepTestList.getEntryRCP("reverse param"),
340  false
341  )
342  );
343  depSheet1->addDependency(simpleNumDep);
344  depSheet1->addDependency(reverseNumDep);
345  simpleNumDep->evaluate();
346  reverseNumDep->evaluate();
347  TEST_ASSERT(simpleNumDep->isDependentVisible());
348  TEST_ASSERT(!reverseNumDep->isDependentVisible());
349  simpleNumDepTestList.set("Temperature",-1.0);
350  simpleNumDep->evaluate();
351  reverseNumDep->evaluate();
352  TEST_ASSERT(!simpleNumDep->isDependentVisible());
353  TEST_ASSERT(reverseNumDep->isDependentVisible());
354 
355 
356  /*
357  * complex Testing the NumberVisualDependency
358  */
360  doubleVisualDepList = My_deplist->sublist(
361  "NumberVisual Dependency List (double)",
362  false,
363  "Number visual Dependency testing list"
364  );
365 
366  doubleVisualDepList.set(
367  "Temperature",101.0, "The temperature of the fondue");
368  doubleVisualDepList.set(
369  "Cheese to Fondue", "Swiss", "The cheese to fondue");
370  doubleVisualDepList.set("reverse param", "hello");
371  RCP<SubtractionFunction<double> > fondueFunc = rcp(new
373 
377  doubleVisualDepList.getEntryRCP("Temperature"),
378  doubleVisualDepList.getEntryRCP("Cheese to Fondue"),
379  true,
380  fondueFunc
381  )
382  );
383  RCP<NumberVisualDependency<double> > reverseFondueDep =
386  doubleVisualDepList.getEntryRCP("Temperature"),
387  doubleVisualDepList.getEntryRCP("reverse param"),
388  false,
389  fondueFunc
390  )
391  );
392  depSheet1->addDependency(fondueDep);
393  depSheet1->addDependency(reverseFondueDep);
394  fondueDep->evaluate();
395  reverseFondueDep->evaluate();
396  TEST_ASSERT(fondueDep->isDependentVisible());
397  TEST_ASSERT(!reverseFondueDep->isDependentVisible());
398  doubleVisualDepList.set("Temperature",99.0);
399  fondueDep->evaluate();
400  reverseFondueDep->evaluate();
401  TEST_ASSERT(!fondueDep->isDependentVisible());
402  TEST_ASSERT(reverseFondueDep->isDependentVisible());
403 
404  /*
405  * Testing the BoolVisualDependency
406  */
408  boolVisDepList = My_deplist->sublist(
409  "Bool Visual Dependency List",
410  false,
411  "Bool Visual Dependency testing list."
412  );
413  boolVisDepList.set(
414  "ShowPrecs", true, "Whether or not to should the Preciondtioner list");
416  Prec_List0 = boolVisDepList.sublist(
417  "Preconditioner",false,"Sublist that defines the preconditioner.");
418  Prec_List0.set("Type", "ILU", "The tpye of preconditioner to use");
419  RCP<EnhancedNumberValidator<double> > droptolValidator =
420  rcp(new EnhancedNumberValidator<double>(0,10,1e-3));
421  Prec_List0.set(
422  "Drop Tolerance", 1e-3,
423  "The tolerance below which entries from the "
424  "factorization are left out of the factors.", droptolValidator);
426  precDep1 = RCP<BoolVisualDependency>(
428  boolVisDepList.getEntryRCP("ShowPrecs"),
429  boolVisDepList.getEntryRCP("Preconditioner"),
430  true
431  )
432  );
433  depSheet1->addDependency(precDep1);
434  precDep1->evaluate();
435  TEST_ASSERT(precDep1->isDependentVisible());
436  boolVisDepList.set("ShowPrecs", false);
437  precDep1->evaluate();
438  TEST_ASSERT(!precDep1->isDependentVisible());
439 
440 
441 
442  /*
443  * Testing the StringVisualDependency
444  */
446  stringVisDepList = My_deplist->sublist(
447  "String Visual Dependency List",
448  false,
449  "String Visual Dependency testing list."
450  );
452  favCheeseValidator = rcp(
454  tuple<std::string>( "Swiss", "American", "Cheder" ),
455  "Favorite Cheese"
456  )
457  );
458 
459  stringVisDepList.set("Favorite Cheese",
460  "American", "Your favorite type of cheese", favCheeseValidator);
462  swissValidator = rcp(new EnhancedNumberValidator<int>(0,10));
463  stringVisDepList.set("Swiss rating", 0,
464  "How you rate swiss on a scale of 1 to 10", swissValidator);
466  swissDep1 = RCP<StringVisualDependency>(
468  stringVisDepList.getEntryRCP("Favorite Cheese"),
469  stringVisDepList.getEntryRCP("Swiss rating"),
470  "Swiss",
471  true
472  )
473  );
474  depSheet1->addDependency(swissDep1);
475  swissDep1->evaluate();
476  TEST_ASSERT(!swissDep1->isDependentVisible());
477  stringVisDepList.set("Favorite Cheese", "Swiss");
478  swissDep1->evaluate();
479  TEST_ASSERT(swissDep1->isDependentVisible());
480 
481  /*
482  * String Visual Tester with multiple values
483  */
484  ParameterList multiStringVisDepList = My_deplist->sublist(
485  "Multi String Visual Dependency List",
486  false
487  );
489  favCheeseValidator2 = rcp(
491  tuple<std::string>( "Provalone", "Swiss", "American", "Cheder" ),
492  "Favorite Cheese"
493  )
494  );
495 
496  multiStringVisDepList.set(
497  "Favorite Cheese", "American",
498  "Your favorite type of cheese", favCheeseValidator2);
499  multiStringVisDepList.set("Swiss rating", 0,
500  "How you rate swiss on a scale of 1 to 10", swissValidator);
502  swissDep2 = RCP<StringVisualDependency>(
504  multiStringVisDepList.getEntryRCP("Favorite Cheese"),
505  multiStringVisDepList.getEntryRCP("Swiss rating"),
506  tuple<std::string>("Swiss", "Cheder"),
507  true
508  )
509  );
510  depSheet1->addDependency(swissDep2);
511  swissDep2->evaluate();
512  TEST_ASSERT(!swissDep2->isDependentVisible());
513  multiStringVisDepList.set("Favorite Cheese", "Cheder");
514  swissDep2->evaluate();
515  TEST_ASSERT(swissDep2->isDependentVisible());
516 
517  /*
518  * Another test of the NumberVisualDependency.
519  */
521  numberVisDepList = My_deplist->sublist(
522  "Number Visual Dependency List",
523  false,
524  "Number Visual Dependency testing list."
525  );
526  numberVisDepList.set("Ice", 50, "Ice stuff");
527  numberVisDepList.set("Room Temp", 10, "Room temperature");
528  RCP<SubtractionFunction<int> > visFunc = rcp(new
533  numberVisDepList.getEntryRCP("Room Temp"),
534  numberVisDepList.getEntryRCP("Ice"),
535  true,
536  visFunc
537  )
538  );
539  depSheet1->addDependency(iceDep);
540  iceDep->evaluate();
541  TEST_ASSERT(!iceDep->isDependentVisible());
542  numberVisDepList.set("Room Temp", 33);
543  iceDep->evaluate();
544  TEST_ASSERT(iceDep->isDependentVisible());
545 
546  /*
547  * Test condition visual dependency
548  */
549  RCP<ParameterList> conVisDepList = sublist(
550  My_deplist,"Condition Visual Dependency List", false);
551  conVisDepList->set("double param", 4.0, "double parameter");
552  conVisDepList->set("bool param", true, "bool parameter");
553  conVisDepList->set("string param", "blah", "a string parameter");
554  RCP<NumberCondition<double> > numberCon =
556  conVisDepList->getEntryRCP("double param")));
557  RCP<BoolCondition> boolCon =
558  rcp(new BoolCondition(conVisDepList->getEntryRCP("bool param")));
560  tuple<RCP<const Condition> >(numberCon, boolCon);
561  RCP<AndCondition> andCon = rcp(new AndCondition(conList));
564  andCon, conVisDepList->getEntryRCP("string param"), true));
565  depSheet1->addDependency(conVisDep);
566  conVisDep->evaluate();
567  TEST_ASSERT(conVisDep->isDependentVisible());
568  conVisDepList->set("bool param", false);
569  conVisDep->evaluate();
570  TEST_ASSERT(!conVisDep->isDependentVisible());
571 }
572 
576 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testTwoDRowDependency){
578  RCP<DependencySheet> depSheet1 =
580 
582  rowNumDepList = My_deplist->sublist(
583  "2D Row Depdency List", false,
584  "2D Row Dependecy testing list.");
585  rowNumDepList.set("Num rows", 10, "num rows setter");
586  TwoDArray<double> variableRowsArray(11,2,16.5);
588  varRowArrayVali = RCP<EnhancedNumberValidator<double> >(
590  );
591  rowNumDepList.set(
592  "Variable Row Array", variableRowsArray, "variable row array",
594  new TwoDArrayNumberValidator<double>(varRowArrayVali)));
595 
597  arrayRowDep = rcp(
599  rowNumDepList.getEntryRCP("Num rows"),
600  rowNumDepList.getEntryRCP("Variable Row Array") ,
601  rcp(new AdditionFunction<int>(1))
602  )
603  );
604  depSheet1->addDependency(arrayRowDep);
605  TwoDArray<double> curArray =
606  rowNumDepList.get<TwoDArray<double> >("Variable Row Array");
607  TEST_EQUALITY_CONST(curArray.getNumRows(),11);
608  rowNumDepList.set("Num rows", 12);
609  arrayRowDep()->evaluate();
610  curArray =
611  rowNumDepList.get<TwoDArray<double> >("Variable Row Array");
612  TEST_EQUALITY_CONST(curArray.getNumRows(),13);
613  rowNumDepList.set("Num rows", -2);
614  TEST_THROW(arrayRowDep()->evaluate(),
616 }
617 
621 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testTwoDColDependency){
623  RCP<DependencySheet> depSheet1 =
625 
627  colNumDepList = My_deplist->sublist(
628  "2D Col Depdency List", false,
629  "2D Col Dependecy testing list.");
630  colNumDepList.set("Num cols", 2, "num cols setter");
631  TwoDArray<double> variableColsArray(11,3,16.5);
633  varColArrayVali = RCP<EnhancedNumberValidator<double> >(
635  );
636  colNumDepList.set(
637  "Variable Col Array", variableColsArray, "variable col array",
639  new TwoDArrayNumberValidator<double>(varColArrayVali)));
640 
642  arrayColDep = rcp(
644  colNumDepList.getEntryRCP("Num cols"),
645  colNumDepList.getEntryRCP("Variable Col Array") ,
646  rcp(new AdditionFunction<int>(1))
647  )
648  );
649  depSheet1->addDependency(arrayColDep);
650  TwoDArray<double> curArray =
651  colNumDepList.get<TwoDArray<double> >("Variable Col Array");
652  TEST_EQUALITY_CONST(curArray.getNumCols(),3);
653  colNumDepList.set("Num cols", 4);
654  arrayColDep()->evaluate();
655  curArray =
656  colNumDepList.get<TwoDArray<double> >("Variable Col Array");
657  TEST_EQUALITY_CONST(curArray.getNumCols(),5);
658  colNumDepList.set("Num cols", -2);
659  TEST_THROW(arrayColDep()->evaluate(),
661 }
662 
663 
667 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testArrayLengthDep){
669  RCP<DependencySheet> depSheet1 =
671 
673  numberArrayLengthDepList = My_deplist->sublist(
674  "Number Array Length Dependency List", false,
675  "Number Array Length Dependecy testing list.");
676  numberArrayLengthDepList.set("Array Length", 10, "array length setter");
677  Array<double> variableLengthArray(11,23.0);
679  varLengthArrayVali = RCP<EnhancedNumberValidator<double> >(
681  );
682  numberArrayLengthDepList.set(
683  "Variable Length Array", variableLengthArray, "variable length array",
685  new ArrayNumberValidator<double>(varLengthArrayVali)));
686 
688  arrayLengthDep(
690  numberArrayLengthDepList.getEntryRCP("Array Length"),
691  numberArrayLengthDepList.getEntryRCP("Variable Length Array"),
692  rcp(new AdditionFunction<int>(1))
693  )
694  );
695  depSheet1->addDependency(arrayLengthDep);
696  Array<double> curArray =
697  numberArrayLengthDepList.get<Array<double> >("Variable Length Array");
698  TEST_ASSERT(curArray.length() ==11);
699  numberArrayLengthDepList.set("Array Length", 12);
700  arrayLengthDep()->evaluate();
701  curArray =
702  numberArrayLengthDepList.get<Array<double> >("Variable Length Array");
703  out << curArray.length() << std::endl;
704  TEST_ASSERT(curArray.length() ==13);
705  numberArrayLengthDepList.set("Array Length", -2);
706  TEST_THROW(arrayLengthDep()->evaluate(),
708 }
709 
713 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testDepExceptions){
716 
717  list1->set("int parameter", 4, "int parameter");
718  list1->set("double parameter", 6.0, "double parameter");
719  list1->set("string parameter", "hahahaha", "string parameter");
720  Array<double> doubleArray(10,23.0);
721  list1->set("array parameter", doubleArray, "array parameter");
722  list1->set("bool parameter", true, "bool parameter");
723 
724  RCP<AdditionFunction<int> > intFuncTester = rcp(new
727  rcp(
729  list1->getEntryRCP("bool parameter"),
730  list1->getEntryRCP("double parameter"),
731  true,
732  intFuncTester)),
734 
735  /*
736  * Testing StringVisualDepenendcy exceptions.
737  */
738  RCP<StringVisualDependency> stringVisDep;
741  list1->getEntryRCP("double parameter"),
742  list1->getEntryRCP("int parameter"),
743  "cheese", true)),
745 
746  /*
747  * Testing BoolVisualDependency exceptions.
748  */
751  list1->getEntryRCP("int parameter"),
752  list1->getEntryRCP("double parameter"), false)),
754 
758  TEST_THROW(numArrayLengthDep =
760  list1->getEntryRCP("double parameter"),
761  list1->getEntryRCP("array parameter"))),
763 
764  TEST_THROW(numArrayLengthDep =
766  list1->getEntryRCP("int parameter"),
767  list1->getEntryRCP("double parameter"))),
769 
770  /*
771  * Testing StringValidatorDependency exceptions.
772  */
774  cheeseValidator = rcp(
776  tuple<std::string>( "Swiss", "American", "Super Awesome Cheese"),
777  "Food Selector"
778  )
779  );
780 
782  sodaValidator = rcp(
784  tuple<std::string>( "Pepsi", "Coke", "Kurtis Cola", "Bad Cola" ),
785  "Food Selector"
786  )
787  );
788 
790  chipsValidator = rcp(
792  tuple<std::string>( "Lays", "Doritos", "Kurtis Super Awesome Brand"),
793  "Food Selector"
794  )
795  );
796 
797 
798  list1->set(
799  "string 2 parameter", "Swiss",
800  "second string parameter", cheeseValidator);
802  testValidatorMap1["Cheese"] = cheeseValidator;
803  testValidatorMap1["Soda"] = sodaValidator;
804  testValidatorMap1["Chips"] = chipsValidator;
808  list1->getEntryRCP("int parameter"),
809  list1->getEntryRCP("string 2 parameter"),
810  testValidatorMap1)),
814  testValidatorMap1["Candy"] = intVali;
818  list1->getEntryRCP("string parameter"),
819  list1->getEntryRCP("string 2 parameter"),
820  testValidatorMap1)),
822 
827  list1->getEntryRCP("string parameter"),
828  list1->getEntryRCP("string 2 parameter"),
829  emptyMap)),
831 
832  /*
833  * Testing BoolValidatorDependency exceptions.
834  */
836  rcp(new EnhancedNumberValidator<double>(0.0,20.0));
838  rcp(new EnhancedNumberValidator<double>(5.0,20.0));
839  list1->set("double parameter", 6.0, "double parameter", doubleVali1);
840 
844  list1->getEntryRCP("int parameter"),
845  list1->getEntryRCP("double parameter"),
846  doubleVali1,
847  doubleVali2)),
849 
853  list1->getEntryRCP("bool parameter"),
854  list1->getEntryRCP("double parameter"),
855  intVali,
856  doubleVali2)),
858 
862  list1->getEntryRCP("bool parameter"),
863  list1->getEntryRCP("double parameter"),
864  doubleVali1,
865  intVali)),
867 
868  /*
869  * Testing RangeValidatorDependency exceptions.
870  */
871  list1->set("Cheese to Fondue", "Swiss", "the cheese to fondue");
873  lowTempCheeseValidator = rcp(
875  tuple<std::string>( "PepperJack", "Swiss", "American" ),
876  "Cheese to Fondue"
877  )
878  );
880  highTempCheeseValidator = rcp(
882  tuple<std::string>("Munster", "Provalone",
883  "Kurtis Super Awesome Cheese"),
884  "Cheese to Fondue"
885  )
886  );
887 
888  list1->set(
889  "Cheese to Fondue", "Swiss", "the cheese to fondue",
890  lowTempCheeseValidator);
891 
893  tempranges[std::pair<double,double>(100,200)] = lowTempCheeseValidator;
894  tempranges[std::pair<double,double>(200,300)] = highTempCheeseValidator;
895  TEST_THROW(
897  cheeseTempDep = RCP<RangeValidatorDependency<double> >(
899  list1->getEntryRCP("string parameter"),
900  list1->getEntryRCP("Cheese to Fondue"),
901  tempranges
902  )
903  ),
905  );
906 
907  tempranges[std::pair<double,double>(400,800)] = intVali;
908  TEST_THROW(
910  cheeseTempDep = RCP<RangeValidatorDependency<double> >(
912  list1->getEntryRCP("int parameter"),
913  list1->getEntryRCP("Cheese to Fondue"),
914  tempranges
915  )
916  ),
918  );
919 
921  TEST_THROW(
923  emptyMapDep = RCP<RangeValidatorDependency<double> >(
925  list1->getEntryRCP("double parameter"),
926  list1->getEntryRCP("Cheese to Fondue"),
927  emptyMap2
928  )
929  ),
931  );
932 
934  tempranges[std::pair<int,int>(200,100)] = lowTempCheeseValidator;
935  TEST_THROW(
937  cheeseTempDep = RCP<RangeValidatorDependency<int> >(
939  list1->getEntryRCP("string parameter"),
940  list1->getEntryRCP("Cheese to Fondue"),
941  badRanges
942  )
943  ),
945  );
946 }
947 
951 TEUCHOS_UNIT_TEST(Teuchos_Dependencies, DepSheetTest){
952  RCP<DependencySheet> depSheet1 = rcp(new DependencySheet);
953  RCP<BoolVisualDependency> boolDep1 =
955  TEST_ASSERT(depSheet1->empty());
956  depSheet1->addDependency(boolDep1);
957  TEST_ASSERT(!depSheet1->empty());
958 
959 
960  RCP<DependencySheet> depSheet2 = rcp(new DependencySheet);
961  RCP<StringVisualDependency> stringDep1 =
963  depSheet1->addDependency(stringDep1);
964  RCP<StringValidatorDependency> stringValiDep1 =
966  depSheet1->addDependency(stringValiDep1);
967 
968  depSheet1->addDependencies(depSheet2);
969  TEST_EQUALITY_CONST(depSheet1->size(), 3);
970  bool found1 = false;
971  bool found2 = false;
972  bool found3 = false;
973  for(
974  DependencySheet::DepSet::iterator it = depSheet1->depBegin();
975  it != depSheet1->depEnd();
976  ++it
977  )
978  {
979  if(*it == boolDep1){
980  found1 = true;
981  }
982  else if(*it == stringDep1){
983  found2 = true;
984  }
985  else if(*it == stringValiDep1){
986  found3 = true;
987  }
988  }
989  TEST_ASSERT(found1);
990  TEST_ASSERT(found2);
991  TEST_ASSERT(found3);
992 }
993 
994 
995 } //namespace Teuchos
996 
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 dependency 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...
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.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Templated set method.
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...