|
Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Teuchos: Common Tools Package 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #include "Teuchos_UnitTestHarness.hpp" 00043 #include "Teuchos_VerboseObject.hpp" 00044 #include "Teuchos_ParameterList.hpp" 00045 #include "Teuchos_StandardConditions.hpp" 00046 #include "Teuchos_StandardParameterEntryValidators.hpp" 00047 #include "Teuchos_StandardConditions.hpp" 00048 00049 namespace Teuchos{ 00050 00054 TEUCHOS_UNIT_TEST(Teuchos_Conditions, testConditions){ 00055 //Settin up initial list 00056 RCP<ParameterList> testingList = rcp(new ParameterList("Condition Testing List")); 00057 00058 /* 00059 * Testing for string condition 00060 */ 00061 Array<std::string> validValues(tuple<std::string>("mountain dew", "pepsi", "coke", "fanta")); 00062 RCP<StringValidator> stringVali1 = rcp(new StringValidator(validValues)); 00063 00064 testingList->set("string param", "fanta", "parameter for testing string conditions", stringVali1); 00065 00066 StringCondition::ValueList conValues1(tuple<std::string>("pepsi", "coke")); 00067 RCP<StringCondition> stringCon1 = rcp( new StringCondition(testingList->getEntryRCP("string param"), conValues1)); 00068 TEST_ASSERT(!stringCon1->isConditionTrue()); 00069 testingList->set("string param", "coke"); 00070 TEST_ASSERT(stringCon1->isConditionTrue()); 00071 00072 /* 00073 * Testing for number condition 00074 */ 00075 testingList->set("double param", 5.0, "parameter for testing number conditions"); 00076 00077 RCP<NumberCondition<double> > numberCon1 = 00078 rcp( new NumberCondition<double>(testingList->getEntryRCP("double param"))); 00079 TEST_ASSERT(numberCon1->isConditionTrue()); 00080 testingList->set("double param", -1.0); 00081 TEST_ASSERT(!numberCon1->isConditionTrue()); 00082 RCP<SubtractionFunction<double> > doubleTesterFunc = rcp( new SubtractionFunction<double>(100)); 00083 RCP<NumberCondition<double> > numberCon2 = 00084 rcp( new NumberCondition<double>(testingList->getEntryRCP("double param"), doubleTesterFunc)); 00085 TEST_ASSERT(!numberCon2->isConditionTrue()); 00086 testingList->set("double param", 101.0); 00087 TEST_ASSERT(numberCon2->isConditionTrue()); 00088 00089 /* 00090 * Testing bool conditions 00091 */ 00092 testingList->set("bool param", true, "parameter for testing bool conditions"); 00093 00094 RCP<BoolCondition> boolCon1 = rcp( new BoolCondition(testingList->getEntryRCP("bool param"))); 00095 TEST_ASSERT(boolCon1->isConditionTrue()); 00096 testingList->set("bool param", false); 00097 TEST_ASSERT(!boolCon1->isConditionTrue()); 00098 00099 /* 00100 * Test Not condition 00101 */ 00102 RCP<NotCondition> notCon1 = rcp(new NotCondition(numberCon1)); 00103 TEST_ASSERT(!notCon1->isConditionTrue()); 00104 testingList->set("double param", -1.0); 00105 TEST_ASSERT(notCon1->isConditionTrue()); 00106 00107 /* 00108 * Test And condition 00109 */ 00110 Condition::ConstConditionList conList1(tuple<RCP<const Condition> >(stringCon1, boolCon1)); 00111 RCP<AndCondition> andCon1 = rcp(new AndCondition(conList1)); 00112 TEST_ASSERT(!andCon1->isConditionTrue()); 00113 testingList->set("bool param", true); 00114 TEST_ASSERT(andCon1->isConditionTrue()); 00115 00116 /* 00117 * Testing or condition 00118 */ 00119 testingList->set("bool param", false); 00120 RCP<OrCondition> orCon1 = rcp(new OrCondition(conList1)); 00121 TEST_ASSERT(orCon1->isConditionTrue()); 00122 testingList->set("string param", "fanta"); 00123 00124 /* 00125 * Testing equal condition 00126 */ 00127 RCP<EqualsCondition> equalsCon1 = rcp(new EqualsCondition(conList1)); 00128 TEST_ASSERT(equalsCon1->isConditionTrue()); 00129 testingList->set("bool param", true); 00130 TEST_ASSERT(!equalsCon1->isConditionTrue()); 00131 } 00132 00133 //Test getters and setters 00134 TEUCHOS_UNIT_TEST(Teuchos_Conditions, testConditionGetterAndSetters){ 00135 //Settin up initial list 00136 RCP<ParameterList> testingList = rcp(new ParameterList("Condition Testing List")); 00137 00138 Array<std::string> validValues(tuple<std::string>("mountain dew", "pepsi", "coke", "fanta")); 00139 RCP<StringValidator> stringVali1 = rcp(new StringValidator(validValues)); 00140 00141 testingList->set("string param", "fanta", "parameter for testing string conditions", stringVali1); 00142 00143 StringCondition::ValueList conValues1(tuple<std::string>("pepsi", "coke")); 00144 RCP<StringCondition> stringCon1 = rcp( new StringCondition(testingList->getEntryRCP("string param"), conValues1)); 00145 Dependency::ConstParameterEntryList stringParameters = stringCon1->getAllParameters(); 00146 TEST_ASSERT(stringParameters.size() == 1); 00147 TEST_ASSERT(stringParameters.find(testingList->getEntryRCP("string param")) != stringParameters.end()); 00148 00149 /* 00150 * Testing for number condition 00151 */ 00152 testingList->set("double param", 5.0, "parameter for testing number conditions"); 00153 00154 RCP<NumberCondition<double> > numberCon1 = rcp( new NumberCondition<double>(testingList->getEntryRCP("double param"))); 00155 Dependency::ConstParameterEntryList numberParameters = numberCon1->getAllParameters(); 00156 TEST_ASSERT(numberParameters.size() == 1); 00157 TEST_ASSERT(numberParameters.find(testingList->getEntryRCP("double param")) != numberParameters.end()); 00158 00159 /* 00160 * Testing bool conditions 00161 */ 00162 testingList->set("bool param", true, "parameter for testing bool conditions"); 00163 00164 RCP<BoolCondition> boolCon1 = rcp( new BoolCondition(testingList->getEntryRCP("bool param"))); 00165 Dependency::ConstParameterEntryList boolParameters = boolCon1->getAllParameters(); 00166 TEST_ASSERT(boolParameters.size() == 1); 00167 TEST_ASSERT(boolParameters.find(testingList->getEntryRCP("bool param")) != boolParameters.end()); 00168 00169 /* 00170 * Test Not condition 00171 */ 00172 RCP<NotCondition> notCon1 = rcp(new NotCondition(numberCon1)); 00173 Dependency::ConstParameterEntryList notParameters = notCon1->getAllParameters(); 00174 TEST_ASSERT(notParameters.size() == 1); 00175 TEST_ASSERT(notParameters.find(testingList->getEntryRCP("double param")) != notParameters.end()); 00176 00177 /* 00178 * Test And condition 00179 */ 00180 Condition::ConstConditionList conList1(tuple<RCP<const Condition> >(stringCon1, boolCon1)); 00181 RCP<AndCondition> andCon1 = rcp(new AndCondition(conList1)); 00182 Dependency::ConstParameterEntryList andParameters = andCon1->getAllParameters(); 00183 TEST_ASSERT(andParameters.size() == 2); 00184 TEST_ASSERT(andParameters.find(testingList->getEntryRCP("string param")) != andParameters.end()); 00185 TEST_ASSERT(andParameters.find(testingList->getEntryRCP("bool param")) != andParameters.end()); 00186 00187 /* 00188 * Testing or condition 00189 */ 00190 RCP<OrCondition> orCon1 = rcp(new OrCondition(conList1)); 00191 Dependency::ConstParameterEntryList orParameters = orCon1->getAllParameters(); 00192 TEST_ASSERT(orParameters.size() == 2); 00193 TEST_ASSERT(orParameters.find(testingList->getEntryRCP("string param")) != orParameters.end()); 00194 TEST_ASSERT(orParameters.find(testingList->getEntryRCP("bool param")) != orParameters.end()); 00195 00196 /* 00197 * Testing Equsl condition 00198 */ 00199 Condition::ConstConditionList conList2(tuple<RCP<const Condition> >(numberCon1, boolCon1)); 00200 RCP<EqualsCondition> equalsCon1 = rcp(new EqualsCondition(conList2)); 00201 Dependency::ConstParameterEntryList equalsParameters = equalsCon1->getAllParameters(); 00202 TEST_ASSERT(equalsParameters.size() == 2); 00203 TEST_ASSERT(equalsParameters.find(testingList->getEntryRCP("double param")) != equalsParameters.end()); 00204 TEST_ASSERT(equalsParameters.find(testingList->getEntryRCP("bool param")) != equalsParameters.end()); 00205 00206 /* 00207 * Testing BoolLogicCondition add 00208 */ 00209 equalsCon1->addCondition(orCon1); 00210 Dependency::ConstParameterEntryList equalsParameters2 = equalsCon1->getAllParameters(); 00211 TEST_ASSERT(equalsParameters2.size() == 3); 00212 TEST_ASSERT(equalsParameters2.find(testingList->getEntryRCP("string param")) != equalsParameters2.end()); 00213 TEST_ASSERT(equalsParameters2.find(testingList->getEntryRCP("double param")) != equalsParameters2.end()); 00214 TEST_ASSERT(equalsParameters2.find(testingList->getEntryRCP("bool param")) != equalsParameters2.end()); 00215 00216 } 00217 00218 //Test that exceptions get thrown when they should. 00219 TEUCHOS_UNIT_TEST(Teuchos_Conditions, testConditionException){ 00220 //Settin up initial list 00221 RCP<ParameterList> testingList = rcp(new ParameterList("Condition Testing List")); 00222 testingList->set("double param",1.0); 00223 testingList->set("string param", "awesome"); 00224 RCP<ParameterList> testingList2 = rcp(new ParameterList("Condition Testing List")); 00225 testingList2->set("bool param", true); 00226 00227 TEST_THROW(BoolCondition boolCon1(testingList->getEntryRCP("bool param")), InvalidConditionException); 00228 TEST_THROW(StringCondition stringCon1(testingList->getEntryRCP("double param"), "coke"), InvalidConditionException); 00229 TEST_THROW(BoolCondition boolCon1(testingList->getEntryRCP("double param")), InvalidConditionException); 00230 Condition::ConstConditionList conList1; 00231 TEST_THROW(AndCondition andCon1(conList1), InvalidConditionException); 00232 RCP<const Condition> con1; 00233 TEST_THROW(NotCondition notCon1(con1), InvalidConditionException); 00234 } 00235 00236 } //namespace Teuchos
1.7.6.1